by raganwald · 14y ago · 0 comments
For some language X where Y “compiles to “ X, Y is a new language if it introduces new semantics. For example, pure functional semantics, or object-orientation, or pattern matching, or method flavours, or static typing.
One easy test for this is to ask whether compiling Y to X can be done in small chunks or whether it requires “Whole program rewriting.” For example, transforming a program with continuations into CPS requires whole-program rewriting. I would call any language that adds continuations to JavaScript a new language on that basis alone.
CoffeeScript is almost entirely local transformations. I think of it as JavaScript.
• a classical object model, complete with super()
• forced strict equality
• loop-local index variables (gets around the setTimeout(function() {console.log(i)}, 100) problem)
• all variables local unless explicitly declared otherwise
• CoffeeScript's splat arrays are totally different from JavaScript's arguments object
• list comprehensions (whether this is a semantic or syntactic change is debatable, I suppose, but the same could be said for basic OO)
• everything is an expression
The last one is a biggie that completely changes the meaning of many seemingly identical blocks of code. If that isn't a semantic change, what is?
Javascript has a distinction between statements and expressions, while to my knowledge CoffeeScript does not. "Everything is an expression" is a huge difference in semantics even though nothing has been added.
Are they the same language?