Why use CoffeeScript?
I can't speak for you, but where I can, I like to use CoffeeScript because:
- it makes my life easier by helping me avoid basic errors like using ==
- it looks and feels more like Ruby which means I don't have as far to go when switching contexts between Ruby and client side code
- I don't have to do bizarre things like create self calling functions or functions that sit in between public and 'private' methods just to obtain some degree of encapsulation**
- jasmine specs look lovely vs eeew!
I used to think that CoffeeScript was somewhat pointless as you might as well learn Javascript, and learn it properly. Then I tried it and I didn't miss the power.
** edit: I rather suppose I do actually, as the compiled Javascript is full of such nonsense. I just don't have to see it quite so much. Somethings are best swept under the carpet...
Written by Dominic Barker
Related protips
10 Responses
When switching from CoffeeScript back to Ruby I always forget to put commas in my multi line hashes.
@jisaacks It was forgetting to put semicolons at the end of lines when going from Ruby to JS that did it for me...always going to get told off by Mr Crockford sooner or later :)
Why i need learn a "new" language to write same things? I disagree of most of meta-languages.
Like I said, I thought something similar, it just so happens that I enjoyed writing in the new language more than the other one. You dont need to of course - but give it a go, you might like it. I did.
Learning a new language like coffeescript has several benefits. It's similar in analogy (but at a much smaller scale) as moving from C to Python. Your code becomes instantly more readable and less error prone. You get more powerful constructs like list comprehensions and other things that are just outside of the realm of the other language without some 3rd party library. Furthermore, in 6 months when you are trying to fix a bug a client found or are trying to get someone else adapted to the code base, the forced formatting and overall legibility makes for a much easier transition. I was skeptical at first, but I've embraced it.
For me, the main reason is developing with CS is much faster than JS.
Totally agree with @jeanmask. Coffee script is for stubborn ruby developers. Shouldn't need to learn a new language that isn't required. (Unless forced to like in Rails > 3.2)
@keaplogik You don't need to, you just might prefer it like I did. Always worth giving things a go; you never know what you might be missing out on.
Sorry might have bee trolling a bit :)
No need to apologise, it's always fun to talk. :)