3 ms·
The reason to use CoffeeScript over JavaScript is because it is better software engineering. Number of lines of code has been shown to be one of the few good i
by ilaksh 14y ago
The reason to use CoffeeScript over JavaScript is because it is better software engineering.
Number of lines of code has been shown to be one of the few good indicators for predicting defects. CoffeeScript significantly reduces the number of lines of code in a project and therefore the number of defects.
CoffeeScript is cleaner and easier to read, which is better software engineering. CoffeeScript solves many of the issues with JavaScript. The fewer warts and plumbing people have to deal with related to the language, the more they can focus on the actual problems they wanted to solve.
This is a little bit like the architectural decision to program user applications in languages and platforms with garbage collection and built-in frameworks rather than using a language like C or C++ with manual memory management and minimal standard libraries. Sure you get less control over the lower-level details such as allocation and deallocation of memory, but those lower level details actually are distracting from the application domain and were actually repetitive and could be automated. So the best way to solve those problems is to move to a platform that abstracts them away or handles them for you.
The reason that developers don't like CoffeeScript (other than the fact that they haven't learned it yet, and don't want to take the time) is simple, psychological rather than logical, and its the same reason that they don't like platforms like the ones I was talking about above: it makes things significantly easier, and that is problematic psychologically for programmers for two reasons:
1) The whole point of being a programmer is that you are mastering complex ASCII codes that other people can't decipher. Making things less complex takes away part of your identity as a programmer (not for everyone obviously, but for many).
2) Many programmers instinctively and falsely believe that any system which makes their job significantly easier must automatically come with compensatory trade-offs in things like performance or flexibility. This is intuitive, but false.
CoffeeScript improvements: indenting two spaces and using -> plus no closing parens and curly braces makes nested callbacks much easier to read and write, fat arrow binds this making it easier to use classes, class and extends provide a standard, simple way to create and extend classes, iterating over arrays and objects is much easier and cleaner, control flow and function definition is cleaner, better variable scoping, simplified closer wrapper in loops, more straightforward boolean operators, existential operator for cleanly and simply checking for variable existence.
Thought of one other explanation for not liking CoffeeScript: plain old status quo bias. http://en.wikipedia.org/wiki/Status_quo_bias http://en.wikipedia.org/wiki/Status_quo_bias
- baddox 14y agoBy that reasoning, it is "better software engineering" to give variables, methods, etc. the shortest names possible.
- ilaksh 14y agoI took out the line about the number of characters. Number of SLOC corresponding to defect count is not something you dispute is it?
- thebigshane 14y agoI'll dispute it. If I cram more code into a single line it will not lower my defect count. In fact there is a chance that the concision may turn into clutter and become harder to read/maintain and that may increase defect count. Is there a measurement term for number of symbols (in the lisp sense) in a given program? Example: '+', 'add', 'defn' would all be individual symbols. I could see a loose correlation between symbol count and defect count... maybe. Or to go even more abstract: number of concepts per program is probably the ultimate measurement we are looking for: https://en.wikipedia.org/wiki/Concept https://en.wikipedia.org/wiki/Concept
- pooriaazimi 14y agoTrue. But CS doesn't encourage cramming more code in a single line, like veteran C++ers do. It just give you nice shortcuts for what you have to manually write in vanilla JS (like maps, array comprehensions, ...)
- AlisdairO 14y ago> Number of lines of code has been shown to be one of the few good indicators for predicting defects. Curious - is there evidence that that applies in a cross-language manner? It seems intuitively sensible that a smaller project will have fewer bugs than a big project, but that's not the same as saying that a big project rewritten in a language which causes fewer lines of code to be used will result in fewer bugs - in the latter case, the systemic complexity is the same.