Sunday, March 30, 2014

CoffeeScript vs TypeScript

Why do I prefer CoffeeScript over TypeScript?

There are some obvious syntax differences -

  • CS uses white space to define bocks,  TS uses curly braces 
  • CS uses the -> operator to define functions
  • CS uses @ to represent the current context, TS uses the 'this.' keyword

In addition, there are some higher level differences -

  • TS has a concept of modules, CS is not opinionated on this.
  • TS allows you to define a type when you declare vars.
  • TS resolves the super class at compile type, CS accepts a run-time reference.

The syntax differences are more a matter of preference. To me, CoffeeScript is cleaner looking, and requires less keyboard action to write. It also makes async and callbacks easier to follow, especially with the alternate bound function definition operator => for events.

Higher level differences make more of a difference when deigning your app. TypeScript restricts you to their own concept of modules. CoffeeScript is flexible on this matter, and I can use several different module libraries, from native node require on the server to RequireJS or Browserify on the client. 

All in all, I find CoffeeScript easier to code, and less restrictive, where TypeScript fights the dynamic nature of javascript, 

1 comment: