Selected CoffeeScript Features
Splats and Default Arguments
require'tap'=sum += value for value in valuessumtest 'add'tequal add1236'should be 6'tend=whattest 'say'tequal say'Hello''should be Hello'tequal say'Ciao''Ciao''should be Ciao'tend
require 'tap'name = 'Coltrane'test 'string'tequal "John "'John Coltrane''should be John Coltrane'tequal "1 + 2 = "'1 + 2 = 3''should be 1 + 2 = 3'tend
require'tap'name: 'Moe'test 'assignment'tequal name'Moe''should be Moe'tend
require'tap'=name: namemoe = getItem 'Moe'larry = getItem 'Larry'curly = getItem 'Curly'items = moelarrycurlytest 'iterate'i = 0i++ for item in itemstequal i3'should be 3'tendtest 'map'names = itemname for item in itemstequal typeof name'string''should be string' for name in namestequal nameslength3'should be 3'tendtest 'filter'item = item for item in items when itemname is 'Curly'0tsame itemcurly'should be curly'tend
Classes and Inheritance
require 'tap'::'Woof!':super + ' Woof!'test 'dogs'cheech = 'Cheech'tequal cheechname'Cheech''should be Cheech'tequal cheechgreet'Woof!''should be Woof!'chong = 'Chong'tequal chongname'Chong''should be Chong'tequal chonggreet'Woof! Woof!''should be Woof! Woof!'tend
But details aside, the three most significant features of CoffeeScript are: meaningful whitespace, implicit function returns, and less code. Meaningful whitespace prevents boring discussions about code formatting (semicolons anyone?), implicit function returns cultivate functional programming style, and less code is less code.
Looking at CoffeeScript was the first time I got a little bit of language envy.
CoffeeScript is well done and more convenient to use than JS, provided you buy into the Python-esque significant space and the costs of generating JS from another source language. But semantically it’s still JS.
Isaac Schlueter is right:
CoffeeScript does not offer an order of magnitude difference in expressiveness. I’m not using “expressiveness” as some fuzzy term to mean “how happy you are expressing yourself in X language”, but the more mathy technical meaning of “how many relevant program tokens are required to do X task.” CoffeeScript may require fewer tokens, sure, but not 10 to 1 fewer.
Transpilers are inherently divisive. People who are fluent in the target language will hate the new language; people new to the target language will love the new language, especially if it’s related to a language they already know.
Most transpilers are valuable. Not only can they inspire further progress, but they also draw new people to their respective target language. CoffeeScript pulls Ruby programmers on board of the Black Pearl.
Evidently too close for Max Krohn, he forked CoffeeScript to write IcedCoffeeScript, which adds synchronous control flow mimicry by introducing two new keywords:
Coco is another more radical CoffeeScript dialect.
I’m not motivated to learn Esperanto even though it might be preferable to English and German and French and Russian (if everybody switched).
You see that my objections are merely based on practical concerns; I enjoy the elegance of CoffeeScript, and find it delightful that Michael Ficarra secured funding to make a better compiler. Programming languages need independent influence from outside committees and corporations. We should be open to all language developments by independent parties.