Rails 3.1 Adopts CoffeeScript, jQuery, Sass and.. Controversy

By Peter Cooper

Guess what? Yep, the forthcoming Rails 3.1 is going to be bringing in a few new friends as dependencies: CoffeeScript, jQuery, and Sass. What does this mean? Why has this been controversial? I'm going to quickly run through the details here.

jQuery - A Non-Controversial Switch

It was back in March (2011) when David Heinemeier Hansson, creator of Rails, dropped an interesting nugget of info on Twitter:

A lot of Rails applications lean on JavaScript to provide client-side and AJAX functionality. Till now, the Prototype library had been included in Rails by default as a way to make various things easier to achieve across different browsers, but jQuery has become significantly more popular over the last few years.

Given this, DHH's announcement passed with little controversy since Rails developers had become used to using jQuery and installing the jquery-rails gem anyway. A good move and a progression with the times - awesome.

CoffeeScript - JavaScript, Improved

Today's news:

CoffeeScript started life as a Ruby project that converted a cleaner, JavaScript-esque language into JavaScript (we covered it in January 2010). CoffeeScript's syntax enables you to write JavaScript in a cleaner and, often, more logical way.

The project eventually became self hosting (so no Ruby was required) and has gone from strength to strength. While regular JavaScript doesn't have to worry about losing many developers any time soon, CoffeeScript has become a popular way to write JavaScript code in a tighter, easier to follow form amongst more progressive developers.

Trivia: The creator of CoffeeScript, Jeremy Ashkenas, was inspired by Marc Andre Cournoyer's Create Your Own Programming Language e-book. Yes, I make a small commission on this. If I get enough to build a mansion, I'll have your name etched into the cornerstone.

Sass - CSS, Improved

Sass is to CSS as CoffeeScript is to JavaScript, though to a less extreme level. In its modern form, Sass looks just like CSS but adds support for things like variables, functions, nesting, and similar useful features. Crucially, Sass is just a superset of CSS so you can still use regular CSS with Sass and it'll Just Work™. You can then learn new features one by one and start using them as you like (I must admit, I'm a massive fan of Sass and I mostly stick to the variables and nesting features).

Controversy - Bullpoop, Same Old

In true Ruby and Rails style, there's been a little controversy over today's CoffeeScript and Sass news. While the jQuery migration was pretty much accepted due to Prototype's position six feet under, plenty of developers are familiar with JavaScript and either feel slighted by CoffeeScript's inclusion as a default or are concerned that it'll act as a barrier for newcomers to Rails in future.

Given that you can "opt out" of having CoffeeScript and Sass included in your Rails projects by making a minor change to your Gemfile, this faux-controversy is nowhere near as interesting to me as the legitimate RSpec vs Test::Unit debate that DHH kicked off.

However, if you want to grab some popcorn and enjoy the bullshit, the comments on this GitHub commit page are epic. People have even gone so far to produce graphics to express their opinions. Rock and roll. There's also a significant level of pie-slinging going on on Twitter too.

But what about HAML!?

It had to be asked right?

Phew!

Last but not least:

I'm glad David's stepping into these sorts of discussions again. He seemed to fade away during the year before Rails 3 came out, leaving a lot of the "thought leadership" to Yehuda Katz. Now he's back on top form and talking sense - long may it last.

UPDATE: Wanna play with Rails 3.1 and CoffeeScript right away?

Oh, and do you actually want to play with Rails 3.1 RIGHT NOW? You can - just click that link. I already wrote a tutorial post about it.