Significant Whitespace

by Justin Meyer

Significant Whitespace

Justin Meyer If you haven't read it already, please read Ryan Florence's "A Case Against Using CoffeeScript." It's well thought out and makes a lot of interesting points. But for me, the most important one was Significant White-space Means CoffeeScript Will Always Be Compiled.

posted in Development on December 14, 2011 by Justin Meyer

If you haven’t read it already, please read Ryan Florence’s A Case Against Using CoffeeScript. It’s well thought out and makes a lot of interesting points. But for me, the most important one was: Significant White-space Means CoffeeScript Will Always Be Compiled.

He goes on to say:

It makes no sense for a web scripting language to have significant white-space; you can’t compress it. Therefore it will never really be supported natively, and will always be a compile-to-JS language, and will therefore always have a terrible debugging experience.

I like CoffeeScript, probably because I like Ruby, and it’s supported by JavaScriptMVC’s dependency management system – Steal. It’s also done a great job of influencing JavaScript as a playground to explore ideas. I’ve heard (either directly at conferences, or word of mouth) that both Brendan Eich and Douglas Crockford think that CoffeeScript is good stuff.

But with that being said …

I wonder if CoffeeScript would be more useful (it’s already extremely useful) to the JS community had it not decided to make whitespace significant. It could give us the syntactic sugar we crave such as:

destructuring and spread

[a,b] = [b,a]

block or arrow functions {|e| e * e} 

default values

function add( x= 0, y = 0) { }

rest parameters

function( foo, ...args ){ }

simple classes

class Monster { }

… but provide a path for browser support.

Could it work?

On the surface, it seems trivial to accomplish with a script loader like RequireJS or Steal. Simply load the Harmony style code, process it, and eval it. CoffeeScript could even be a starting point. Browsers that support it can skip processing entirely. The tricky part might be compiling to a specific version of JS to minimize the amount of re-writing.

The benefit is that much of your code will have a solid debugging experience. And, it might encourage people to build apps with parts of Harmony well before they are done.

It seems like such a big bag of win that I’m almost surprised someone for ECMA hasn’t whipped this up for RequireJS as a plugin. Anyone got a Harmony -> JS compiler in the works?

blog comments powered by Disqus

Get Started with StealJS and ES6 in 5 Minutes

Julia Poladskyposted in Development, StealJS on August 4, 2015 by Julia PoladskySomedays it feels like JavaScript is always changing, and it is hard to keep up. It is even harder when you’ve spent countless hours, blood, sweat and tears to get your build tools working. Watch the simplest way to get started using ES6 with StealJS.

Contact Us
(312) 620-0386 |
 or cancel