Use ES2015 or CoffeeScript?

#1

Hey there!

I’ve just stared a new project and I’m happily using CoffeeScript - I just like the minimal syntax!
However, with ES2015 around the corner, I’m not sure if I should continue using CoffeeScript. The main problem I see is, that CoffeeScript maintainers aren’t willing to include features, which aren’t available to all platforms/ browsers being used, so new features to the JS language won’t be included. Because of this, using CoffeeScript is basically like using ES3.
I’m also thinking about using React in the future and I think that it plays better with JS than CS.

So I’m not sure now if having a nicer syntax is worth not being able to use new features.
What would you do - and why?

5 Likes
IDE for Meteor with CoffeeScript
#2

I used to use coffee script and here’s why I stopped.

No consistent style: Everyone has their own coffee style and some take it too far and play code golf. It makes it compact and hard to read. My personal style was to mimic python by including braces and brackets.

Less open source contributions: Even though it’s similar it’s a hassle for most to work in CoffeeScript so the number of people sending PRs drops.

Context switching: Even when you work in Coffee there’s a switching cost to bear when going back and forth. This is especially bad when a project has both js and coffee.

ES6 is easy to use now: before it was non trivial to experiment with ES6 transpililing. now it’s almost automatic.

Project Development is stagnant: it’s the same as it was 5 years ago… not ideal. ES6 has more features at this point.

It’s not less typing: at first I thought that it was less typing… but with tab triggers I still type class tab to create a class in both languages.

10 Likes
#3

Here’s a biased, uninformed opinionated reply.
I looked at switching to coffeescript for a day last week and eventually found ES6 had alot of the nice syntactical sugaring I was craving for. Different, but just as good and will be alot better supported in the community.
So now I’m waiting for ES6 in 1.2 but I don’t think this is a big choice to make. Personally, I’ve written html/jade, typescript/coffeescript (a day)/javascript, c#/java(shudders) (sorry, java doesn’t compile into c# but very similar). I think it takes a little time to get used to syntax or to read different syntax, however, it’s easy to switch later on if you really want to and shouldn’t stop you from using it if it’s the right choice right now.

2 Likes
#4

I have been using CoffeeScript for several years now and don’t plan to stop. For me, the big advantage of CoffeeScript is that I find it helps developers write less-buggy code. To list just two examples:

  • if someVar? in CoffeeScript is so much better than JavaScript’s if (someVar) which should really be written as if (someVar != null) or even if (typeof someVar !== "undefined" && someVar !== null) if you want to be completely proper. I don’t want all the developers on my team to need to be JS ninjas who remember the latter (or need to remember to use a helper function we write for this purpose).
  • CoffeeScript’s significant whitespace makes code easier to read. Strip all those braces and many of those parentheses away, use proper indentation all the time, and your code reveals itself. Easier-to-read code = less-buggy code. It also eliminates bugs caused by a developer writing an if statement without braces, perhaps because at first it was intended to be a one-liner but later it became a block and the developer forgot to add the braces.

You see where I’m going with this. I can imagine a lot of people reading this might scoff at such concerns, that they’re experts and don’t make such newbie mistakes and don’t need the language to handhold them (or anyone else on their team). Well, hooray for you. I think the reality, though, is that we all make stupid mistakes, whether it’s coding late at night or coding while thinking about the problem rather than the syntax we’re typing. CoffeeScript helps cut down on the stupid mistakes.

And there are very few ES2015 features that CoffeeScript lacks. I was chatting with a developer at a meetup recently who was telling me how he switched from CoffeeScript to ES2015 because of the destructuring; he apparently never noticed that CoffeeScript already has destructuring. Many of ES2015’s features, like the fat arrow, are adopted from CoffeeScript. About the only features I can find that CoffeeScript doesn’t support are the new import/export syntax (irrelevant for Meteor, and for other frameworks like Ember you can just wrap your import and export lines in backticks) and tail-call optimization, which I had never heard of before ES2015 came on the scene. You can read someone smarter than me discuss the specific features here. CoffeeScript’s feature set hasn’t changed much in years mainly because it doesn’t have to.

As with anything, it’s a tradeoff. I greatly prefer CoffeeScript’s syntax, and I think it helps my team avoid bugs. I’m fortunate that I have a team that agrees with me; I totally understand the mindset of someone already learning ES2015 and not wanting to learn yet another thing. And I think the risk of limiting your contributors to an open-source project is a real concern (though in that case you might just want to stick to old ES5). At the moment, both CoffeeScript and ES2015 compile down to ES5, and that will be the case for years to come until browser support for ES2015 features is more widespread; but by then, I expect CoffeeScript will compile down to ES2015.

11 Likes
#5

!!someVar or Boolean(someVar)

#6

and how about
return someObject?.someProperty1?.secondProperty?.thirdProperty is "result"

#7

Whenever i see a tutorial, code snippet, question with CoffeeScript… i usually skip. Sorry…

3 Likes
#8

Agreed. JS devs are for the most part not computer scientists, so they pick up skills or habits here and there. Those who bounce between jobs the most seem to have the widest array of both. Fundamentals and discipline create good habits, but JS folk are an odd ilk until there is formal education. However, formal education may just ruin the greatness of what we have today. So if a few misguided, short-sighted folk wish to build libraries to appease those who refuse to move from a posix syntax to an ecma style, so be it. Lessons learned all around. And we should all embrace everyone and not do this weird mac vs. pc, christian vs. muslim nonsense we see too much of today. We’re Meteor developers, and it’s beautiful!

#9

Seems like backticks dont work with meteor.

#10

Yes, I commented on that issue. However I’ve found that you don’t need backticks to get modules to work in CoffeeScript in Meteor 1.3: see post.

#11

I couldn’t say it better than you did here. Everything is true :smile:

#12

That’s because he made it come true :slight_smile: . Seriously though, he stepped in a while back, became the primary maintainer/contributer of https://github.com/jashkenas/coffeescript/, and is the driving force behind coffeescript progressing (by itself, and within Meteor core). So if you’re a coffeescript fan, you have @GeoffreyBooth to thank for its continued progress. :clap: :bowing_man:

2 Likes