Analysis / News / Technology / Top Stories /

An Updated CoffeeScript Brews a Batch of Smoother JavaScript

28 Sep 2017 9:00am, by

Northern Californian Geoffrey Booth was an unlikely bloke to take on the ongoing task of making JavaScript easier to work with. But as the new maintainer for the recently revamped CoffeeScript, he holds the key to taming the web’s favored front-end programming language.

Booth came to programming from a different direction than most developers. As a film school graduate, he found himself building web applications for movies instead of editing scenes. By 2013, he was working on major movie sites, like that of “Jurassic World.”

That “Jurassic World” site, said Booth, was built with CoffeeScript, a popular JavaScript-based language that takes the Perl-ish-like syntactic obfuscation out of the language entirely. This is accomplished by removing brackets, elongating commands to plain English, and generally making it easier to define functions.

The end effect is a language that compiles 1-to-1 to JavaScript, and has fewer complex symbols and syntax to learn. Booth said that he, “Liked it a lot. I liked the syntax. It was cleaner and easier to follow. I started using that. I was coding by myself, and I didn’t have to worry about what anyone else thought.”

Over the years, however, CoffeeScript started to show its age. Many of the things it was doing to make the language simpler were being addressed in the actual ECMAScript specifications, and when new versions of JavaScript arrived, CoffeeScript was left wanting.

Until that is, Booth rolled up his sleeves and decided to make the jump from film company programmer to open source contributor. “I think the big tipping point for me was that there was something in ECMAScript 6 called a ‘modules import and export’ statement, which was a new syntax for requiring other files or modules of other chunks of code in a way that split your application into multiple files,” said Booth.

“That had been possible with Node.js for years, but that was never part of the JavaScript language itself. It was an API that Node.js exposed. This was part of the future of JavaScript, itself. It’s a very weird syntax, and it doesn’t look anything like the rest of JavaScript. The Node version looks like a function call. This doesn’t. This doesn’t have parenthesis, which is very unusual looking in JavaScript syntax,” said Booth.

Booth said you couldn’t create “import or export” syntax in CoffeeScript. As he’d come to the language originally through the Meteor JavaScript framework, he saw a solution there. Using import statements in Meteor meant the developer had to use back-ticks in CoffeeScript. A special back-tick operator operates as an escape hatch, where whatever you put between back-ticks just gets output as JavaScript when the CoffeeScript compiles to JavaScript.

“People starred putting in the import statement back-tick, and that worked fine, but it struck me as not being a good sign,” Booth said. “There are going to be more things like this in the future that ECMAScript is going to come up with that CoffeeScript isn’t gonna support, sooner or later this won’t be a solution.”

Thus, Booth started the arduous task of kickstarting the CoffeeScript open source development effort, which has stalled by this time. This was no small task as Jeremy Ashkenas, the language’s creator, was off riding a motorcycle through South America for a year. To make matters worse, Booth had never attempted such complex development work before.

Simon Lydell was the default maintainer at the time. “Simon had limitless patience for guiding me through this pull request, which must have taken months. I figured out how to get import export working properly. That led to version 1.11,” said Booth.

With small steps begin great journeys. That work was completed in September of 2016, and last week, the work on version 2.0, which really began to surface in February, came to a conclusion.

The 2.0 line offers a few breaking changes, but this yields many advantages. For example, CoffeeScript 2.0 can support and run natively in Node 7.6 and beyond. Previous versions required transpilation to work. Additionally, CoffeeScript 2.0 now compiles classes to the class keyword, meaning it’s possible to extend a JavaScript class.

Booth said he does not expect people to simply move to CoffeeScript. He is a tad gunshy of all the hate the language can get from JavaScript purists. But he likes the language because he considers it easier to read and debug. The removal of endless brackets, and the easier to read syntax makes it a more sensible way to develop JavaScript for some. And now, with the help of Booth, CoffeeScript addicts can continue to use their language of choice.

Feature image via Pixabay.


A digest of the week’s most important stories & analyses.

View / Add Comments

Please stay on topic and be respectful of others. Review our Terms of Use.