Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Although I like Javascript and its tools have improved dramatically in the last few years, a number of cases (like [] + {} vs. {} + []) are decisively non-ideal for teaching people who are not somewhat versed in programming languages. It's this kind of thing which gave Javascript a reputation as a kind of client side PHP.

I would be very happy if these kinds of irrationalities could be ironed out in a future version of the language, even if it meant backward incompatibility.

If the language is thoroughly rationalized and there is a simple, beautiful API for graphics then I think it becomes the beginner's language to end all (since client-side web is such a nice platform to target). But for now, it isn't there... I'd be happy to hear that it was a priority.

Perhaps something like Dart will pick up that quest.



I think for the purpose of teaching people the basics of programming it's perfectly acceptable to leave them with a basic understanding of "You can only add numbers and strings." Then allow them to revisit the oddities much later after they have a much better understanding of what objects are. Honestly, I think it might be acceptable to just ask the student to explain to you how "object addition" would work. There are various ambiguous problems you could run into (concatenating two objects with the same property name but different values). I think this basic understanding is enough that even a novice would accept.

I think things like dynamic "this" in javascript will be more confusing for newcomers. But, once you start talking about "this", you should probably already have the basics down.

Edit: With all that said, I'm not saying Javascript is a great language to learn programming with. But I don't honestly know of a single language that I would be perfectly comfortable telling people to learn with. Most languages have their own quirks.


Tangent: to be clear, there is no difference between []+{} and {}+[] in javascript.

var a = {} + [];

var b = [] + {};

var c = String({}) + String([])

All three are equal. The order does matter in general because its doing string concatenation which obviously matters ([1] + [2] == "12"), but the fact that js always does string coercion and concatenation anytime you have + without numbers on both side isn't really that crazy.


Type coercion is crazy, if for no reason other than making the behavior of certain code harder to predict. That said, I don't think it's a major stumbling block, and once you learn to avoid relying on it there's no problem.

There are plenty of parts of JavaScript like that, but these gotchas are just red herrings. The core language is great.


There is a slight difference between []+{} and {}+[], in fact, but you're unlikely to see it outside of a console. At a console, {}+[] gives you 0, which is different to the result you get above. That's because it's an empty block followed by +[].


perfect!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: