<linkrel="alternate"lang="fr"xml:lang="fr"title="Pourquoi je n'utiliserai pas CoffeeScript (malheureusement)"type="text/html"hreflang="fr"href="/Scratch/fr/blog/2011-01-03-Why-I-sadly-won-t-use-coffeescript/"/>
<linkrel="alternate"lang="en"xml:lang="en"title="Why I won't use CoffeeScript (sadly)"type="text/html"hreflang="en"href="/Scratch/en/blog/2011-01-03-Why-I-sadly-won-t-use-coffeescript/"/>
<p><spanclass="sc"><abbrtitle="Too long; don't read">tl;dr</abbr>: </span> I tried <ahref="http://coffeescript.org">CoffeeScript</a>. In the end there was more inconvenients than advantages to its use.</p>
</div>
<p>Recently I read <ahref="http://news.ycombinator.com/item?id=2053956">this entry</a> on HackerNews.
The most upvoted comment praised (within other things) <ahref="http://coffeescript.org">CoffeeScript</a>.
Recently I used <em>a lot</em> of javascript. After trying
<ahref="http://sproutcore.com">Sproutcore</a>,
<ahref="http://cappuccino.org">Cappuccino</a>, looking at
I’ve finally decided to make my own minimal javascript MVC framework.<supid="fnref:1"><ahref="#fn:1"rel="footnote">1</a></sup></p>
<p>I had to fight the horrible syntax of javascript. It was like experiencing a back-in-time travel: </p>
<ul>
<li>Verbose Java-like syntax, </li>
<li>Strange and insanely Verbose Object Oriented Programming,</li>
<li>No easy way to refer to current instance of a class (<code>this</code> doesn’t work really well),</li>
<li>etc…</li>
</ul>
<p>I was so annoyed by this that at a point, I had thinked about creating my own CoffeeScript.</p>
<p>I’ve finished a first draft of my MVC javascript framework and learn about the existence of CoffeeScript. Praise git I immediately create a new branch with only goal to try CoffeeScript.</p>
<p>Here is my experience:</p>
<ol>
<li>I had to install <code>node.js</code> and use <code>npm</code> just to use CoffeeScript. It wasn’t a big deal but it wasn’t as straightfoward as I expected either.</li>
<li>Existing javascript file are not coffee compatible. You <em>must</em> first translate them.</li>
<li>There is no script to help you translate old javascript file to coffee file. Bad news, I had to translate it by hand.
Thanks to <ahref="http://vim.org">vim</a>, it wasn’t too hard to translate 90% of the javascript using some regexp.
The <code>--watch</code> option of coffee was also really helpful to help in the translation.
But I had to write my own shell script in order to follow an entire directory to also accepts the subdirectories.</li>
<li>An unexpected event. I made some meta-programming in javascript using <code>eval</code>. But in order to work, the string in the eval must be written in pure javascript not in coffee. It was like writing in two different languages. Really not so good.</li>
</ol>
<h2id="conclusion">Conclusion</h2>
<p>Advantages:</p>
<ul>
<li>Readability: clearly it resolved most of javascript syntax problems</li>
<li>Verbosity: I gained 14% line, 22% words, 14% characters</li>
</ul>
<p>Inconvenients:</p>
<ul>
<li>Added another compilation step to see how my code behave on the website.</li>
<li>Ease of use: I have to launch some script to generate on change every of my javascript file</li>
<li>I have to learn another Ruby-like language,</li>
<li>meta-programming become a poor experience,</li>
<li>I must convince people working with me to:
<ul>
<li>install <code>node.js</code>, <code>npm</code> and CoffeeScript,</li>
<li>remember to launch a script at each code session,</li>
<li>learn and use another ruby-like language</li>
</ul>
</li>
</ul>
<p>The last one is definitively the biggest problem for me.</p>
<p>But even if I’ll have to work alone, I certainly won’t use CoffeeScript either. CoffeeScript is a third party and any of their update can break my code. I experienced this kind of situation many times, and it is very annoying. Far more than coding with a bad syntax.</p>
<h2id="digression">Digression</h2>
<p>I am sad.
I wanted so much to program Javascript like Ruby.
But in the end I think it is not for me.
I have to use the <em>horrible</em> javascript syntax for now.
At least I would have preferred a complete <code>ruby2js</code> script for example<supid="fnref:2"><ahref="#fn:2"rel="footnote">2</a></sup>.
But I believe it would be a really hard task just to simulate the access of current class for example.</p>
<p>Typically <code>@x</code> translate into <code>this.x</code>. But the following code will not do what I should expect. Call the foo function of the current class.</p>
<p>Knowing this, <code>@</code> notation lose most of its interrest for me.</p>
<hr/><divclass="footnotes">
<ol>
<liid="fn:1">
<p>I know it may not be the best nor productive decision, but I’d like to start from scratch and understand how things works under the hood.<ahref="#fnref:1"rev="footnote">↩</a></p>
</li>
<liid="fn:2">
<p>I know there is <code>rb2js</code>, but it doesn’t handle the problem I talk about.<ahref="#fnref:2"rev="footnote">↩</a></p>