5 ms·
I've been writing JS for over a decade and never had a problem with it. I put off CoffeeScript for ages, because nothing was wrong with my JS code. "Besides,"
by doublerebel 14y ago
I've been writing JS for over a decade and never had a problem with it. I put off CoffeeScript for ages, because nothing was wrong with my JS code. "Besides," I thought, "CoffeeScript compiles to JS, it can't do anything JS can't do."
And that is true. Nothing is exactly wrong with JS. In fact many things are great about JS, which is how we end up with ClojureScript and CoffeeScript and x86 emulators. JS is very powerful -- maybe too powerful. There are a million ways to accomplish the same task, which means that during an initial look at a new JS codebase, the program flow is not obvious.
Some developers hate semicolons, some always put commas at the end of the line and some at the beginning, some always use braces and some don't use braces with single-line statements. One can never be sure where a statement ends, or what constitutes a code block, unless one hunts down all the trailing braces, parentheses, and semicolons. I'm not even going to mention all the possible inheritance patterns.
CoffeeScript is not nearly as flexible in syntax. There is one way to make a code block, one inheritance method. It doesn't need semicolons, braces, or parentheses because of its strict style. Therefore there is less to think about. There is less to go wrong. No one needs to use a CoffeeScriptLint, because CoffeeScript is not full of non-obvious 'gotchas'.
CoffeeScript code is more concise and more intuitive, because it reads more like an English sentence. When I read another developer's CoffeeScript I can begin understanding the meaning instantly, rather than having to spend time determining the structure and programming technique. List comprehensions, ranges, and other functional programming tools simply don't exist in pure JavaScript -- the JS equivalent is much more verbose and much less obvious. CoffeeScript encourages creating small flexible code blocks, which together make a powerful structure. This all leads to fewer opportunities for bugs to appear.
The only thing I don't like about CoffeeScript, is that I didn't keep an open mind and start using it sooner. I think anyone who considers themselves a serious JS developer should give CoffeeScript a try. It's a much more relaxing, simple way to write powerful JS.
(Credit goes to Spine.js switching to CoffeeScript to finally push me into it.)
EDIT: Of course it is possible to write ambiguous, unclear code in any language. CoffeeScript is an opportunity to let go of old habits and find a fresh perspective on problem-solving: Maybe there is a better way to do things. (I had to let go of semicolons!)
CoffeeScript's functional programming style has changed the way I approach programming. My code is now more robust and less complicated. Less bugs and less keystrokes mean I ship faster. CoffeeScript is a better language because it's a tool which makes me a better developer.
- deleted 14y ago[deleted]
- jlongster 14y agoThere's definitely improvements to the language in CoffeeScript. It makes sense; it was able to take 10 years of js experience and write a new language. But that doesn't mean CoffeeScript itself is without problems, or that it even improves development time. There's certainly many different ways to do things in CoffeeScript, like even calling functions (parenthesis is optional). Talk about having to think about syntax! http://stackoverflow.com/questions/12077114/coffeescript-syntax-structure-is-wrong http://stackoverflow.com/questions/12077114/coffeescript-syn... There are other ambiguities too due to the arrow pattern for defining functions. You have to be careful where you place stuff. CoffeeScript is definitely an improvement in some ways, but please don't market it as superior to javascript (I certainly prefer brackets). It's just different. All of this really doesn't make much difference in how long it takes you to ship products.
- MatthewPhillips 14y ago> CoffeeScript encourages creating small flexible code blocks, which together make a powerful structure. This all leads to fewer opportunities for bugs to appear. Personally I find single-line statements that do too much to be difficult to read. I also find nested functions really difficult to read in CS. From a coffee mug I own: coffee.height drink coffee, e.angle That's only 2 functions, it gets much more confusing when it's 3 or 4 which multiple parameters. Before you say "don't nest functions that way", I agree completely, however a large part of the appeal of CS is reducing LOC and these one-liners, so in real world code I've come across this often.