Taking a quick look at CoffeeScript
I have been sort of skeptical of CoffeeScript based on my limited knowledge of it for a few simple reasons: I don’t particularly care for the indented block style; the “human readable” style, while easy to read, is not as easy to scan; and I don’t feel like I need a layer of abstraction on top of JavaScript.
But there are enough CoffeeScript headlines popping up on HackerNews that it’s clear I needed to read a little bit about it, so that’s what I did today. So first with the bad:
- Debugging: Tracing errors back from the compiled JavaScript to your CoffeeScript is going to be a pain in the ass until there are add-ons or direct support from the browsers to handle debugging.
- Var as a reserved word: This seems like a minor issue weighed against the benefits of CoffeeScript handling your var declarations for you, but you can’t shadow outer variables. It would be nice to be able to explicitly gain control of the var keyword.
- [edit: forgot to add this] Comparison conversion: CoffeeScript automatically makes == become === so coercion comparison just isn’t an option as far as I can tell.
So other than the fact that I prefer all those brackets, braces and semicolons, that’s really the worst of it. And here are some of the things that make me want to give CoffeeScript a try:
- Default arg values: This simple addition will help clean up my code quite a bit.
- Using reserved words as properties: JS has too many reserved words, and it would be really nice to be able to use them without having to worry about quoting them.
- Until and Unless loops: I think these will make code easier to scan and have often found myself wishing I had this option in JS.
- Chained comparisons: This reads much better and is much more intuitive to write.
- Classes: Classical inheritance is just messy in JS. CoffeeScript cleans it up nicely.
There’s enough there that I’m going to give it a try to see how I like it. I have a small project I recently started and I’m curious to see how much smaller it will get in CoffeeScript. There’s also the claim of “tends to run as fast or faster than the equivalent handwritten JavaScript,” so I’ll have to check performance before and after as well.