The real reason for the CoffeeScript/JavaScript flame war
I have been slightly (but not entirely) surprised by the current flame war over the programming languages CoffeeScript versus JavaScript. Michael Woloszynowicz finds the rise of CoffeeScript “alarming”. He gives possible reasons people are interested in CoffeeScript and possible pitfalls in choosing to use it rather than straight JavaScript.
I believe that all that is happening is simply a repeat of history, with a small twist.
C
Once upon a time, there was a guy named Bjarne Stroustrup who found himself frustrated with the C programming language. Not only were there various flaws in C (some small, some large), but also it was frustrating writing, in a standard way, object-oriented programs. To be sure, there were very well-known idioms for writing C programs in an object-oriented way. But repeatedly using idioms, manually, can get frustrating.
C with Classes, then C++
Stroustrup created a compiler for an extension of C called “C with Classes”. The compiler was called cfront and compiled the new language to C, which was then simply compiled with any suitable C compiler. Eventually, the extension of C was called C++.
Stroustrup took care to design the language so that syntactically, almost every valid C program was also a valid C++ program.
C++ became very popular, although to this day there are many programmers who have refused to use C++, for a variety of reasons. Many of those reasons are the reasons Woloszynowicz gives for being skeptical of CoffeeScript. For example, even though C++ is “higher level”, in actuality you have to know the low-level aspects of C in order to really understand C++. Also, there are programmers who don’t use C++ very well and are better off having stuck to C longer, to have mastered the C parts of C++ before going for all the advanced features of inheritance and templates and exceptions, etc.
Example of C versus C++
To illustrate how C++ can be considered an extension of C, compare the handwritten implementation of inheritance in C with that provided by C++:
(For amusement, see how knowing the low levels of C can enable doing abusive things in C++.)
JavaScript to CoffeeScript
The debate over JavaScript versus CoffeeScript has some similarities to the debate between C and C++. CoffeeScript does some things to “fix” issues in JavaScript:
- Like C++, CoffeeScript changes some matters in variable scoping from the original language.
- Like C++, CoffeeScript introduces “classes” and expands them to a very idiomatic pattern that one could have written out by hand in the original language (in the case of CoffeeScript, classes just implement one way to use JavaScript’s prototypes).
- Like C++, CoffeeScript makes some changes with function definitions. C++ introduced a new syntax for parameters, while CoffeeScript is more radical and forces the programmer to define functions in lambda-style syntax.
The power of syntax
However, I believe that the real reason for the uproar over JavaScript versus CoffeeScript is that CoffeeScript makes huge syntax changes to the original language.
C++ made as few syntax changes as possible (until rather recently, for this year’s C++11 standard; but I believe C will borrow some syntax changes back, as it has done in the past, e.g., with ANSI function prototypes and bool). In fact, Stroustrup would have liked to change C’s type declarator syntax, but didn’t because of his mission to change C syntax as little as possible.
Ironically, semantically CoffeeScript is much more of a “preprocessor” to JavaScript than C++ is to C. I don’t really consider CoffeeScript a new language, whereas I do consider C++ to be a new language.
I think the uneasiness some feel toward CoffeeScript, as well as the excitement others feel, comes from the illusion that CoffeeScript is something new and hip and radical.
Imagine if CoffeeScript had been designed to be maximally compatible syntactically with JavaScript. I don’t think there would be as much of an uproar if CoffeeScript had the appearance of being a simple extension of JavaScript, keeping all the braces and parentheses and only introducing extra syntax that was unobtrusive. In fact, suppose the language were then called JavaScript++, with the promise that except for things like variable scope semantics, most valid JavaScript programs were also valid JavaScript++ programs.
I believe (from anecdotal praise I have heard from converts) that the excitement over syntax is responsible for much enthusiasm for CoffeeScript, and I suppose I do share Woloszynowicz’s concern that those looking for shiny new syntax might miss that anyone who is a serious CoffeeScript programmer must master the underlying JavaScript and cannot consider CoffeeScript a standalone distinct higher-level language.
Conclusion
I don’t see any special reason to be alarmed by the rise of CoffeeScript. Some people will enjoy and use well the features of it, and others will botch it up. But there is no threat to JavaScript. If anything, because CoffeeScript has such an obvious translation into JavaScript, CoffeeScript can only solidify the JavaScript world by bringing in extra enthusiasm from those who use it effectively.
(Update of 2013-02-12)
Martin Fowler wrote about JavaScript and CoffeeScript in the context of what he calls the phenomenon of transparent compilation. He says that personally, he prefers to write CoffeeScript.
Actually there already is a JavaScript++ http://jspp.javascript.am/ and no one made an uproar about it or any other compiler. I think most of the discussion is due to a lot of movement in the Rails community and that it has nothing to do with JS and its flaws. On the other hand, for the same reason that developers like CoffeeScript is that a lot of developers that like JavaScript are waiting for Ecma to come to agreements on some parts of the language so projects like Traceur become usable. http://code.google.com/p/tr...
I really don't like preprocessors (either for JavaScript or CSS) that remove curly braces. Not sure why, but it just feels wrong. I also really like curly braces, so a language that removes them is not one that I would use.
Like you said though, it's not a huge threat. It's just that I would never personally use CoffeeScript since the flaws in JavaScript don't feel so huge to me.
That's exactly my point: I suspect that a lot of people who either love or hate CoffeeScript do so purely because of syntax, and not anything else. In particular, we know that Ruby and Python people who hate braces flock to CoffeeScript.
Me, I don't really care much about syntax. Apart from Lisp, there is no language I have used in which syntax was a major issue for me. I happen not to like braces but have programmed for years in languages using them without once complaining.
Ruby and Python developers will definitely feel right at home with CoffeeScript, partially due to the lack of braces.
My only problem with CoffeeScript is that if you're working with someone on a team, everyone must agree on using pure JavaScript or CoffeeScript. That's probably the biggest reason that CoffeeScript might be a "threat" to JavaScript and JavaScript devs.
It's true that team environments require consistency. Even when using just one language, there are issues of coding style and also what IDE and version control system and bug tracking system to use. Software development goes far beyond the question of language. In the case of CoffeeScript, I don't perceive a problem, because I think anyone who can use CoffeeScript or JavaScript properly can use either, and compromise as needed depending on team consensus.
i don't feel this is correct under every conceivable project setup. the 'native' environment / habitat / community of CoffeeScript is certainly NodeJS, a community that embraces CommonJS and has brought forth npm. in the project i'm working in we needed to have a certain server-side component, and our web server is written in pure JavaScript, based on Express on NodeJS. so i sat down and programmed that missing component in CoffeeScript, then published it on npm, meaning my colleague who's taking care of the server-side stuff could just npm install that stuff and add some code to the server i sent along. very simple. to him and the project at large it's transparent and largely irrelevant that i coded a component in CS. hell if anyone cares they can even debug the transpiled JS.
IMO the real issue is when you write c or c++ you debug THAt language whereas cs is not native
Perhaps I'd agree with your comparison when I can debug that same cs in, ie Firebug
Recall that in the early years of C++, it was strictly a preprocessor to C, so that when you debugged C++, you debugged the generated C. Remember mangled names in C++ and having to run a separate demangling tool back in the 1980s and even into the early 1990s?
So be patient: CoffeeScript is very new, and therefore tool support is not all there yet. I have every belief that CoffeeScript will eventually be supported well by vendors.
I stand by my belief that the debates over CoffeeScript are similar to those over C++ in its early years.
c > c++
its turtles all the way down; programs writing programs. syntactic sugar and transpiling is about doing more while writing less; productivity. if there were no trade-off between productivity and control, we'd all be writing assembly.
some authors enjoy writing, some are warriors acting in an information battlefield, some just need to get paid--respect for privacy be damned. to each his own.
as always, the best language is the one you're currently sustaining production with. if you don't like it, don't buy it. but as for me, more coffeescript, please!
you may also enjoy: https://github.com/curimit/...
Agreed. Whatever works. When doing JavaScript, I myself prefer using the CoffeeScript variant.