Workshops and Conferences

A Sip of Coffee Script


CoffeeScript is essentially just a syntactic rewrite of JavaScript. The core language itself stays the same, with small semantic enhancements. The syntax is modified, modeled after Python and Ruby.

CoffeeScript compiles down to raw JS and hence outputs clean JavaScript that not only follows best practices but also eminently readable.This means that you don’t have to worry about compatibility down the line.

Under the web development umbrella, there is already a fair share of this ideology. HAML is a new way of writing HTML while SASS does the same for CSS. All of them clean up the structure and syntax of their languages making them more easier to work with and thus boosting our productivity.

Pros and Cons

Yays

  • Python style whitespacing
  • Ruby styled lightweight syntax
  • Concise function declarations
  • JSLint approved
  • Class based inheritance

There are, of course, numerous other points including semantic and syntactic enhancements.

Nays

  • Slight learning curve involved
  • Deployment, depending on your route, may be a chore
  • You’ll need a basic knowledge of JS for debugging purposes. You can’t directly start here, naturally.

When somebody hears about CoffeeScript the first question that comes to mind is “/should I learn CoffeeScript” and the developer of CoffeeScript answers that question in this way

Jeremy Ashkenas

Yes. CoffeeScript is not an entirely new and strange language. It exists to allow “reasonably solid” JavaScript developers to write the same code they were going to write in the first place, in a more readable and fluent way. The basic idea is to write what you mean, instead of writing within the limits of historical accident. For example, if I want to loop over every item in a list, in CoffeeScript, I can write what I mean:

1
2
for item in list
  process item

Whereas in JavaScript, I partially obscure my intention, by writing:

1
2
3
4
for (var i = 0, l = list.length; i < l; i++) {
  var item = list[i];
  process(item);
}
Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s