<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 "> Bitovi Blog - UX and UI design, JavaScript and Frontend development
Loading

Significant Whitespace

Significant Whitespace

Justin Meyer

Justin Meyer

Twitter Reddit

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

a.map {|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?

Previous Post