Slashdot Mirror


Ask Slashdot: Making JavaScript Tolerable For a Dyed-in-the-Wool C/C++/Java Guy?

DocDyson writes "I'm a dyed-in-the-wool C/C++/Java developer with over 20 years of experience. I'm making a good living and having fun doing back-end Java work right now, but I strongly believe in being a generalist, so I'm finally trying to learn the HTML5/CSS3/JavaScript future of the Web. However, I find JavaScript's weak typing and dynamic nature difficult to adapt to because I'm so used to strongly-typed, compiled languages with lots of compile-time error-checking and help from the IDE. Does anyone out there who has made this transition have any tips in terms of the best tools and libraries to use to make JavaScript more palatable to us old-school developers?"

78 of 575 comments (clear)

  1. Going down in flames by Anonymous Coward · · Score: 5, Insightful

    Probably gonna get flamed for this, but my advice.. don't fight it! When in Rome.. etc.

    Javascript isn't meant to be done like c++ or Java, so don't try! Think about the mess you get when an assembly guy tries his hand at Java. It's the same deal. It's a whole different mindset, and if you fight it you'll just end up with a big mess and a lot of wasted time.

    That said, some stuff does transfer over. You can still go through proper requirements, design and testing. Basic principles like encapsulation and reuse still sorta apply (and are highly recommended imo). Before doing anything that seems like a common use case, check to see if someone has already done it (but don't blindly use it.. a lot of really shitty stuff out there.. but some gems too!).

    1. Re:Going down in flames by Anonymous Coward · · Score: 5, Informative

      Moving from assembly to Java is a big jump because you're gaining many abstractions that just don't exist in assembly, and giving up some some concreteness that just isn't as useful in Java.

      The exact opposite happens when you move from Java or C++ to JavaScript, and this is what the submitter is suffering from. JavaScript has inferior abstractions compared to what Java and C++ offer. The submitter feels pain because he's apparently an experienced programmer who knows that he's losing many valuable tools when using JavaScript, and getting nothing beneficial in return.

      Just look how stupidly difficult it is in JavaScript to implement even basic inheritance. There are many different ways, and they are all horrible. Java and C++ both make the definition of classes and inheritance hierarchies extremely simple and easy. It's far easier to imitate JavaScript's prototype-based OO approach in Java or C++ than it is to implement rudimentary class-based inheritance in JavaScript.

      JavaScript advocates usually toss out something about "lambda functions" or "closures" at this point. Well, it turns out that they can both be implemented very easily using the proper class support that both Java and C++ offer. Nevertheless, C++11 currently offers some syntactic sugar to make lambda functions easier to work with, and Java 8 will likely support an even easier lambda syntax, as well.

      This is all ignoring the other major problems the submitter highlighted, too. You don't have a compiler doing a lot of type checking automatically when you're using JavaScript. So you have to accept that these errors will be caught by the end user (and they always will be), even if you put in a lot of manual effort basically implementing type checking yourself within your JavaScript code. Then there are the lack of proper IDEs, good debuggers (Firebug pales compared to a real C++ or Java debugger), and the many other tools that a C++ or Java programmers expects to use.

      My advice to the submitter is for him to lower his standards significantly. It'll be painful, but that's the only way to stay sane when using JavaScript. Expect poor results from the language you're using. Expect poor results from the libraries you're using. Expect poor results from the runtimes (browsers) you're targeting. Expect lower-quality software. Expect more end-user complaints. Oh, and welcome to web development.

    2. Re:Going down in flames by Anonymous Coward · · Score: 5, Insightful

      The most telling thing about JavaScript as a language, and the community that surrounds it, is that the most widely-respected book is "JavaScript: The Good Parts". It's a book that basically tells you what parts of JavaScript never to use!

      Compare this to the most respected books about other programming languages. I'm talking about "The C Programming Language" for C, "The C++ Programming Language" for C++, and even "Programming Perl" for goddamn Perl. They're the complete opposite. They explain each and every feature the language offers, and how to use them effectively.

      Something is seriously wrong with a programming language when the most useful books about it are those telling you to not use large portions of the language!

    3. Re:Going down in flames by nahdude812 · · Score: 4, Interesting

      Use Google's Closure Compiler in ADVANCED_OPTIMIZATIONS mode. It reads various JSDoc hints, and can provide compile-time warnings and errors when you violate type constraints. It doesn't exactly make JavaScript strongly typed, there are a variety of ways you could fool it if i you want, but you'll be writing TIGHT JavaScript code that would be the envy of most web developers. And it'll out-perform anything they can produce because of the additional compile-time optimizations it can offer.

      It's part of our build process here now. All JS scripts have to go through Closure. Unfortunately a number of 3rd party libraries won't work in advanced optimizations mode, so we can't use advanced across the board, but those scripts where we control the source, we get substantial size and performance gains, as well as the sanity of a compiler looking over our shoulder making sure we don't make a variety of humdrum simple mistakes.

      You also get the advantage of being able to use compiler flags to alter the compiled source (@const declarations are replaced inline, and you can override the value of an @const at compile time, so you can have the equivalent of IFDEF's for different code paths per browser, and so forth - dead code paths are trimmed by the compiler so they don't increase the size of the output or have any performance impact for the end user).

    4. Re:Going down in flames by chooks · · Score: 5, Informative

      If closures and lambda expressions were so easy to implement using basic inheritance, Java would already have it. Java 7 has no lambda structures or closures. Anonymous inner classes are a hacked on incomplete poor mans semi-closure that provides just enough to get you almost what you want, but not quite. Last I checked, JCP (or related) had this as a work in progress. And will it be a first class construct in Java or some kind of pre-compiler/interpreter/VM? I am not sure, but hopefully the former.

      Java makes many things easier, but functional programming constructs is not one of these. Once I (re)learned how to use the more functional approach (it has been a long time since my LISP days) I really started to (re)appreciate the power of it. Some may wax poetical about elegance, simplicity, etc.. but that is really what it felt like to me. It sure made it harder to swallow some of the limitations that Java has without these constructs.

      I am definitely not a javascript fanboi, and absolutely agree with you (and the 1E6 others) that hate the toolset for developing with it, but I do appreciate the programmatic constructs it allows. And these constructs are definitely not in Java yet (cause boy, could I have used some of them on my last project!)

      --
      -- The Genesis project? What's that?
    5. Re:Going down in flames by defcon-11 · · Score: 3, Informative

      "JavaScript has inferior abstractions compared to what Java and C++ offer" As someone who codes in both Java and JavaScript, I find Javascript much more flexible, and closer to a true OO language, as opposed to Java's sort-a-kind-a OO. Javascript has several well known design flaws, but so does Java. The flaws are generally well known, and experienced programmers form either language shouldn't have a problem avoiding them. Most people that I've worked with and who complain about Javascript haven't taken the time to learn how the language works, and instead just try to impose class based OO, which always fails miserably. When using a prototype OO language (Javascript, Python, Ruby), OO principles such as 'interface composition instead of inheritance' that Java developers praise suddenly become much easier to apply without resorting to design patterns aimed at getting around Java's lack of multiple inheritance, or other shortcomings. Java's type checking can be helpful at times, but after many years developing with dynamic languages, I will tell you that mismatched-typing issues are a tiny minority of bugs I've seen make it to production.

    6. Re:Going down in flames by ozmanjusri · · Score: 4, Informative

      Lack of a good debugging and testing environment is the only reason Javascript is goddamn annoying.

      Eclipse/Aptana, Webstorm or Netbeans are all good IDEs that handle debugging either natively or with plugins.

      --
      "I've got more toys than Teruhisa Kitahara."
    7. Re:Going down in flames by cshark · · Score: 4, Informative

      My advice to the submitter is for him to lower his standards significantly. It'll be painful, but that's the only way to stay sane when using JavaScript. Expect poor results from the language you're using. Expect poor results from the libraries you're using. Expect poor results from the runtimes (browsers) you're targeting. Expect lower-quality software. Expect more end-user complaints. Oh, and welcome to web development.

      I'm really tired of hearing xenophobic morons complain about languages and tools they don't understand, and spouting off the same nonsense that hasn't been true for years. It doesn't bode well for your understanding of any language when you're readdressing grievances that were resolved a decade ago. Get your head out of your ass, and get with the times, please. Here's the deal: Just because you don't understand it, does not make it an infirior, low quality language. Just because you're incapable of writing code that performs well, does not means that the language is slow or sluggish. It simply means you're a closed minded idiot who refuses to learn the basic principles, ideas, and uses behind the thing.

      You can't compare Javascript to C++ or Java. Not only is it a totally different mindset, but it's a totally different use case. In Java and C++ you're writing libraries and interfaces. In Javascript, you're writing libraries and documents. Documents are fundamentally different than interfaces because the structures are different. Javascript is a means by which to manipulate a web page. In practical terms, nothing more. Javascript is out of place on server side, which is why server style Javascript has never caught on, and it doesn't really make a lot of sense as a general purpose programming language either.

      To date I've met a lot of C++ programmers that have tried Javascript. I've only known one who was any good at it, and none of them have been better at it than me (which is generally how I evaluate other programmers, generally). It's not a bad thing. It is what it is. C++ and Javascript are so different, that there's really no way to do an apples to apples comparison. And, it's probably easier to go from something like Javascript to C++ than it is to go the other way.

      If you're going to go from C++, just put the whole thing out of your mind, and pick up something hands on. If there's a Hard Way book on the subject, it would be a good place to start. Also, picking up other scripting languages like Dart, PHP, or Python might get your brain to soften up a little. After spending time in C++ world, where you have to have absolute control over every aspect of everything you develop, going to Javascript where you really only control the DOM can be jarring. The hardest thing to do is just accept that Javascript is nothing like C++, and the tools that you're used to in and for C++ don't work for a reason.

      As far as debugging tools. Don't bother with Chrome. It's nearly worthless for Javascript testing or debugging. Get yourself a copy of the latest Firefox stable, download Firebug, and the Web Developer Toolbar. Make sure you have at least a basic understanding of CSS 2 and its basic properties before attempting to do anything, and get yourself a copy of Netbeans. It has the best debugger, and the best reference material, in my opinion. It also has built in support for Subversion and CVS, which I find useful. Don't write anything in Javascript without version control. You'll thank me for that.

      When you're first getting started, don't try to become an expert in Jquery or YUI. Learn the real thing first, and write something challenging from scratch. Since you're a C++ programmer, there are any number of things, I'm sure, that you can think of that would be fun to write in Javascript. When I learn a new language, I like to write an e-commerce program start to finish in it. If I were just starting with Javascript, I would attempt to write something for mobile. Mobile has the extra challenge of writing something useful, that maintains a smaller footprint. It'll kill your C++ tendencies flat. Or, it'll frustrate the hell out of you.

      Either way.
      Take Care

      --

      This signature has Super Cow Powers

    8. Re:Going down in flames by Anonymous Coward · · Score: 5, Informative

      Heh... the idea that you would be using every part of C++ and that all of it was good... brought a smile to my place. First of all, C++ is so large a language that practically no one knows everything about it. Second, books like "Effective C++" are precisely about the specific way to use selected features of C++ in order not to get bogged down later on.

    9. Re:Going down in flames by sg_oneill · · Score: 4, Interesting

      There used to be a great debugger called the Venkman debugger. Actually its still around , but more and more I just use firebug.

      If your doing web, here are your main tools. webdeveloper toolbar & firebug. webdeveloper toolbar has a bunch of useful widgets like screen rulers and stuff, and firebug lets you poke under the hood of a page , run queries against the javascript , look at the calculated values of various DOM properties and so on.

      You also NEED to aquaint yourself with jquery. Javascript is almost untolerable without it. Jquery provides an xpath-ish interface to getting at the dom and utilizes lots of anonymous-closure goodness (dont fear it, embrace it, its good) to let you build up fairly complex behaviors quickly.

      You'll probably want a good whiskey supply to drown your sorrows after knock off time too. Javascript is bloody awful.

      --
      Excuse the Unicode crap in my posts. That's an apostrophe, and slashdot is busted.
    10. Re:Going down in flames by justforgetme · · Score: 4, Insightful

      I have learned to program in about a dozen programming languages over the years plus many frameworks for some of them. I can;t claim to be proficient (or efficient) in all of them but what I can claim is this: The only languages/frameworks I have no headaches about are the ones I have drilled down on and put an effort into understanding at the most involved level they allow.

      In most cases it's not the language but the attitude/predisposition that creates problems.

      --
      -- no sig today
    11. Re:Going down in flames by elp · · Score: 4, Insightful

      Jquery is simple to use and "just plain works"(tm). Trying to manage ajax queries on multiple browsers or work the DOM yourself sounds way too much like advanced masochism to me.

    12. Re:Going down in flames by somersault · · Score: 5, Insightful

      If you think JQuery overcomplicates things, maybe you're using it wrong?

      The whole idea of having to put browser-dependent fixes into my JavaScript was what turned me off of doing any fancy UI stuff for a long time. I first looked at it around 2002 and was sickened by the whole incompatible browser DOM mess such that I didn't look again for years. Having all that crap hidden away behind JQuery helps to make it almost like "normal" programming again. Though even then there are still things that IE messes up..

      If you feel that JQuery is making things less readable, why not wrap the JQuery stuff in your own functions? That's what I did for the AJAX functionality that I've built up.

      --
      which is totally what she said
    13. Re:Going down in flames by julesh · · Score: 4, Insightful

      Stop using jquery and you'll find that half of your headaches are gone automatically. Javascript can brain-dead simple if you know how to use it -- and it can be a gigantic headache when you use it incorrectly. If you think jquery makes your life easier, you're clearly using it wrong.

      Sorry. I cannot agree here. Jquery enables some of the most elegant web programming I have ever seen. It allows, among other things, almost total separation of program logic from content -- I can use an entirely declarative approach on content elements that I want to be active, and then have a separate .js file to hook up the declarations and the actual logic behind them, trivially:

      $(".hideable").before(function () {
          var hideableElement = this;
          return $("#showhidecontrol").clone().click(function () { hideableElement.toggleClass("hidden"); })});

      (doing this from memory, untested, but I'm pretty sure it'll work)

      Do that in three lines of code without jquery or another of the libraries you claim to despise. Hell, do it in 30. For reference -- it finds the element with id 'showhidecontrol' from the existing document and places deep copies of it before each element with class 'hideable', adding an onclick event handler to it that adds the class 'hidden' to the element with class 'hideable' if it isn't already present, or removes it if it is.

    14. Re:Going down in flames by narcc · · Score: 4, Informative

      Working with the DOM yourself is painless if you understand it. Most people don't (yet assume that they do) and haven't even made a legitimate effort to learn about it. If you read the standards, and spend some time playing with what you're reading about, you'll find that it's not difficult at all. You'll also find that managing cross-browser compatibility is almost as simple as merely avoiding a (vanishingly) small subset of things.

      As for cross-browser ajax, it's also really easy *if* you've taken the time to actually understand it. I wrote a small cross-browser php/js ajax library years ago (2006 or 2007) that works (it's in production) unmodified to this day. It took less time to write than it did to learn the equivalent bits of jQuery.

      jQuery, in my experience, leads to less-readable and less-maintainable code. The added bloat is just salt in the wound. Really, the people I see push hardest for jQuerey are the same people who don't seem to 'get' that JS is not Java/c#/c++ or people that don't really understand the DOM or CSS.

      Sure, if you were tasked with creating a set of standards for the web you'd never come up with a mess like HTML, CSS, JS -- it's not difficult to imagine a simpler set of standards. Of course, it's what we have. jQuery just makes an already big mess even bigger -- with no obvious net-benefit.

    15. Re:Going down in flames by narcc · · Score: 4, Insightful

      That makes my point, doesn't it? It's non-obvious what the code does, even if you're familiar with jQuery.

      To really understand it, you need a practical knowledge of jQuery, html, css, and ... (wait for it) ... the hard parts of javascript that you're trying to avoid learning about and using in the first place!

      (Oh, and if you let me make my own versions of the before and toggleClass functions I can do that in javascript in well under 30 lines of much more readable code.)

    16. Re:Going down in flames by TheRaven64 · · Score: 4, Funny

      To date I've met a lot of C++ programmers that have tried Javascript. I've only known one who was any good at it

      To be fair, meeting a C++ programmer who is good at C++ is also pretty rare...

      --
      I am TheRaven on Soylent News
    17. Re:Going down in flames by Assmasher · · Score: 5, Interesting

      Simple: clear, debuggable, logically organized, and debuggable code.

      Don't define functions inline of your statement.
      Don't perform evaluations in your return statements.
      Avoid calling methods/functions on objects via the return of another evaluator.

      The code sample he provided is counter to reusability, readability, unsafe in that it doesn't evaluate possible nulls, and arguably impossible to debug.

      It has nothing to do with being a JavaScript guy or not. It has everything to do with the difference between being a programmer and a software engineer. They are two different things.

      --
      Loading...
    18. Re:Going down in flames by Assmasher · · Score: 4, Insightful

      Why not?

      Well, it is unsafe, is anti-reusability, unclear, and impossible to debug without rewriting it to see why it doesn't work or suddenly stopped working. Defining a function inline to your statement, and in that function performing evaluations in your return call that are based upon objects that may be null when you execute an operation on them?

      There's no need to go verbose for verbositys sake, and that piece of script is pretty neat.

      There is a need to go verbose for the sake of everyone else who may ever have to work in the same codebase.

      If you place a completely green web-developer in front of it, sure, he might have a hard time reading it, but if jQuery is a tool you use, and webdevelopment what you do, then this really shouldn't be much of a problem at all.

      I'm not trying to denigrate you in any way, but this type of attitude is the difference between programming and software engineering. It is the discipline to do extra work that is tangibly less fun than doing clever or fun things.

      I don't enjoy long variable names.
      I don't enjoy modified Hungarian notation.
      I don't enjoy seeing an obfuscating and clever way to manipulate something but then do it a more plodding and clear (if equally efficient) way.
      I enjoy software architecture, but I don't enjoy writing up the design.
      I don't enjoy the ridiculously long meetings involved in matching up the design to the spec to the requirements.
      I don't enjoy putting in long comments to make absolutely sure someone coming in to fix a bug in the future is aware of the caveats of the possible changes they could make.

      I do these things because I need to do them for the sake of the codebase/product/Company/Investors.

      --
      Loading...
  2. A language that compiles to JS by wisnoskij · · Score: 4, Informative

    You could try a language that compiles to JS/etc.
    My friend uses HaXe for all of his server development (http://haxe.org/doc/why).

    --
    Troll is not a replacement for I disagree.
    1. Re:A language that compiles to JS by tomk · · Score: 3, Informative

      Unfortunately this is a great way to have to learn two languages (HaXe and Javascript) instead of one. I believe browser support for "source-level" operations (debugging, profiling, etc) for compile-to-JS languages will come some day, but that day is not today.

    2. Re:A language that compiles to JS by mihajul · · Score: 5, Informative

      On the topic of languages that complile to JS, GWT is very nice, especially if you're using a Java back-end.

    3. Re:A language that compiles to JS by Derek+Pomery · · Score: 3, Informative

      https://github.com/kripken/emscripten

      w/ emscripten, if you can output llvm from your language, you can run it in javascript.
      Emscripten author claims 2-3x of optimised C.

      --
      -- perl -e'print pack"H*","6e656d6f406d38792e6f7267"' /. ate my old sig. Bastards.
    4. Re:A language that compiles to JS by Belial6 · · Score: 3, Insightful

      That would contradict the point of his request. The only real answer is the first one given. Don't try to make it what you know. If you want to have skills in a language, learn the language. I could say that I can write code in Machine Code because my because my C compiler outputs machine code, but that doesn't make it true. If DocDyson learns HaXe and compiles to JS, he doesn't know JS he knows HaXe. His request for a good IDE is a valid one. His request for some good libraries that will smooth the learning curve is valid. A request for libraries that will make JS more like C is not valid, as it will not only prevent him from actually learning JS, but it will be useless in an environment that he doesn't have primary control of. If you want to be competent in JS, you have to learn the JS way.

  3. Javascript: The good parts by mhh91 · · Score: 5, Informative

    I suggest reading this book, it's gotten a lot of good reviews, I've seen a lot of people recommend it to people starting out with JS.

    It explains a subset of Javascript that's simple to use, and also the most used in practice.

    1. Re:Javascript: The good parts by markkezner · · Score: 5, Funny

      It's also a really thin book. Burn.

      --
      Dangerous, sexy, turing complete: Femme Bots
    2. Re:Javascript: The good parts by Anonymous Coward · · Score: 3, Interesting

      Take Douglas Crockford's advice: "JavaScript is Lisp in C's clothing."

  4. As a Javascript developer... by RyuuzakiTetsuya · · Score: 5, Funny

    My advice?

    Scotch.

    Lots and lots and lots of scotch.

    Preferably something that burns horribly on the way down and leaves you with a miserable hang over. Only because you've got to look forward to something that hurts less than JS development at the end of the day.

    --
    Non impediti ratione cogitationus.
    1. Re:As a Javascript developer... by RyuuzakiTetsuya · · Score: 4, Informative

      A serious answer is to not feel bad about using a framework like jQuery. It helps to know what jQuery's doing on the inside first and foremost.

      --
      Non impediti ratione cogitationus.
  5. Not an Old-School Problem by RonBurk · · Score: 3, Interesting

    Most "old school" programmers have some interpreted language in their toolkit. People who think "old" means 40 probably have Python/Perl/etc. People who are really old probably had Basic/Awk/etc. So, nothing to do with how long you've been programming, more to do with how narrow your background is. As with learning any new language, there's no getting around the basic advice of: Write More Code.

  6. Dart? by supersat · · Score: 4, Informative

    Have you tried Dart? It's like JavaScript but with optional typing, and it compiles down to JavaScript.

    1. Re:Dart? by Threni · · Score: 4, Funny

      Counterfeight? I certainly did hear it here first. Sounds a little like what the rest of us call counterfeit. You're using a strongly typoed language, right.

    2. Re:Dart? by Concerned+Onlooker · · Score: 5, Funny

      "Have you tried Dart? It's like JavaScript but with optional typing, and it compiles down to JavaScript."

      If the typing is optional how do you actually program it? Voice recognition?

      --
      http://www.rootstrikers.org/
    3. Re:Dart? by Lord+of+the+Fries · · Score: 3, Insightful

      Interesting term. I can clear up the guesswork on why the type system is the way it is a little bit. Lars Back and Gilad Bracha, two of the primaries for Dart, came out of the Self group. Self was an interesting Sun funded experiment where they took the "pure objects all the time, all the way down" ideas behind Smalltalk and took them to a new level by throwing out the classes as well. One of the things pursued was a dynamic method dispatching system, that while dynamically typed (this is different than untyped), could get as much mileage as possible out of run time navel gazing to dynamically optimize the execution. There are some good papers describing how cool some of the stuff they did was/is. This group already liked the idea/value of dynamic languages, and have since been involved in various projects all built around this idea: take a dynamic typed system and make it go fast. Strongtalk was what followed. And then Sun bought them back and their work became the HotSpot VM. And Lars built an embedded Smalltalk along the same ideas in the meantime. While doing prison time with Java, Gilad began Newspeak (a module happy variant of Self/Smalltalk/etc). And Lars helped with the V8 JS engine that everyone knows well about. Along with all of this, all the way back to Strongtalk, they've always held that while a runtime system should be entirely dynamic (e.g. no hints required from a static type system), they see great value in being able to express types from a documentation/communication pov within the code. So the type systems, that any of these languages have had (which all share these similar values) have always been for expressiveness only. Personally I don't agree with this, but it's an interesting position that I've always tried to appreciate.

      --
      One man's pink plane is another man's blue plane.
  7. Adapt or die by Telek · · Score: 5, Insightful

    This depends - are you looking to learn the new coding methods to remain competitive in the workplace, or just for fun?

    Honestly if you make a living doing this then you need to adapt. You need to get over your preconceptions and accept the changes to the way computing works. There are millions of programmers out there, if you want to stay employed you need to show that you're adaptable to the new technologies while applying all of the tried-and-true knowledge and experience from your past. It's hard enough to get a job when you're more than a decade out of school.

    Trust me, I understand where you're coming from. I hate the inefficiencies of the languages these days. I dislike the general idea of doing anything other than a script in a scripted language. However my (perhaps anachronistic) viewpoints don't have many applicable places anymore. Unfortunately the tradeoff between RAD and proper coding often leans a little too far to the RAD side, necessitating the use of many types of languages and tools that you will undoubtedly not enjoy.

    Not only will you be a lot more productive, but you'll be a lot more marketable if you just succumb to the "dark side" that is today's trend in programming languages.

    --

    If God gave us curiosity
    1. Re:Adapt or die by Threni · · Score: 5, Insightful

      That's why he asked the question.. Do you have an answer?

  8. go assert yourself... by TheCouchPotatoFamine · · Score: 3, Informative

    let go, my man... breath the untyped air.

    Real tip: "use strict" at the top of your code and and write using assert() methods. A little more tedious, but your used to that, right? Being "dyed-in-the-wool" and all...

    --
    CS majors know the time/space tradeoff, but they never get taught the 3rd, crucial, tradeoff of the set: comprehension!
  9. one word: JQuery by thatisscary · · Score: 5, Informative

    While it won't get you over the loosely typed nature of the language, it will make things a bit more manageable. You can write nice terse code which accomplishes oodles, as opposed to hand rolling everything. There is something nice to javascripting. I find it a nice respite. JQuery makes it beautiful.

    1. Re:one word: JQuery by coffeeyesplease · · Score: 4, Informative

      Completely agree. My advice to you is learn JavaScript on it's own merits. Stop comparing it to C/C++/Java or whatever. heck, you might even have to stop thinking in objects and all that comes with OOP because sometimes it just doesn't apply. In my experience and for what I see with most of my programmers, is that no one really bothers to learn JavaScript. They just keep on doing whatever they're we're doing in C/C++/Java and then complain about how crappy everything is. A good starting point is this book http://eloquentjavascript.net/ it's free and it's a also refresher on computer science in general, download chrome or firefox (with firebug) to help you debug (c'os that's a frustrating task, at times) As someone mentioned already it's a completely different mindset. I personally have a hard time programming anything that is not strongly typed. Mainly because I'll go into it already thinking that I don't like it.But for someone who's been programming applications (some web, some not) for 13 years, JavaScript can help you achieve wonders. I find practically unavoidable when it comes to web applications and it has helped me achieve some UI stuff that I thought impossible just last year. (and yes, JQuery is a must)

  10. That's an antipattern by slimjim8094 · · Score: 4, Informative

    I have no particular love of Javascript, but when I work in it, I write Javascript. When I use Python, I write Python, not Java. When I use C++, I write C++, not C.

    It's hard. It's annoying. But the idea is that you write the language like a "native". If you're really a generalist, it's not such a big deal. Read plenty of good Javascript to learn the idioms common to the language, and go from there.

    I could write for loops using counters and statements terminating with semicolons in Python. But I don't. I use iterators, list comprehensions, and so on. Because that's how Python code is written.

    The way I see it, the goal of learning a new language is the same whether it's a programming language or a spoken language - to be able to do useful things with it, and ideally come off as a native speaker. Look at it as a matter of pride.

    --
    I have developed a truly marvelous proof of this comment, which this signature is too narrow to contain.
    1. Re:That's an antipattern by multipartmixed · · Score: 3

      If you've been programming long enough, you realize that programs have "shapes" and programming languages are really .. like, ah..spoken languages.

      Most people think of callback-heavy library routines, reams upon nested reams of functions (encouraged by jQuery and ilk) when they think of the JS language. This language makes it particularly easy to write programs of certain shapes (spaghetti is a shape, right?). Just like it is probably easier to write an opera in Italian (or Klingon) than Russian, because the words flow into the form better.

      But, when writing JS to do UNIXy things, the code starts to feel a lot C, because the shape is UNIXy and we strongly associate C with UNIX. Just like a Russian rock song still sounds like a rock song. It might sound a little wonky, but you would totally identify it as a rock song because of the form (shape).

      Here's a snippet from some UNIXy JS I wrote a couple of years ago. Obviously, it's not for the browser, it's for a POSIX system -- and I think that makes my point:

      /**
        * Determine whether two paths refer to the same storage (file or directory), either by
        * virtue of symbolic or hard links, such that modifying one would modify the other. In
        * the case where either some or all paths do not exist, we return false. If we are
        * unable to verify if the storage is the same (such as by having insufficient permissions),
        * an exception is thrown.
        *
        * @param pathA A file or directory name
        * @param pathB A file or directory name
        * @returns boolean
        */
       
      exports.same = function same(pathA, pathB)
      {
        var sb1 = new ffi.MutableStruct("struct stat");
        var sb2 = new ffi.MutableStruct("struct stat");
       
        if (stat(path, sb1) != 0)
          sb1 = false;
        else
        {
          if (stat(path, sb1) != 0)
            sb2 = false;
        }
       
        if (!sb1 || !sb2)
        {
          if (ffi.errno == ffi.dh.ENOENT)
            return false;
       
          throw new Error("Unable to compare '" + pathA + "' and '" + pathB + "'" + syserr());
        }
       
        if (typeof sb1.st_dev != "undefined")
          if (sb1.st_dev != sb2.st_dev)
            return false;
       
        if (typeof sb1.st_rdev != "undefined")
          if (sb1.st_rdev != sb2.st_rdev)
            return false;
       
        return sb1.st_ino == sb2.st_ino;
      }

      --

      Do daemons dream of electric sleep()?
  11. Why? by LizardKing · · Score: 4, Interesting

    Why bother making the transition? You're background sounds like mine - C, C++ then Java - and based on a few years of dealing wih Perl I'd never willingly use a weakly typed language. Many errors in statically typed languages can be caught by the compiler, static analysis tools or nowadays by the IDE. Whereas with crap like Perl, JavaScript or *spit* PHP, such tools are hindered by the language and often by the libraries to the point where you'll drown in warnings that may or not be of genuine concern. In short, your existing skills are in demand, so leave the crap languages to the script kids.

    1. Re:Why? by hibiki_r · · Score: 3, Insightful

      Dynamically typed languages almost demand a large unit test suite to minimize quality issues. TDD and all that. If you are going to do that anyway, the dynamic language's weaknesses don't come into play as much, and you get the advantages, like typically needing a whole lot less code to get the same thing done. Look at Groovy, for instance: You can typically reproduce a Java program in half the code, and that if you are not facing one of those problems where dynamic typing really makes your life dramatically easier.

  12. should get you started... by VoidEngineer · · Score: 5, Insightful

    First, get thee Aptana for development.

    Second, download thee jQuery. I would also recommend jQuery Mobile and jQuery.tools.

    Third, dig around in jquery until you find qunit for unit testing.

    Fourth, do a refresher on Lisp and functional languages. They say that javascript got it's fathers curly braces and it's mothers lexical scope. It may *look* like C/C++/Java, but under the hood is ActionScript ala Scheme ala Lisp. And it a very real difference which gets played out in copious usage of events and callback functions. As a refresher, the HTML5 paradigm is basically an MVC paradigm, where HTML is handling the Model, CSS is handling the View, and Javascript is handling all the controller functions. Phrased differently, the HTML is describing the What is displayed; CSS is describing How it should be displayed, and Javascript is describing When it should be displayed. And the When gets implemented as callbacks and events. And it just so happens that functional languages are ideally suited for that kind of work (ala lambda calculus, etc).

    Lastly, if you're brave, check out Node.js.

  13. Seriously, find something else to do... by Assmasher · · Score: 3, Interesting

    JavaScript can do amazing things, but it's a total disaster if you're coming from a more traditionalist background.

    Let me give you a taste of what's to come for you :).

    Let's say you have an Applet/ActiveX Control/Plugin of some type that your company has built and needs to be scriptable from JS, and it must also be able to call into JS (JavaScript devs can register for events, notifications, console/logging messages, et cetera...)

    You add a new feature to your Company's doohickey. Now you need to test it properly.

    Your customer set requires that you need to test on OSX Snow Leopard, OSX Lion, Windows XP, Vista, Win 7, OpenSUSE, Redhat, and Ubuntu. On each of these operating systems you need to test on the most popular browsers, so you get jiggy with Safari, Firefox, Opera, IE7, IE8, IE9, Konquerer, et cetera... Then you, depending upon the plugin's architecture, need to test on both 32-bit and 64-bit versions of the plugin in each browser on each operating system.

    That's not even getting started with Mobile, or JRE versions, or different deployment types, code signing, et cetera, ad nauseum, ad infinitum.

    If you think you don't need to test like that, you're in for a rude awakening my friend... For example, this very testing led to our discovering that in Firefox, on Windows 7 rapid LiveConnect usage between an Applet and JavaScript is perfectly fine if the applet has focus, or another windows has focus, but causes total freezing of Firefox/Java Plugin IF THE FOCUS GOES TO ANOTHER ELEMENT ON THE SAME WEB PAGE. How's that for crazy sh**? :) LOL.

    Anyhow.

    Browser application development is a nightmare.

    I would pay good money for them to rip JavaScript out and everyone get together (yeah, I know, pipe dream) and come up with a client side scripting language that rocked oldSk00l.

    --
    Loading...
  14. GWT by alannon · · Score: 3, Informative

    I think GWT is actually a reasonable tool for writing code that compiles to Javascript. This makes a lot of sense if you're writing your server code in Java, since your server and client code can all live within the same source tree and be edited with the same IDE in the same language. Significantly, this also allows you to debug your code using your Java debugger (read up on 'hosted mode' if you want to understand that witchcraft) while it's running in your browser. GWT also de-fangs the javascript event model that often leads to memory leaks. It might be of benefit to some people that by default (you can turn it off) the emitted JS code is heavily obfuscated. GWT is mature and well-supported, and integrates simply with vanilla JS code if you wish to.
    Available for GWT is GWTQuery, which is (you've probably guessed) a jQuery clone for GWT, including events, effects, etc...

  15. Try the Dojo Toolkit by hilather · · Score: 3, Informative

    The Dojo Toolkit definitely makes javascript feel a little more friendly.

  16. My tip by bonch · · Score: 3, Insightful

    My tip is to never let yourself remain attached to a particular subset of languages for 20 years. Absorb all crazy things, because it makes you better in all languages.

    Try LISP sometime.

  17. Dynamic typing is paradise. As is static typing. by Qbertino · · Score: 4, Insightful

    I'm just going the other way. Building my first app in C++ using Qt. Which basically goes like this: OMG you piped a literal string without it being a genuine QString into my label ... KERNEL PANIC! CRASH! 10 bazillion compiler errors. ... WTF?
    Of course this sucks. However I'm well seasoned enough to know that when building a non-trivial application, it's exactly this sort of thing that will save my sanity in the long run.

    With dynamically typed languages it's the exact opposite. Try building an IDE in JS. It has been done, but it need a solid amount of thorough planning and the one or other hack/stunt. However, writing a little script in JS is like having awesome sex compared to doing the same 'three-liner' in C++ which is like masturbating with a cheese grater in comparison. And still uses 30 lines.

    All I can say is go with the flow. Wrap your head around dyn typing if you are not used to thinking in it and eventually you'll see the beauty in JS which blows C++ out of the water in the areas it is meant for.

    Keep up with the spirit and good luck. ... And now excuse me, I have to set up my little QWidget 20-something lines of code with 20 typecasts strewn about just to get the bloody label to show a simple literal when I click a menu entry.

    My 2 cents.

    --
    We suffer more in our imagination than in reality. - Seneca
  18. Use Google's 'Closure Compiler' by arthur5005 · · Score: 3, Informative

    http://code.google.com/closure/compiler/ It's exactly what you're looking for. It does type checking, it checks syntax and variable reference, it does file dependancy, and has a great inheritance system so you can get back to your Java/C++ ways. It's just awesome.

  19. Get Over Yourself by cthlptlk · · Score: 5, Funny

    Nan-in, a Japanese master during the Meiji era (1868-1912), received a university professor who came to inquire about Zen.

    Nan-in served tea. He poured his visitor's cup full, and then kept on pouring.

    The professor watched the overflow until he no longer could restrain himself. "It is overfull. No more will go in!"

    "Like this cup," Nan-in said, "you are full of your own opinions and speculations. How can I show you Zen unless you first empty your cup?"

  20. Perl by rrohbeck · · Score: 3, Interesting

    Learn Perl first. Or maybe LISP. That way you'll get rid of the statically-typed mindset.
    Java/ECMAscript is Perl/Python in C++/Java clothes. Don't even think about C++ or Java. It doesn't work that way. :)

  21. It's a good time to look, but I wouldn't jump in by fean · · Score: 3, Informative

    Take a look at Sencha / ExtJS... It's aimed squarely at enterprise-level developers/engineers, not the script-kiddies that rant and rave about the cool shit they can do because they've overwritten a 'built-in' type. It should work with Google Closure, as well...

    IDEs are in terrible shape. There's WebStorm and Aptana... neither of which hold a candle to what you're used to, but it's better than notepad/textmate. I'm an linux/eclipse guy, but can't get used to the ways that Aptana breaks shit, so I tend to jump back and forth between WebStorm and SublimeText (it looks nice, but it's not 'all there').

    There are some good books out there, JS: The Good Parts, Eloquent Javascript (free)... and I'm starting on Test-Driven Javascript Development, though I can't say if it's any good yet...

    I'd recommend doing a little bit on the side, get your feet wet, but don't commit yet. Thinks have changed a lot in the last year or two, and nearly everyone and their dog is becoming an HTML5/JS Dev. You're behind the curve already, and will have a hard time getting ahead, so I'd wait until the editors and browser compatibility is better before diving in.... don't ignore it, and if you can find someone who will pay you to torture yourself, do it... but don't be too anxious.

  22. Re:GWT by JThaddeus · · Score: 4, Informative

    I second this. I've been using the Google Web Toolkit (GWT, http://code.google.com/webtoolkit/) for about 5 years now with good results. Write in Java, compile to Javascript, and let GWT handle the browser differences. The source is all there if you want to see how their Javascript works, and you can insert you're own Javascript code when and where you want it. Finally, the user's group has been an excellent source of advice.

    --
    "Love is a familiar; Love is a devil: there is no evil angel but Love." --William Shakespeare ('Love's Labors Lost')
  23. Re:Know the language, practice safe coding by nomel · · Score: 3, Interesting

    I think he's basically asking for jslint, where you can catch errors many levels deep in your code at compile time, rather than waiting for the code to crash when it, eventually, gets run (in unit test or whatever).

  24. Go with the flow, my man by multipartmixed · · Score: 5, Insightful

    I have 20 years of C under my belt, 15 of those paid. I currently spend the vast majority of my time writing JS, and I love it.

    Back in the good old days, we didn't pick C because of it's great syntax, or the warnings from the compilers (which have gotten much better in the last 20 years!). We picked it because it fast, portable (enough), available, and you could use it to do the stuff we were interested in.

    Well, times have changed. JS and CPUs are now fast enough that execution time is not were "fast" usually matters: *developer* time is. JS syntax is good enough. Runtime warnings are getting good enough if you're writing ES5 strict code. Most importantly, if you're writing code for the web, you pretty much have to pick JavaScript. (Just like writing X11 code 15 years ago pretty much meant C++).

    Syntax -- "go with the flow, my man". It's juicy, delicious. Don't be limited by the lack of types: embrace the flexibility. Prototypal inheritance is awesome in its simplicity, shallow object hierarchies make for easy reasoning. Make you *get* closures.

    Functions are first-class members, like strings and arrays and objects. Sure, their literal syntax is longer than "", [] or {}, but function(){} is still a literal.

    Just as the developer who thinks GNU make is some kind of super-shell is doomed to failure, so will the developer who thinks JS is a variation of something else.

    JS isn't the new C. It's not the new Java. Or C++. Or Scheme. Or Perl. Or Python. Or Logo. Or BASIC. It's JS.

    I currently write a LOT of day-to-day mundane code in JS. Some exciting code, too. I write web pages, validate forms, load modules (CommonJS), and design object exchange protocols and the applications which use them. That's on the web browser.

    On the web server, I'm using it kinda like 1995's PERL. I query databases, do CGIs. I can call into POSIX. I write daemons, and "shell scripts". Some week I'll spend a few days and make my CGIs faster than CGIs. Remember mod_perl? Same deal. Mast fast_cgi. I dunno, performance metrics say I don't need to quite yet.

    It's a hell of a language. But if you really want to work with it, you have to "get it". Be comfortable with it's multi-faceted layer. Understand that it's "functional", "object oriented", and "imperative", all at the same time.

    In C, the Zen boils down to "everything is just a number". That's why string operations are so easy in C once you "get it". In C, the Zen boils down "everything is just a jsval". So, it's IS typed -- everything is the same variadic type. Get over writing reams of code to make your little soldiers walk the goose step, and just tell them where to go. They'll get there.

    --

    Do daemons dream of electric sleep()?
  25. Re:JS is not OO by BitterOak · · Score: 4, Informative

    Javascript is not perfect but more importantly, it's not OOP.

    Actually, Javascript is object oriented. It's just that, unlike most object oriented languages, it is prototype based rather than class based. Both are legitimate forms of object oriented programming, although class-based is more popular now.

    --
    If I can be modded down for being a troll, can I be modded up for being an orc, or a balrog?
  26. Javascript: The Good Parts (Douglas Crockford) by oldspicepuresport · · Score: 5, Informative

    This is book is worth every penny and more (~$18 on amazon).

    Like the submitter, I come from C/C++/Java background and always despised Javascript whenever I had to deal with it. I picked up this book a few months ago and can confidently say that this book completely changed my view of Javascript. Javascript is a quirky language, and has some really bad parts (the book has a chapter dedicated to the bad parts). This book clearly explains common misconceptions about the language, as well as all the things a programmer used to a more traditional language needs to look out for. The book explains how Javascript works under the hood in great detail (the prototype-chain, functional scope, type conversion and equality, first class objects/functions ,closures, etc.)

    This is a book for programmers, it's not a cookbook or how-to, and you need a good understanding of programming for it to be useful. That being said, for programmers coming from more traditional languages to Javascript, this book is exactly what you're looking for. I can honestly say that in a few short months Javascript has gone from one of my most hated languages to one of my favourites. The language is incredibly powerful and expressive once you get a good understanding of how it works and why.

  27. Here's an example by gr8_phk · · Score: 4, Insightful

    How does the code look that much different? Besides some syntax differences, they're all almost *exactly* the same. Some languages force you to format your declarations and types differently, but a for loop is a for loop

    for (x=0; x lessthan 10; x++) //sorry, can do lt in comment
    {
    square[x] = x*x;
    }

    That's a for loop, while this:

    square = [x*x for x in range(10)]

    is a list comprehension in Python.

    You can write it like a for loop - and I did when I was first learning Python - but it sucks to do that. This is probably what the GP was alluding to. If you really know a language you don't want to read crap written by people who think they're all the same with different syntax. This of course is but a single small example.

  28. Re:I thank you for y0ur time by Spiked_Three · · Score: 3, Funny

    Yes, that is what Java script code looks like.

    --
    slashdot troll = you make a compelling argument I do not like the implications of.
  29. Sure ... The first thing you should do is by hey! · · Score: 5, Insightful

    Stop building narratives like "I'm an X type of guy trying to do Y." That's bound to increase your frustration with what are most likely going to be the normal road bumps in learning to do things differently. Think "different tools and methods for different jobs."

    Instead of asking "how do I make working in toy language like Javascript tolerable for *real* programmer like me," you should be asking "how do the very best Javascript programmers do what they do?"

    And don't think of yourself as "dyed in the wool" anything. Think of yourself as a versatile person who likes learning about new ways of doing things, because you've got a *lot* more to learn than just the Javascript *language* if you want to actually *use* Javascript. You've got to learn about DOM and CSS and HTTP and web application architecture and security. Once you learn about those things and learn how to actually do something useful with Javascript, you'll be in a much better position to make an *informed* critique the design of the language, popular libraries and frameworks like JQuery, and common Javascript idioms. It makes no sense to approach mastering the whole Javascript ecosystem with preconceived notions about its shortcomings. You aren't qualified to judge yet.

    Learning a new kind of tool means learning new kinds of skills and strategies. Some aspects of the tool will seem like major problems with the tool until those good habits become second nature. For example novice Java programmers tend to create code that allocates unnecessary strings inside loops, when they should be using a StringBuilder. The result is the programmer thinks that it's Java that's slow, when it's really their ignorance of efficient Java programming idioms that's to blame.

    --
    Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
  30. You have a clear anti-JS bias. by Static · · Score: 5, Insightful

    Your post reads a lot like all those people who hate PHP. "It has all these things wrong with it!" Well, actually, no it doesn't - because most of them aren't a problem to the people busy using it effectively. JavaScript doesn't have 'inferior' abstractions: it has *different* ones.

    I have programmed a lot over the decades in both strongly typed and weakly typed languages - too many to name. I've come to Java in the last few years after a much longer time in JavaScript and PHP (and others) and have experienced the reverse of the OP's problem. But it's only a problem if you let it be a problem. Solving problems in an untyped language has some fundamental differences to a typed language. Get over that and a lot of the perceived 'problems' Just Go Away.

    1. Re:You have a clear anti-JS bias. by Anonymous Coward · · Score: 5, Insightful

      Your post reads a lot like all those people who hate PHP.

      So he's an experienced professional software developer who cares about the reliability, performance, maintainability, correctness, portability, and the overall quality of the code he writes. That's not a bad thing at all. You should listen to him. What he wrote is absolutely right.

  31. Re:Dynamic typing is paradise. As is static typing by Anonymous Coward · · Score: 3, Informative

    ... And now excuse me, I have to set up my little QWidget 20-something lines of code with 20 typecasts strewn about just to get the bloody label to show a simple literal when I click a menu entry.

    You're doing it wrong
    http://stackoverflow.com/questions/1814189/how-to-change-string-into-qstring

  32. Your are clearly too rational to be here... by snowgirl · · Score: 4, Insightful

    Please get off the intarwebs... your clear and concise explanations of matters is undesired here in this wretched hives of memes and flamewars.

    Seriously though, you're totally right. It's different. It's not inferior, it's different.

    People who complain about this or that language being a piece of crap because of X and Y, are usually deadset in one particular mode of thinking, and cannot adapt. The question the original author should have been asking was not "how can I make this tolerable", but rather, "how can I best learn the correct way to use this tool?"

    To put things in perspective, I was already doing a lot of crazy command-line parsing before I ever started using C. And when I started using C, I was upset, because I knew what I wanted to do, and I could easily accomplish it in BASIC, but C was different. The whole paradigm was new to me, and I had to learn to adapt. I haven't forgotten that, and I try to keep myself from becoming entrenched in any particular mode of thinking... it leads to inflexibly dictating that all else is inferior.

    --
    WARNING! This girl exceeds the MAXIMUM SAFE standards established by the FDA for BRATTINESS
    1. Re:Your are clearly too rational to be here... by shutdown+-p+now · · Score: 4, Insightful

      It makes no sense to claim that programming languages can't be meaningfully compared with respect to things like efficiency, conciseness, level of abstraction etc. It may be politically correct (towards VB/PHP/JS crowd), but it's still false.

      Yes, languages differ. Yes, there's no single one that's the best. No, that doesn't mean that your favorite language is just as good as mine (unless your favorite language is Common Lisp).

    2. Re:Your are clearly too rational to be here... by justforgetme · · Score: 4, Interesting

      Programing languages are tools. The only objective comparison for tools is the
      objects they can produce; programs.
      So to objectively compare programing languages you must compare programs
      that do exactly the same thing but are written with different programing languages.

      Now how easily would you create an asynchronously interactive web site
      without javascript and how would it perform?

      --
      -- no sig today
    3. Re:Your are clearly too rational to be here... by Alex+Belits · · Score: 4, Insightful

      web

      Here is your problem. Javascript is an awful language, it just by the whim of Netscape it is the only one available in a browser. This does not mean, Javascript is good, it means that Netscape fucked up, and no one was around to fix the problem because everyone was busy fending off Microsoft and Adobe, who tried to "standardize" everyone on things that make Javascript look good.

      A good solution would be to use Java or C++ with Qt, and distribute the application with sources (and everyone who opens his mouth about revealing the source code is welcome to shut up because Javascript is always distributed in source anyway). This may be an overkill for something as simple as a widget for displaying lists/icons/graphs..., but for a complex application Javascript is still a bad language.

      Same applies to writing "for consumer PC" and Win32/.NET/other horrible things from my "favorite" company.

      --
      Contrary to the popular belief, there indeed is no God.
    4. Re:Your are clearly too rational to be here... by TheRaven64 · · Score: 3, Insightful

      I'll prefix this by saying that Javascript is not my favourite language, although I have written a compiler for a dialect of it and an Objective-C compiler that emits JavaScript.

      A lot of what you're talking about has nothing to do with the language and everything to do with the libraries. Given a DOM binding and a function for generating asynchronous HTTP requests, everything that you request is pretty trivial in most high(ish)-level languages and would almost certainly perform better. Writing a fast implementation of JavaScript is insanely hard. One of the big reasons why it is easier to make Java perform faster than Smalltalk - in spite of the fact that the two have a lot in common in terms of memory and object models - is that Java has integer types, so a + b can be compiled to a single add instruction by a naive compiler, while doing the same thing in Smalltalk requires you to perform some nontrivial type inference. In JavaScript, it's even worse because integers must transparently overflow to double-precision floating point values.

      It would almost certainly be more maintainable too. JavaScript was intended for scripting, not for writing large applications. It lacks any module feature - or even classes. You can split a JavaScript program into multiple files, but then including them in a different order can significantly alter the semantics of the program. In other languages, you can separate independent parts into separate components and not, for example, pollute the global namespace with local concerns.

      --
      I am TheRaven on Soylent News
    5. Re:Your are clearly too rational to be here... by shutdown+-p+now · · Score: 3, Insightful

      Now how easily would you create an asynchronously interactive web site without javascript and how would it perform?

      You need to define what a "website" is for this to work.

      The problem is that "website" is, effectively, defined by W3C. And W3C, in their infinite wisdom, standardized on JavaScript as the scripting language for the web. So, as of today, the definition of website essentially includes JS, and excludes other languages, making any such comparisons irrelevant.

      We came up with some workarounds for that, like X-to-JS compilers. Unfortunately, because the end result is still JS, this approach doesn't let you actually realize the performance benefits of a statically typed PL on VM level, since all types are erased by the time code is running.

      However, it is perfectly possible to do a "what if?" - take some other PL, and see how well it would fit into the niche occupied by JS today. And if you do that, you suddenly realize that practically any mainstream dynamic language, excepting possibly PHP, would do all the same things better.

  33. Re:Any rational programmer is anti-JS by John+Courtland · · Score: 3, Interesting

    Javascript has closures and none of the other languages have them, sorry buddy, Javascript has superior abstractions.

    --
    Slashdot is proof that Sturgeon's Law applies to mankind.
  34. B0rked closures is enough for JS loving? by Anonymous Coward · · Score: 5, Insightful

    Java has better closures. Clunky, sure, but not broken.

    Scala has better closures. Closures you can love.

    Haskell has total awesomeness oozing out of its handling of closures.

    Javascript is retarded in all ways. It's just flabbergasting that anyone defends it.

  35. Re:Any rational programmer is anti-JS by shutdown+-p+now · · Score: 5, Informative

    Javascript has closures and none of the other languages have them

    All mainstream languages except for Java have lambdas/closures (and Java is getting them in the upcoming release).

    For that matter, most languages that do have lambdas, provide syntax for them that is considerably less verbose than that of JS - which makes a lot of sense when you actually start using lambdas heavily. To give an example with fold used to sum a sequence (assuming fold is a member function in all cases, for the sake of uniformity, and ignoring the ability to treat operator itself as a binary function in languages that support it):

    // JS
    xs.fold(function(x, y) { return x + y; });
     
    // C#
    xs.fold((x, y) => x + y);
     
    ' VB
    xs.fold(Function(x, y) x + y)
     
    // Java 8
    xs.fold((x, y) -> x + y);
     
    // Scala
    xs.fold(_ + _)
     
    # Python
    xs.fold(lambda x, y: x + y)
     
    # Ruby
    xs.fold {|x| x + y }

  36. Re:Any rational programmer is anti-JS by velinion · · Score: 4, Informative

    Wow. Lisp has closures, and it dates back to 1958. Not that I like Lisp a whole lot. I prefer to have syntax beyond parenthesis.

    When I need closures and a functional programming paradigm, I usually turn to OCaml myself. (Cue hated from the lisp crowd)

    Seriously, programming language preference is like editor preference. It has a lot to do with what you are most used to, and a lot to do with how your mind happens to be most comfortable thinking.

    I prefer the much shorted debugging period afforded by strongly typed statically typed languages, even though it forces me to jump through some hoops that a weakly typed dynamically typed language would save me form. Personally, I've coded in C, Java, C++, Perl, Python, OCaml, Lisp, Scheme, PHP, Prolog, Javascript (very little) and Basic. Among these, Perl, Ocaml, Lisp, and Scheme all make extensive use of closures. Others may as well. (I just haven't used closures in more than those 4)

    --
    In life, not all of your questions will be answered; all of your answers will be questioned.
  37. Re:Any rational programmer is anti-JS by Anonymous Coward · · Score: 5, Informative

    I guess C++ isn't a mainstream language anymore. Go figure.

    Actually, C++ has it since C++11... but with typed arguments of course:


    # C++
    xs.fold( [](int x, int y) { return x + y; } );

    Of course, both Javascript and C++ are still much less powerful than any variant of LISP.

  38. Re:Any rational programmer is anti-JS by rmstar · · Score: 4, Insightful

    Actually, C++ has it since C++11... but with typed arguments of course:

    C++ closures are what happens to a beautiful abstraction after it goes through mordor. It becomes an orkish, vile thing more fit to hurt the user and confuse him than to achieve something of good and beauty.

    I mean, where's your GC?

  39. He wants Google Web Toolkit by Requiem18th · · Score: 4, Informative

    I agree, it was flammish to say JS has inferior abstractions. It DOES have LESS abstractions. But the few it has are actually more powerful and general than Java's. In other words JS is more orthogonal than Java, you do more with less, which is a good thing, and I say this as a harsh critic of JS!

    But typechecking is one of those things that, while dynamic programmers like me shrug, does make a lot more sense than I usually accept. If static type checking is for you, JS isn't. However it is possible to compile Java to JS, there are several implementations but the best one is Google's Google Web Toolkit which is exactly that. A Java environment that compiles to Javascript.

    --
    But... the future refused to change.
    1. Re:He wants Google Web Toolkit by Broolucks · · Score: 5, Interesting

      JS's problem is not dynamic typing, it's that it is not strict enough. If you try fetching a property or method that doesn't exist on an object in Python or Ruby, which are dynamic languages, you get a runtime error. In JavaScript you get undefined, in Lua you get nil. But even Lua doesn't allow you to do freaking *arithmetic* on nil, and fetch arbitrary properties on numbers and strings. In JavaScript, undefined + 0 is valid and yields NaN, and then you can happily keep operating on that value until you crash and burn. And then you can do {} + [], giving 0, and [] + {}, giving "[object Object]". It is ridiculous. All of these additions should be errors, plain and simple, and ideally, x.y, when y is not a field of x, should be an error. Maybe x.?y and x[?y] could return undefined or nil in these situations, as a handy syntactic sugar.