Fat vs thin
This one has definitely bitten everyone who has used CoffeeScript one time or another. Keeping track of what
this is pointing to and when you need to use the fat arrow => instead of the thin arrow -> is sometimes a tricky business. You’re tempted to use the fat arrow always for simplicity, but then you’re paying a price in performance.
CoffeeScript automatically returns the result of the last statement within a function, just like Ruby. Personally I like this feature, but it has caused some surprises. We use promises extensively, and when a function in a promise chain returns a promise, that promise is automatically added as part of the promise chain.
We’ve had a few cases where a function that shouldn’t have any meaningful return value accidentally returns a promise. This in turn is inadvertently injected into a promise chain where it shouldn’t be. This took a while to figure out, and is something to watch out for. If a function does not have any meaningful return value, you may want/need to add a
null on the last line to prevent accidental returns.
We’ve even considered mandating usage of parenthesis in all code, but I don’t really like such mandates either.
After using other languages, it came as a slight surprise that CoffeeScript is still a language in development. We had a mysterious issue where the same code built successfully on some machines, but not on others. We discovered that catching errors without naming the error was introduced in 1.6.3, while one of our developers still had 1.6.2.
Web development is transforming as we speak. There are a lot of altJS languages cropping up, all with their strengths and weaknesses.
I doubt we’ll be using CoffeeScript in ten years’ time, but at the moment it’s a very viable alternative. You just need to be aware of the pitfalls. Even with its shortcomings, I still consider it the correct choice for our application.