4 ms·
My main problem with Javascript is the various truthiness rules as well as the numerous implicit conversions to strings. Eg. > [2,1,3,10,6, 200].sort() [1, 10
by jtuple 12y ago
My main problem with Javascript is the various truthiness rules as well as the numerous implicit conversions to strings.
Eg.
> [2,1,3,10,6, 200].sort()
[1, 10, 2, 200, 3, 6]
is both unexpected, and is just one of many landmines that can completely derail beginners.
- rectangletangle 12y agoJavaScript has numerous caveats and idiosyncrasies that result in strange and unexpected behavior. It's scoping rules are also pretty broken. While Python does have some of its own quirks, they're far fewer in number. There are two that bite people pretty often, using a mutable type as a default function parameter, and accidentally typing a comma after an expression subtly converting it to a tuple.
- Pacabel 12y agoA lot of the problems with JavaScript aren't "caveats and idiosyncrasies" or "quirks". They're rather horrible and unjustifiable flaws, plain and simple.
- rectangletangle 12y agoI agree, they are horrible flaws. Though to be fair, you have to understand why JavaScript has as many flaws as it does. I believe this is largely due to the context in which it was created. First, it was written in the absolute minimal amount time possible. "If it fits, it ships", really applies here. Second, JavaScript was designed to make sub 200 line scripts that add basic interactivity to web pages, not to make the complex layered applications it's often used for today.
- Pacabel 12y agoThat was true in 1995. It's now 2014. There has been ample time to fix the many flaws. There's no justifiable reason why, nearly 20 years on, JavaScript is still so inherently busted in so many ways.
- rectangletangle 12y agoOnce again, I entirely agree. I personally wish browsers could run a sand-boxed Python implementation, with some sort of DOM interface. Think `import dom`. Ideally browser's would agree on a hard set of standards ahead of time, so things like jQuery would be unnecessary (even though jQuery is about the only good thing involving JavaScript).
- nmjohn 12y agoI can't disagree with you at all, though I don't necessarily share the same level of contempt for javascript. The thought of creating a "new" and "fixed" language to replace it brings the xkcd comic on standards to mind (#927). I would argue there is a justifiable reason. Before I do bear in mind I accept it may not be a good reason, or one without workarounds, but hindsight makes both of those much easier to see than in the day to day development. Backwards compatibility. The two words which really haunt web developers everywhere, on so many levels. We don't want old sites to break in new browsers, or new sites to break in old browsers, so fixing major issues of such magnitude would require at a minimum a unique version that could be differentiated from older sites. And when was the last time you saw a version of javascript specified in a websites code? So then a situation occurs where we could use the new code and "do it right," but we would need fallbacks for old browsers. Or, we could "do it wrong," only use the old way, and development would take significantly less time. While over time the new way likely would win out, it would be a long and drawn out process taking enough developers and managers putting their feet down and saying, no, while this will take more time, cost more money, for the exact same functionality, it is the right thing to do for the future of the language. And getting their bosses to accept that tough sell. The above seems very similar to HTML5 and IE6/7 support. And how long has that fight been going on? So yes, one would think the flaws should be fixable, but looking at it from an in the moment perspective as opposed to through the lens of history, it isn't completely incomprehensible as to why they still exist. Another thought that just popped into my head, is for the majority of the life of javascript, it was used by web developers, many of whom would by todays standards be much closer on the spectrum to "my nephew who designs websites" than a software engineer. It wasn't until much more recently that it began to heavily be used by engineers who pushed the limits much further and ran into these problems. It makes me curious on when the first documented case of these issues was brought up. Was it 20 years ago, or maybe only in the last 5?
- notduncansmith 12y agoThis may be an unpopular opinion (certainly contrary to what the majority of publications on the web would have one believe) but I wouldn't consider Javascript a beginner's programming language. C was hard for some kids to grasp in my high school class, but I didn't struggle with it, and it certainly taught me rigor and attention to detail. Ruby (on and off Rails) helped me build things without getting bogged down in syntax; the LOC-to-output ratio was quite gratifying. Only later did I progress to writing non-trivial Javascript. While it's an incredibly powerful language (when I hear people describe the "enlightenment" of developing in Lisp, I'm often reminded of JS), it has a lot of warts that, as you rightly stated, can throw beginners for a loop. I imagine that if I had encountered the example you described above at the beginning of my career, I would have decided that Javascript is for the birds and resolved to just write C/C++ for the rest of my life.