Tuesday, 3 July 2012

CoffeeScript and the Curious Case of the Missing Bracket

Over the last month or two, I've grown to admire . This little language encourages developers to drop braces, sprinkling liberally around enabling . But there is one area where I think a little more would help a lot.

I sometimes find it useful to think of as just a functional language dressed up in someone else's Object Oriented clothes. Passing a function (rather than its value) is as simple as dropping its braces. So, for example alpha = bar.foo assigns the function foo on bar to alpha. Use alpha = bar.foo() to assign the value instead.

Objects and classes in CoffeeScript feel more natural, yet bar.foo still refers to the function foo. Intuitively, this feels wrong, and the only reason I can fathom for introducing this inconsistency is compatibility with JavaScript behaviour. This price seems too high for such little gain.

I suggest that, in CoffeeScript, bar.foo should call foo on bar with no parameters (just like bar.foo message passes message to foo on bar), and special syntax be introduced for function passing: bar.foo! perhaps...

No comments:

Post a Comment