5 ms·
My problem with CoffeeScript has always been the syntax vs. semantics issue. CoffeeScript saw a big opportunity to improve JavaScript semantics and help program
by aclimatt 13y ago
My problem with CoffeeScript has always been the syntax vs. semantics issue. CoffeeScript saw a big opportunity to improve JavaScript semantics and help programmers more easily avoid the JavaScript minefield ("var" and "===" for example), but in doing so decided "while we're at it, let's overhaul the general syntax too".
Gratuitously changing "function" to "->" for no reason other than removing characters seems to introduce more brand new idiosyncrasies than it's worth. If the goal were to improve JavaScript as a language by smoothing over a few of the gotchas, which of course would require a few syntax updates, then I think it would be immensely valuable. (Think SCSS instead of the original "Sass".) But it seems as if the authors were more troubled that JavaScript didn't write like Ruby, so they made a new language that happens to compile to JavaScript. And now I have two languages to choose from, each with pros and cons and their own gotchas, adding more complexity to my decisions when I was hoping for simplification.
- joev_ 13y ago> Gratuitously changing "function" to "->" for no reason other than removing characters seems to introduce more brand new idiosyncrasies than it's worth. What idiosynchrasies are you referring to here? Just curious. I love the stabby lambda (for the exact reason you listed, because I am defining functions on every other line).
- andrewvc 13y agoI totally disagree regarding 'function'. Good javascript tends to be more functional than imperative. That means using 'function' a lot. Most functional languages use either fun, fn, or lambda, all relatively short words for this because it's used ALL THE TIME. Shortening it to two chars made sense IMHO. The long form of the word function directly impacts code quality and readability.
- jrpt 13y agoThe arrows are better because they're shorter, more math-like, and because there's two of them (skinny and fat arrows) that do useful things. For what it's worth, the arrow syntax is likely going to be in JS at some point: https://mail.mozilla.org/pipermail/es-discuss/2012-March/021872.html https://mail.mozilla.org/pipermail/es-discuss/2012-March/021...
- cben 13y agoIf all you want is a sane subset of JS, then all you need is a JS linter. The whole point of the language was more compact syntax. Shortening lambdas is one of the most important changes because it makes heavy callback/DSL code viable. Exhibit: http://coffeekup.org/ http://coffeekup.org/. Now renaming JS's `for (name in obj)` to `for name, val of obj` and redefining `in` to `for x in array` is indeed confusing (coming from other languages I can see how it's better than JS ideosyncratic use of `in` but still confusing...)