Live data from Hacker News

Why CoffeeScript Isn't the Answer

walkercoderanger.com

91–100 of 148 posts

Re: Why CoffeeScript Isn't the Answer

#91

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 in…

The 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/021...

Re: Why CoffeeScript Isn't the Answer

#92
>> Why CoffeeScript Isn't the Answer

What is the question for which CoffeeScript is a compelling answer?

"I needed to speak to Germans, so I learned French and spoke through a French-German interpreter. Things were occasionally lost in translation and somteimes I couldn't get my point across, but French is prettier. Can I recreate this experience in code?"

"My team can't learn to write `var` or `===`. Can we just learn a new language instead?"

"Indentation speaks to my aesthetic sensibilities, but braces do NOT! What fits my needs?"

"I don't want to use JavaScript. Fortunately, since I never make coding errors, I'll never need to debug transpiled JavaScript. What's the right language for me?"

Seriously, though, what is the problem that CoffeeScript solves?

Re: Why CoffeeScript Isn't the Answer

#93

Disclosure: I have never used CoffeeScript. However, based on the article, the death-knell against CoffeeScript for me was the variable scoping rules. With no variable declaration keyword (a la var, my, local, private), adding a variable assignment anywhere could radically change the variable scoping. I'm done, this isn't suitable for prime-time, time to go somewhere else. I spent too many years in the 80s working wi…

I think the death-knell was that you didn't want to bother learning CoffeeScript so that you can actually make an informed decision.

Re: Why CoffeeScript Isn't the Answer

#94
post #75

Earlier quoted context omitted.

The point is it doesn't pass static verification. It doesn't compile. It's a rather silly thing for the author to argue imho.

Agreed. I was responding more to the assertion that CoffeeScript doesn't have a problem with variable scoping rules. It does and the consequences are scary.

You're right that the scoping rules in CoffeeScript are unintuitive for someone coming from a statically-typed, declare-everything paradigm. But I'd hesitate to call it a problem. It's a feature not a bug that the same symbol in nested scopes always refers to the same variable. As I said previously, I believe code that relies on variable shadowing to work correctly is broken.

I've been hit by the scoping rules many times, but every time I ask myself why I'm using identifiers like i, j or x to refer to different variables in nested scopes anyway. Names like that should be reserved for only the tightest of scopes.

Is there another aspect of the scoping rules that you're referring to?

Re: Why CoffeeScript Isn't the Answer

#95

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 in…

If 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/.

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...)

Re: Why CoffeeScript Isn't the Answer

#96

I used CoffeeScript full-time for a year, both client-side and server-side (node.js). I completely agree with everything here -- it's a great summary, and it describes exactly while I never, ever want to use it again. In CoffeeScript, ambiguous code is the rule, not the exception. On top of that, things like variable capture and everything-returns-a-value introduce new kinds of bugs. The author says "realistically, t…

You completely agree with everything he wrote, after a year full-time? Really?

So you would use curly braces and commas to specify an object, and then be confused when CoffeeScript doesn't get it?

After a year you didn't figure out that its a best practice to leave off the parenthesis in just the outermost function call, but to include them in the other calls on a line to make things clear?

After a year, you didn't realize that with the CoffeeScript scoping rules, you couldn't just throw in a global at the last second without looking carefully to see if it was used somewhere else?

After a year, you still hadn't learned about function binding with fat arrow?

After a year, you still hadn't learned that the existential operator (?) means you don't have to use typeof nearly as much?

Re: Why CoffeeScript Isn't the Answer

#97
post #92

>> Why CoffeeScript Isn't the Answer What is the question for which CoffeeScript is a compelling answer? "I needed to speak to Germans, so I learned French and spoke through a French-German interpreter. Things were occasionally lost in translation and somteimes I couldn't get my point across, but French is prettier. Can I recreate this experience in code?" "My team can't learn to write `var` or `===`. Can we just lea…

http://en.wikipedia.org/wiki/Status_quo_bias

CoffeeScript obviously solves problems. Its not compelling to you because of status quo bias, and because you don't want to invest the effort to learn it.

The issue with equality is a real issue. CoffeeScript solves that issue.

Braces and parenthesis _do_ become awkward in JavaScript with callbacks. CoffeeScript solves that problem.

You have been able to debug CoffeeScript as CoffeeScript for some time now with source maps. However, debugging the generated JavaScript is not hard for someone who knows JavaScript.

Re: Why CoffeeScript Isn't the Answer

#98
post #96

I used CoffeeScript full-time for a year, both client-side and server-side (node.js). I completely agree with everything here -- it's a great summary, and it describes exactly while I never, ever want to use it again. In CoffeeScript, ambiguous code is the rule, not the exception. On top of that, things like variable capture and everything-returns-a-value introduce new kinds of bugs. The author says "realistically, t…

You completely agree with everything he wrote, after a year full-time? Really? So you would use curly braces and commas to specify an object, and then be confused when CoffeeScript doesn't get it? After a year you didn't figure out that its a best practice to leave off the parenthesis in just the outermost function call, but to include them in the other calls on a line to make things clear? After a year, you didn't r…

Ha! Not necessarily those specific examples, but the overall reaction to it. Here are a couple of other articles which explain the same things:

Section "full of surprises": http://ruoyusun.com/2013/03/17/my-take-on-coffeescript.html

http://ceronman.com/2012/09/17/coffeescript-less-typing-bad-...

And here's an old HN comment of my own which described a few representative difficulties: https://news.ycombinator.com/item?id=4518892

Also, there's no such thing as a global in CoffeeScript (unless you explicitly specify window.xyz), since everything is scoped to the file. And that's the point -- it's ridiculous to have to "look carefully" at all your code to see if functions further down share a variable name inside of them. In JavaScript, you don't need to worry about that because you know "var" scopes each variable to its function, regardless of whether a higher function or global variable uses the same name. In CoffeeScript, you suddenly do have to worry about that, which is fairly insidious and bug-prone behavior.

Re: Why CoffeeScript Isn't the Answer

#99

Sometimes I think that most CoffeeScript, ClojureScript, etc. programmers are people who were advanced in other languages before they learned JavaScript. There are quite a few programmers who have no issues with these "bad parts" or "really bad parts" because they cut their teeth on them, and these numbers are growing: Most people now learn JavaScript as their first language. JavaScript already won, and things like C…

Your argument is that because programmers who learned JavaScript first "have no issues" with the "bad parts" or "really bad parts" that means they aren't really issues, or that we should ignore the issues and adopt JavaScript anyway because we don't want people to think that we are old?

Re: Why CoffeeScript Isn't the Answer

#100
post #96

Earlier quoted context omitted.

You completely agree with everything he wrote, after a year full-time? Really? So you would use curly braces and commas to specify an object, and then be confused when CoffeeScript doesn't get it? After a year you didn't figure out that its a best practice to leave off the parenthesis in just the outermost function call, but to include them in the other calls on a line to make things clear? After a year, you didn't r…

Ha! Not necessarily those specific examples, but the overall reaction to it. Here are a couple of other articles which explain the same things: Section "full of surprises": http://ruoyusun.com/2013/03/17/my-take-on-coffeescript.html http://ceronman.com/2012/09/17/coffeescript-less-typing-bad-... And here's an old HN comment of my own which described a few representative difficulties: https://news.ycombinator.com/item…

Hm.. well you may want to use more precise language in the future, because you said you "completely agree" and that it describes "exactly".

So you are saying that none of those particular issues are problems you are having today with CoffeeScript or were problems for most of the year?

In which case, what problems did you have?

Edit: it looks like in another thread you are pointing out some random and unmaintainable code examples that are ambiguous and saying that its hard to know how they will be interpreted by the compiler. Its hard to know how those examples would be interpreted by anyone, or why you would write code like that and create that problem for yourself.

Post reply on HN