TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why CoffeeScript Isn't the Answer

136 pointsby jhackabout 11 years ago

41 comments

crazygringoabout 11 years ago
I used CoffeeScript full-time for a year, both client-side and server-side (node.js). I completely agree with everything here -- it&#x27;s a <i>great</i> summary, and it describes exactly while I never, ever want to use it again.<p>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 &quot;realistically, the issues I have raised with CoffeeScript don’t come up every day,&quot; but in my experience they pretty much did.<p>But the real kicker on top of it all is that none of the stuff is documented. When you&#x27;re trying to guess if you should use parentheses or a comma or an indent or a newline or a backslash or <i>what</i>, there are no reference documents to help you. The CoffeeScript home page just has a bunch of tutorial examples which give you an overall idea, but there&#x27;s nothing rigorous, and the devil is in the details when you start combining aspects of the syntax.<p>In the end, I&#x27;m much more productive programming in JavaScript because I know <i>exactly</i> how the language works, no surprises. JavaScript has its fair share of warts, but you take a day or two to learn them, and then you never need to worry about them again. CoffeeScript, on the other hand, is just endless surprises. And I still felt that way after a whole <i>year</i> of using it at work. It&#x27;s basically unlearnable -- no matter how much experience you have, you constantly find yourself pasting different versions of a line into the &quot;try&quot; tab of <a href="http://coffeescript.org/" rel="nofollow">http:&#x2F;&#x2F;coffeescript.org&#x2F;</a> until you get one which, through trial and error, turns into the JavaScript code you want.
评论 #7497760 未加载
couchandabout 11 years ago
This article proves not that CoffeeScript is flawed but that Jeff Walker doesn&#x27;t understand how to use it. For instance, his first example is:<p><pre><code> # BROKEN func 5, { event: (e) -&gt; if e.something 36 else 45, val: 10} </code></pre> Anyone with more than a day&#x27;s experience with CoffeeScript knows that it&#x27;s much better to express this with the simpler:<p><pre><code> # far better func 5, event: (e) -&gt; if e.something 36 else 45 val: 10 </code></pre> Note how just dropping the excessive notation makes the intention clearer while also making the code cleaner.<p>His example on variable capture neatly illustrates a few of the opinions of CoffeeScript that actually make it far easier to reason about code: don&#x27;t use global variables, and if a variable has the same name, it should refer to the same thing. It&#x27;s far more confusing to allow rampant variable shadowing. Code that relies on variable shadowing is simply broken.<p>His last example shows a fundamental misunderstanding of not just CoffeeScript, but JavaScript generally. Granted `this` binding can be sometimes confusing, which is why CoffeeScript has a fat arrow (`=&gt;`) to automatically capture `this`.
评论 #7497354 未加载
评论 #7497209 未加载
评论 #7497436 未加载
评论 #7497361 未加载
评论 #7497574 未加载
评论 #7498465 未加载
shittyanalogyabout 11 years ago
It&#x27;s a tool, that is all.<p><i>Ambiguous code</i> is a poorly thought out contrived example with a simple solution.<p>To me, this:<p><pre><code> eat food for food in foods when food isnt &#x27;chocolate&#x27; </code></pre> Is kind of beautiful and much more readable than:<p><pre><code> for (var i = 0, var len = foods.length; i &lt; len; i++) { var food = foods[i]; if (food !== &#x27;chocolate&#x27;) { eat(food); } } </code></pre> How is this even an argument?: <i>&quot;One wouldn’t realize it was conditional until reading the end.&quot;</i> How do you expect to understand any code without reading it? How do you understand people when they talk without listening? And the whole paragraph is moot with syntax highlighting.<p>Variable clobbering is javascript&#x27;s problem not coffescript&#x27;s.<p>ECMAScript 6 introduces a syntactic sugar for classes as well as like every single JS framework.<p>Knowing plain old JS is important, especially for understanding CS. CS is just a tool that some people find useful, I don&#x27;t really understand the passion or frustration.
评论 #7498818 未加载
评论 #7498759 未加载
hhsnopekabout 11 years ago
Ok, so if CoffeeScript is just JavaScript, add the parenthesis. If you need brackets to make a section of code readable or compile to &quot;certain&quot; JavaScript, then add them. Even the programs I work on we add parenthesis, brackets, etc for readability. Use CoffeeScript to increase productivity. Nowhere does CoffeeScript say you must use white space instead of brackets and such. Keep it simple and easy, classes are also nice; I&#x27;ll be reading those are articles soon as well to gain less of a bias.
评论 #7497069 未加载
freyrabout 11 years ago
<i>&gt;&gt; Why CoffeeScript Isn&#x27;t the Answer</i><p>What <i>is</i> the question for which CoffeeScript is a compelling answer?<p><i>&quot;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&#x27;t get my point across, but French is prettier. Can I recreate this experience in code?&quot;</i><p><i>&quot;My team can&#x27;t learn to write `var` or `===`. Can we just learn a new language instead?&quot;</i><p><i>&quot;Indentation speaks to my aesthetic sensibilities, but braces do NOT! What fits my needs?&quot;</i><p><i>&quot;I don&#x27;t want to use JavaScript. Fortunately, since I never make coding errors, I&#x27;ll never need to debug transpiled JavaScript. What&#x27;s the right language for me?&quot;</i><p>Seriously, though, what is the problem that CoffeeScript solves?
评论 #7497775 未加载
berdarioabout 11 years ago
I agree with some the things he writes, but others seem blatant absurdities:<p>&gt; &quot;the + operator is still both numeric addition and string concatenation. That is frequently listed as one of the bad parts of JavaScript. Why no provide separate operators for the two?&quot;<p>The problem isn&#x27;t operator overloading: the problem is implicit type coercion.<p>Having to use 2 separate operators&#x2F;functions for separate types when writing code, is useful only if types are actually checked at compile time, and the compiler can do inference on them (see the + and +. operators in F#)<p>If you have a dinamically typed language, you can have sane semantics if you make it so that type conversions are explicit (e.g. Python, Ruby...)<p>See also: <a href="http://james-iry.blogspot.it/2009/03/operator-overloading-ad-absurdum.html" rel="nofollow">http:&#x2F;&#x2F;james-iry.blogspot.it&#x2F;2009&#x2F;03&#x2F;operator-overloading-ad...</a>
评论 #7497597 未加载
kevingoslarabout 11 years ago
This article only proves that when doing it wrong, CoffeeScript causes problems.<p>No parenthesis make nested calls unreadable? Simple add parenthesis for the inner calls. Like in any other language with optional parenthesis (Ruby) too.<p>Too long statements are unreadable? Don&#x27;t write them. Maintaining an 80 or 100 character line limit is good coding practice anyways.
评论 #7497476 未加载
ceronmanabout 11 years ago
This is not the first article talking about CoffeeScript&#x27;s ambiguity and readability issues.<p>It&#x27;s interesting how CoffeeScript fans almost always decide to blame the programmers for these problems. They said good developers should use common sense and use best practices to make code readable, for example by always using parentheses when calling functions. I hear exactly the same argument in the Perl community.<p>But reality is that if a language allows you to write bad code easily, people will write bad code, and you will have to read bad code. This is very easy to verify: most CS project on GitHub, starting with the CS code itself (<a href="http://github.com/jashkenas/coffee-script" rel="nofollow">http:&#x2F;&#x2F;github.com&#x2F;jashkenas&#x2F;coffee-script</a>) contain a lot of bad ambuigous uses of the language. A very similar thing happens with Perl code.<p>Programming language design is not only about making it easy to write good code, but also about making it hard to write bad one.
评论 #7499219 未加载
untogabout 11 years ago
I do have some frustrations with CoffeeScript as outlined here - I find the unless keyword infuriating because it forces me to read backwards:<p><pre><code> a = 123 unless b == 2 </code></pre> &quot;OK, so a is set to 123. Oh, unless b is 2. That&#x27;s annoying&quot;<p>That said, my answer is to just not use the unless keyword. If you don&#x27;t like CoffeeScript classes, you don&#x27;t have to use them. IMO you could write CoffeeScript using only the kind of functionality availabie in vanilla JS and it would <i>still</i> be a preferable experience.
评论 #7497393 未加载
评论 #7499430 未加载
评论 #7500705 未加载
评论 #7497183 未加载
darkxanthosabout 11 years ago
Am I the only one astounded that we&#x27;re still having this conversation? The fact that it&#x27;s still around shows me it has indeed been &quot;the answer&quot; for some. The fact that it hasn&#x27;t become ubiquitous is plenty of proof that it also is not a one size fit all solution, as if any solution is.
omarantoabout 11 years ago
I wonder what the author thinks of GorillaScript [1].<p>[1]: <a href="http://ckknight.github.io/gorillascript/" rel="nofollow">http:&#x2F;&#x2F;ckknight.github.io&#x2F;gorillascript&#x2F;</a>
评论 #7496982 未加载
RossPenmanabout 11 years ago
&quot;CoffeeScript isn&#x27;t the answer because I don&#x27;t understand how it works.&quot;
philliphaydonabout 11 years ago
This seems to share many of the same things of CoffeeScript I&#x27;ve had. I prefer plain old JS. More readable, unless you&#x27;re looking at twitter bootstrap code... No semicolons? Such messy code IMO.
mrinterwebabout 11 years ago
I find CoffeeScript very readable, and I highly value readability. The extra verbosity of JavaScript doesn&#x27;t really help me when I am reading code. I read CoffeeScript code faster than I can read JavaScript because CoffeeScript removes so much of the repetitive boiler plate code and lets you focus on the intent of the code.<p>I don&#x27;t really understand the ambiguity argument. From the code examples in the article, I get the impression that the author doesn&#x27;t really understand CoffeeScript.<p>I definitely prefer CoffeeScript to good old JavaScript.
Daizabout 11 years ago
I had a lot of niggles with CoffeeScript as well, which is why my compiles-to-JS language of choice is LiveScript[1]. It fixes basically all the annoyances and adds a lot of nice things on top of that. For exmaple, you can write more paren-free code with it and there are more kinds of useful function declarations (hushed functions, curried functions, backcalls).<p>[1] <a href="http://livescript.net/" rel="nofollow">http:&#x2F;&#x2F;livescript.net&#x2F;</a>
kinabout 11 years ago
Mm, most of the issues the article discusses are part of the learning curve of Coffeescript IMO. The real problem I&#x27;ve had (and I still love it for some reason) is dealing w&#x2F; JS frameworks. Like, try using Coffeescript w&#x2F; Angular or something. It&#x27;s quite difficult.
Roboprogabout 11 years ago
Disclosure: I have never used CoffeeScript. However, based on the article, the death-knell against CoffeeScript for me was the variable scoping rules.<p>With no variable declaration keyword (a la var, my, local, private), adding a variable assignment anywhere could radically change the variable scoping.<p>I&#x27;m done, this isn&#x27;t suitable for prime-time, time to go somewhere else.<p>I spent too many years in the 80s working with xBase. I&#x27;ve been shafted too many times by calling a (coworker&#x27;s) routine that forgot to declare its variables &quot;private&quot;, which stomped over one of my variables. (private in xBase is similar to local in Perl 4) To have a language which doesn&#x27;t let you declare the intended scope of a variable - ugh.
评论 #7497276 未加载
评论 #7497364 未加载
评论 #7497346 未加载
评论 #7497230 未加载
评论 #7497718 未加载
rubiquityabout 11 years ago
Phew. I was beginning to worry that a whole month would go by without a blog post about CoffeeScript&#x27;s deficiencies. I hate it when I write unidiomatic code in a language and then get punished by said language.<p>Now that I got my sarcasm out of the way, whenever somebody bashes CoffeeScripts variable shadowing they openly show the world that they don&#x27;t understand how variable scoping <i>should</i> work. CoffeeScript covers up JavaScript&#x27;s warts. One of those warts is JavaScript&#x27;s broken implementation of closures. CoffeeScript is trying to help you, don&#x27;t let your lack of understanding of lexical scope get in its way.
klibertpabout 11 years ago
&gt; The declaration of what food is occurs in the middle of the line and doesn’t even look like a variable declaration.<p>And that&#x27;s what makes the whole line unreadable. And &#x27;unless&#x27; would make it even less readable.<p>I can understand why people insist on discussing such personal, subjective matters as &quot;readability&quot; or &quot;expressiveness&quot; - I like that too. What I don&#x27;t get is why do they confuse their impressions with facts and why do they try to generalise based on them. Is it that hard to admit that what&#x27;s readable to you may be completely unintelligible to someone else?<p>Comparison of programming languages, outside of some really technical metrics, will always be subjective and preference-based. Discussing metrics as vague as &quot;readability&quot; without even agreeing on what it means is absolutely pointless. Yet so many man-hours go into debates and blog posts, sometimes even books, which cover such issues. It&#x27;s stupid, straw-man discussion every single time it appears.<p>I really wish people would stop writing lengthy posts with a sole purpose of informing the world about their preferences. It&#x27;s not that I&#x27;m against people having preferences, I&#x27;d just like them stated as preferences, not facts, and preferably only when they are not repeated a millionth time this month.<p>Edit: also, this: <a href="http://joelgrus.com/2013/12/24/why-programming-language-x-is-unambiguously-better-than-programming-language-y/" rel="nofollow">http:&#x2F;&#x2F;joelgrus.com&#x2F;2013&#x2F;12&#x2F;24&#x2F;why-programming-language-x-is...</a>
ColdHawaiianabout 11 years ago
&gt; eat food for food in foods when food isn&#x27;t &#x27;chocolate&#x27;<p>&gt; from the CoffeeScript tutorial...Furthermore, <i></i><i>until you finish reading the line it isn’t clear which foods will be eaten</i><i></i>.<p>The thing with typing the filter at the end is, that format has its basis in mathematical notation, particularly in set theory. Using an even terser mathematical syntax&#x2F;notation, you could write the same expression this way:<p><pre><code> { eat(food) : ∀ food ∈ { foods } ^ food ≠ &quot;chocolate&quot; } </code></pre> You read that as &quot;the set of eat(food) where for all food in the set of foods, the food isn&#x27;t chocolate&quot;. The notation will be quite familiar to mathematicians, and thus if you have a strong mathematical background, especially in set theory, discrete math, and combinatorics, the CoffeeScript array comprehension feels natural.<p>See the Wikipedia article on Set-nuilder Notation&#x2F;Set comprehension, <a href="http://en.wikipedia.org/wiki/Set_comprehension" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Set_comprehension</a>.<p>Here&#x27;s another example from the Wikipedia article:<p><pre><code> { x | x ∈ R ^ x = x^2 } </code></pre> This reads as &quot;the set of all x, where x is a real number and x = x^2&quot;, which evaluates to the set { 0, 1 }.
tomphooleryabout 11 years ago
I believe there will be a day when converting CoffeeScript to just native JavaScript won&#x27;t be very difficult, but until that time, it&#x27;s useful as a way to have neat syntax features without having to wait for browsers to support it. Indeed, many of the features CoffeeScript introduced into the JS developer&#x27;s mindset are or will be present in the upcoming ECMAScript specifications. We can only assume this trend will continue.
solox3about 11 years ago
<p><pre><code> delayed: () -&gt; -&gt; this.model # isn&#x27;t the class </code></pre> Well, that isn&#x27;t really fair now, is it? You could have used the fat arrow (`=&gt;`) for binding `this` to the class.<p>With that in mind, I agree with the author in that CoffeeScript isn&#x27;t the answer, at least not exactly. With syntax this incredibly similar, how far are we from compiling python (with generators, with statements, imports, ...) to JavaScript?
评论 #7496893 未加载
评论 #7497836 未加载
评论 #7496872 未加载
rzimmermanabout 11 years ago
This is a bit overly critical. The implicit parentheses are optional, so if it&#x27;s confusing or ambiguous you should just use parentheses.<p><pre><code> func 5, { event: -&gt; 45, val: 10} </code></pre> Is reasonable but<p><pre><code> func 5, { event: (e) -&gt; if e.something 36 else 45, val: 10} </code></pre> Really ought to be split up for readability no matter what programming language you use. And besides, the only issue is the extra comma causes it not to compile.<p>To be fair, the `-&gt;` vs `=&gt;` (which `this` is `this`?) for class members is confusing. I&#x27;d almost prefer class members didn&#x27;t give you the option and defaulted to `=&gt;`.<p>The &quot;variable capture&quot; section is overblown, though. You&#x27;re a lot less likely to run into this issue than the classic JavaScript &quot;I forgot `var` and now my variable is global.<p>My biggest complaint is actually the implicit returns. Sometimes I forget a return statement but it works anyway because of this feature. Then I come back later and modify the function slightly only to spend a bunch of time figuring out why it&#x27;s returning `undefined`.
评论 #7497245 未加载
z3phyrabout 11 years ago
Then, for sure, Clojurescript is the answer.
评论 #7497915 未加载
评论 #7497068 未加载
slang800about 11 years ago
The example in &quot;Ambiguous Code&quot; is ridiculous - if you write CoffeeScript like that then you have much bigger problems. Also, the part in &quot;Classes Are an Illusion&quot; totally fails to mention the fat arrow `=&gt;`, which solves the main issue the author raises.<p>However, this part I completely agree with:<p>&gt; Realistically, the issues I have raised with CoffeeScript don’t come up every day. Ultimately though, they are enough to say we need something better. I hope to share some thoughts soon on what such a solution might look like.<p>CoffeeScript isn&#x27;t perfect and we should always be looking for better solutions. So I&#x27;m glad that the author wants to add to the discussion. While CoffeeScript isn&#x27;t <i>the</i> answer, it&#x27;s probably the best answer we have so far,
ritwiktabout 11 years ago
Coffee-script is awesome but suffers from it&#x27;s roots as a preprocessed layer on top .. and that essentially leads to poor overall tool chain support .. I actually enjoyed writing code in it .. debugging not so much .. Would love some of the constructs to make into JS
AdrianRossouwabout 11 years ago
I have a rule of thumb that coffeescript is never appropriate for code that has to be require()&#x27;d by any code written by somebody else than me.<p>I&#x27;ll happily use coffeescript, and enjoy doing so, when that condition is met. It doesn&#x27;t happen very often though.
mrcsparkerabout 11 years ago
While it might not be the answer, it has been a very good answer for me. Recently I worked on an Angular project that had a pretty complex data model, and converting the model to CS made the code much more readable. The rest of the app was still in JS, minus a .&#x2F;models directory which was CS. The other devs found the code very readable also.<p>I am biased towards Python and Ruby. I think that they are nice looking languages.<p>Different tools for different jobs. Next time I am on a JS project and I want to model data, I will probably use CS again.
timestepabout 11 years ago
Answer to what? What&#x27;s wrong with Javascript in the first place?
评论 #7499192 未加载
评论 #7496757 未加载
评论 #7496779 未加载
评论 #7496752 未加载
评论 #7497235 未加载
ryanatknabout 11 years ago
The only gripe I share is scoping, and that&#x27;s fixed in LiveScript. I&#x27;ve started writing LiveScript in a fairly explicit style - for example I use parentheses where they improve readability and I always use curly braces for object literals. Qualitatively I think it&#x27;s increased the readability of my code way beyond JavaScript. It&#x27;s nice to have curly braces carry specific meaning instead of being littered all over the place.
anotherevanabout 11 years ago
CoffeeScript is putting lipstick on a pig. It&#x27;s pretty damn good lipstick, but still being applied to a pig.
aclimattabout 11 years 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 (&quot;var&quot; and &quot;===&quot; for example), but in doing so decided &quot;while we&#x27;re at it, let&#x27;s overhaul the general syntax too&quot;.<p>Gratuitously changing &quot;function&quot; to &quot;-&gt;&quot; for no reason other than removing characters seems to introduce more brand new idiosyncrasies than it&#x27;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 &quot;Sass&quot;.) But it seems as if the authors were more troubled that JavaScript didn&#x27;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.
评论 #7497649 未加载
评论 #7497734 未加载
评论 #7497714 未加载
评论 #7497557 未加载
mck-about 11 years ago
These pitfalls can be easily avoided by following a styleguide [1]<p>[1] <a href="https://github.com/polarmobile/coffeescript-style-guide" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;polarmobile&#x2F;coffeescript-style-guide</a>
jbejaabout 11 years ago
There is still not &quot;answer&quot;, and the world is not gonna end tomorrow, in the future maybe will be one but until that day comes i will stick with whatever i find appealing to me at present. For now is CS.
h1karuabout 11 years ago
CLOJURESCRIPT IS THE ANSWER! no question about it
评论 #7497140 未加载
oinksoftabout 11 years ago
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 &quot;bad parts&quot; or &quot;really bad parts&quot; 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 CoffeeScript are the last gasp of the old regime.
评论 #7497031 未加载
评论 #7496888 未加载
评论 #7497488 未加载
评论 #7497796 未加载
评论 #7497391 未加载
评论 #7496914 未加载
iglabout 11 years ago
Livescript or Gorilla are what I would want from a .js precompiler. Coffeescript just removes brackets and readability.
tsenkovabout 11 years ago
&gt;I ... couldn’t figure out how to write the CoffeeScript for the JavaScript I wanted.
hmansabout 11 years ago
What is the question?
jbejaabout 11 years ago
Who said it was?
teemo_cuteabout 11 years ago
CoffeeScript seems to be an efficient alternative to plain Javascript. The fact is you can&#x27;t avoid seeing Javascript completely. Just try debugging in Chrome or any other browsers built-in debugger and you&#x27;ll know what I mean.