If you’re interested in CoffeeScript, then I’m sure by now you have read Ryan Florence’s blog post titled “A Case Against Using CoffeeScript”. In this post, Ryan explains that he uses CoffeeScript at work, and he likes the language, but in his opinion it is too difficult to comprehend and too difficult to debug. My response to this, in the immortal words of Dwight Schrute, “false!”
Before we get started, let me just say that this article is more about disagreeing with some of the statements made in Ryan’s post, its purpose is not to “sell” you on CoffeeScript, but merely point out that CoffeeScript is not something to be scared of. If you want somewhere to show you how awesome CoffeeScript is, I would recommend checking out the official CoffeeScript site and CoffeeScript is for Closers by Brandon Satrom.
Let me start out by saying that I think Ryan is making two completely unrelated assertions in his post:
- CoffeeScript is too difficult to debug.
- CoffeeScript is too difficult to comprehend.
I feel that the first issue definitely has some validity, but the second really holds no water for me at all.
Too Difficult To Comprehend?
To say that CoffeeScript is too difficult to comprehend seems silly to me. Every language has features in it that, when used poorly, can create horrible unreadable code. If a developer wants to leverage a language in a way that causes unreadable code, there isn’t a language in existence that will stop them. Just saying that code is “bad” or “unreadable” should be a red flag in most language arguments, since these adjectives are usually a matter of personal preference, but too often delivered as fact.
CoffeeScript’s “Bad” Parts
Yes, CoffeeScript has a few warts. But is its ability to call methods without parentheses a “bad” part? I don’t know, ask a Ruby developer then ask a Java fan (do those exist still? I kid. I kid.). I’m sure you’d get two different answers. Given the example that Ryan had:
dfd = $.ajax url: url format: 'json' method: 'get'
CoffeeScript Is Hard To Debug?
I have run into a few situations where I’ve written a chunk of code in CoffeeScript and I’ve received some very odd messages from the CoffeeScript compiler. This has actually been the biggest source of frustration writing CoffeeScript, is that there are places where ambiguities in the language can be accidentally introduced and you’ll get an error saying something along the lines of “unexpected statement start”. Then you have to hunt down the cause of this error.
What I think the problem really comes down to is tooling. If CoffeeScript was natively supported by the browser, you wouldn’t be asking for tools to view the generated ASTs, you would want a debugger. The fact that I can’t view CoffeeScript in the browser and set a breakpoint and debug at that level is annoying, but it isn’t annoying enough that I want to give up the expressiveness that CoffeeScript provides me.
Why Would I Use It?
Now that I spent all this time telling you that it doesn’t suck, I should probably tell you why you might actually want to use it! On a personal level I think that it has a cleaner syntax. I like its roots in Ruby and Python and reading CoffeeScript feels better to me. But I think the real power lies in its expressiveness.
The list goes on and on. I could write a whole blog post about it, but the CoffeeScript website lays it out for you far better than I ever could.
If It Makes Your Life Better, Use It.
When I want to use a tool, I always look at it and weigh the risks of using the tool versus the benefits. At the end of the day I think that the benefits that CoffeeScript gives me outweigh the risks, if you don’t agree, then don’t use it. But if it makes your life easier, and you’re not risking the farm by using it, then by all means have at it!