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.
Pingback: CoffeeScript vs. TypeScript vs. Dart | Code for Hire
Would you use CoffeeScript today, if you were starting an app from scratch?
For other types of projects I might consider other alternatives. See the end summary of the CoffeeScript vs TypeScript vs Dart article for some ideas.
Do you think TypeScript has a brighter future than CoffeeScript? What about Dart? How do you think the future with be for the three languages you’ve reviewed in the past article?
Dart is a revolution. I’d really want it to succeed – from what I read (which was admittedly very little), it seemed like a very well-thought-out language. But it has a much higher barrier to get it rolling.
I don’t see CoffeeScript’s fate as poor either. It’s filling a need. Maybe that need will disappear in the future, and people migrate to other languages. Or maybe CoffeeScript will also evolve into something new.
Both TypeScript and Dart are verbose languages with a rigid syntax, made to be easily accessible. CoffeeScript is very terse. There’s a trend on trying to find more succinct languages, especially among expert coders.
Consider Java and Scala: For a team of ten excellent coders, Scala may be more efficient. But if you have a thousand mediocre coders, I’d place my bets on Java. I think the development of this trend – one way or the other – will have a markable effect on what languages will be used in the future.
“Just recently we discovered that a model that we thought contained a number actually contained a string”
TypeScript probably would have helped here
Pingback: 1p – CoffeeScript woes (2013) – blog.offeryour.com
Pingback: 1p – CoffeeScript woes (2013) – Exploding Ads