Why would I use Coffee Script?

I’ve been doing a set of tutorials learning the Play Framework, and they are using CoffeeScript for all their Javascript interaction. And for the life of me, I can’t figure out why I would ever choose to use this. I didn’t take the time to learn it, but just typing it out based on their tutorials, this makes almost no logical sense. Not to mention, improper spaces matter and bug out!

I’ve kinda searched around and I can’t really find a good clear answer as to why anyone would switch from straight JS/jQuery to using Javascript, other than “it’s cool” and it saves a tiny amount of keystrokes, at the price of learning an entirely new way of thinking about a problem you need to solve.

There are a number of other languages that have similar syntax to coffescript. For people familiar with any of those languages coffeescript would be far easier to learn than JavaScript.

I can understand that, but which languages is it similar to? I haven’t encountered anything like it yet.

But, I honestly think there has to be other reasons for using it that I’m not seeing.

Has anyone else used Coffee Script that could shed some light on it?

If I came off as being completely closed minded about it, I am not. Rather, I just don’t see why it needs to exists and I know there is a reason why it exists and a reason why people would use it.

Hi mawburn,

I haven’t used CoffeeScript myself, but I remember the first time I took a look to see what all the fuss was about I came to much the same conclusion as you!

Looking at the website again now it seems to take some inspiration from Python… indentation instead of curly braces, and comprehensions for example. If you look down the main page and compare the CS with it’s JS equivalent, using CS would save you from a lot of ‘boilerplate’ code.

On the downside though, you’ll end up having to deal with the vanilla JS anyway when debugging, so you just end up learning two languages instead of one.

I believe that coffeeScript was developed by Ruby programmers so that they could createe JavaScript using Ruby syntax.

JavaScript is even implementing some coffeeScript syntax (well almost).

Current JavaScript:

var square = function(x) {
return x * x;
};

CoffeeScript:

square = (x) -> x * x

ES6 JavaScript

var square = (x) => x * x;

I don’t use CoffeeScript either, but I believe it’s as felgall says, that it was created by Ruby programmers so that they could createe JavaScript using Ruby syntax.

There was quite an interesting interview with the inventor of CoffeeScript on the JavaScript Jabber podcast a while back: http://javascriptjabber.com/017-jsj-coffeescript-with-jeremy-ashkenas/

Yeah, since I made this post I’m getting more into the Scala side of things and I can see why they chose to include it in this framework. I’m still using Java for most of it, but I’m doing Scala classes for some of the minor small things and it’s… weird. It’s kind of a different way of thinking and it’s starting to grow on me. I guess this is my first introduction to actual functional programming and it’s quite a bit different than I thought it was. I can definitely see the similarities between Scala and CoffeeScript.

I’m not one for writing something differently for the sake of writing something differently, so I still don’t’ see the need for it. lol

I’ll definitely check that video out later. Thanks.