4 ms·
There are real semantic differences in CoffeeScript. As listed by jashkenas himself more than a year ago in response to the same accusation: Leaving features o
by chc 15y ago
There are real semantic differences in CoffeeScript. As listed by jashkenas himself more than a year ago in response to the same accusation:
Leaving features off the table and just talking about semantic cleanups, here's a few:
* Switch statement doesn't fall-through by default.
* Variables don't need to be declared with "var", and can't ever become global accidentally.
* Equality is strict, using `===`, if you want coercive equality, you coerce the object yourself.
* Loops that are used to generate functions close over their index variables, so that all inner functions don't share the final value of the index. This is the same problem that ECMAScript Harmony introduces "let" to solve.
* Splats largely replace use of the "arguments" object, so you don't get bit by "arguments" only being a faux-array.
* Comparisons can be chained, as in Python -- so you can write: "100 > x > 25", and have the answer be correct.
* Multiline strings are valid without having to escape the newline.
* And the big one: everything in CoffeeScript is an expression. Without having to use temporary variables, you can return the result of an if/else from a function, pass a comprehension (loop) directly into a function call, assign the result of a try/catch, and so on.
(http://news.ycombinator.com/item?id=1697586 http://news.ycombinator.com/item?id=1697586)
- antirez 15y agoThat's definitely more semantics that I thought it contained, thanks for the clarification. However for the same reasons the debugging problems are probably more severe than I realized before.
- chc 15y agoAs I said elsewhere, unless you believe the CoffeeScript compiler is introducing bugs into correct code, I'm not sure I understand your concern. Does the fact that C has different semantics from machine code generally make debugging C harder than debugging machine code? There is still a very close relationship between the CoffeeScript and the JavaScript — closer than, say, what you get with GWT or Closure Compiler. The ease of reading and writing and the reduction in source code length is worth the minor context switch to many people. It's easier to spot a bug in five concise lines than in 25 lines of mostly boilerplate.
- antirez 15y agoFor not using Javascript itself, that is widely understood across the programming community, that is not perfect but either not a disaster as a language, I would expect a lot more gains from a to-javascript-compiler. Here what I see is that there are a few semantical changes and syntax changes, but for me this is not enough to switch. What I think the value of CoffeeScript could be is to show how Javascript could be improved in the next versions.