Why CoffeeScript is tough to maintain

I recently started trying out CoffeeScript only to find out that it caused more headaches. The abstraction level of jQuery was perfect, it did not dictate to coders how to design their code, it just works. However, I recently posted a request to the CoffeeScript team to consider introducing curly braces to help with more complex code to control the flow of logic. For example a if-then-else with many nested levels can be near impossible to debug without tracing through it when using CoffeeScript. Also with IDEs like Visual Studio, regular JavaScript intellicense and auto-formatting make it easy to appropriate indent nested levels without any work on the part of the developer and reading it is not that hard, especially with some extensions that show vertical lines in the code editor to help see what is nested within what part of the code.

However with CoffeeScript that is not the case. The samples given in the CoffeeScript web site are of course just simple examples to explain the features and one gets excited pretty quick over the powerful shortcuts. I tried to convert a piece of JavaScript over to CoffeeScript and gave up since you need to first of all remove ALL non CoffeeScript coding constructs for it to even compile. However js2coffee can help with that. However to keep track of nested levels became something that was simply not manageable using CoffeeScript.

Furthermore, any coding language that controls the flow of logic by indentation is extremely dangerous for obvious reasons. I liked CoffeeScript a lot, but the fact that the logical flow of the code is controlled by how much you indent code, spaces or tabs, is not reliable as there is no way the programmer has an easy way of knowing what parts of the code will get hit when the code spans a page.

When I suggested introducing curly braces in CoffeeScript the team, one contributor advised me that my code needs to be re-designed! Needless to say that is absurd. When I included a piece of the code he asked my if it was legacy code. It's like saying to a Java programmer, sorry you cannot use Java because we don't agree with how you write your code.

jashkenas from the CoffeeScript blog gave some great suggestions and made the point that introducing curly braces would be very problematic for them as they use them to denote objects. Makes sense, but I would still love to see some way to replace code flow control with spaces and indentation to something more concrete and human readable.

Updated: 10/18/2012
After running into some more issues with logic errors, try and debug using Firefox's Firebug. Guess what, now that I found the code that needs to be corrected, I have to find that corresponding code in my CoffeeScript file! You guessed it, you cannot debug CoffeeScript, only the generated code and have to work backwards to find the issue in your CoffeeScript file.

Print | posted @ Friday, July 6, 2012 11:40 AM

Comments on this entry:

Gravatar # re: Why CoffeeScript is tough to maintain
by pete w at 7/9/2012 4:47 PM

Like you I am suffering buyer's remorse with coffeescript, just for different reasons.

The white space is not an issue to me. I'm surprised you adopted coffeescript and you think whitespace is "extremely dangerous" did you have that opinion before you started building anything significant?

Also, when you are changing languages, sometimes it DOES make sense to re-write large sections to take advantages of the new language. This doesnt matter much in coffeescript though, as they say: "its just javascript" so I agree with you it is pretty ridiculous to ask for a re-write and anyone with that kind of opinion isnt a good listener.

My problems with coffeescript stem from the fact that the designer chose elegance over readability. Variable declarations are hard to tell apart from assignments. If you mis-type a variable you just created a new one. Equality between strings and integers simply does not work which is a royal pain when you are comparing JSON numbers to DOM attributes, and they are equal, but not really. Closures are problematic, I cant count how many times I have been burnt by the -> vs => problem. And when something goes wrong? you are debugging generated code. If you are using visual studio for your editor all of the JS generators have memory leaks that slow down your computer as you save edits multiple times.

I am currently re-writing all my code back to javascript and feel a little foolish for buying in to this macro language in the first place.
Gravatar # re: Why CoffeeScript is tough to maintain
by Renso at 7/9/2012 5:56 PM

Wow Pete, you bring up a very valid point, I had not even considered the variable declaration issue. Great point to consider.

Memory leaks, makes sense as I have run over 1 GB in memory consumption with CoffeeScript, I was just not sure what was the issue. Especially since some of my JavaScript files are two - three thousand lines.

The reason I think white-space is so dangerous is simply because one typo, one extra space, space in stead of tab, etc, all have different meanings and when I tried to convert a large file I had real trouble "seeing" the nested levels, it does not read well for me. With curly braces it just seems to work well as you can visually know when the code block starts-ends as well as even if your code design sucks (or someone else's code that you're maintaining) with miss-aligned code blocks you always know it will work. Think about Visual Studio and Resharper, with hot-keys it auto-formats my code for me perfectly, aligned everything just right and makes code very readable, and thus maintainable. I would never trust a tool to do that for me if I know the flow of code is controlled by spaces/tabs. With curly you NEVER have to worry about it.

Worst is the js2coffee converted my script with no errors/warnings and only when I saved the coffee file in Visual Studio it tried to generate my js file for me, keep in mind I had not touched the coffee file after the js2coffee generated it for me!, and then only did it throw me errors, all about white space and indentation issues.

To answer your question second question about white-space, is that I did not write coffee from scratch, I tried to convert large js files to coffee and eventually gave up.

I agree with the rewrite, unfortunately I don't have the luxury of time and resources. With SCSS or .Less I can make the transition into those progressively, with coffee I have no choice, all-or-nothing.

"elegance over readability", unfortunately I have to agree with you. I was hoping that they would see reason in introducing some very important JavaScript components into coffee, like code-block delineation with something like curly braces as curly has another use in coffee. Also like you "var" my be more important than we thought, surely the creators of JavaScript had code terseness in mind as computer in those days had so little memory, I feel if they felt using "var" was a great idea, well then "it was a great idea". It would give a developer the option of a more progressive adoption, and even better it will give them the option of being explicit in not declaring "var", or not.

However, the community on the CoffeeScript github are not willing to see reason in this regard and every time I try and address the issue they revert back to "code-design", talk about PhP and Ruby, as if that is reason to not use curly braces. Which has more code in the world today, Ruby, Php or C#, C, C++ and JavaScript? If that is a reason to argue using curlies we have made our point then. I was following related articles by folks on CoffeeScript on github and it seems their community is mostly made up of PhP, Ruby and Python programmers, which would explain their bias.

In any regard, thanks for your feedback. It was really helpful and has been the last nail in the coffin for CoffeeScript for me and my teams.

Most of all I am disappointed at the attitudes by the contributors on the CoffeeScript github community. Sad!
Gravatar # re: Why CoffeeScript is tough to maintain
by Christian W at 7/10/2012 4:13 AM

Why in the world would you convert _from_ JS to Coffeescript? It would be like me using a VB to C#-converter and then complaining that it didn't work out of the box.

And CoffeScript is opinionated from the beginning. The more languages that gets rid of curlybraces the better. But that's because I'm on a Norwegian keyboard and square brackets and curly braces are on AltGr+7/8/9/0 :/

My point is in essence, why would you use CoffeeScript, a heavily opinionated language, if you don't agree with the structure in the first place?
Gravatar # re: Why CoffeeScript is tough to maintain
by Renso at 7/10/2012 7:52 AM

Christian, thanks for the response. As you know we all are constantly trying new technologies to see if they make our lives easier. All frameworks have their drawbacks, just like and programming language has constructs in it that we don't like or don't have at all. I liked most of what CoffeeScript offered and of course until you actually try it wont know if it is the right tool for you. If you are a PhP or Ruby programmer using CS will be an easy transition as you are used to having to deal with the challenges that come with white-space/indented code blocks to control the flow of code. If you come out an environment like Java, C# or JavaScript that will not be native and as in my case something I don't just feel comfortable with but simply do not have the confidence factor that it will execute as planned. I also never have to be concerned about white-space, especially since it is a big deal in CoffeeScript, which now I will have to not just worry about it but pay very close attention to it, a major reason for me not to consider it.

You are right, it is very "opinionated", we will just have to create our own short-hand JavaScript library and call it jShort :-)
Gravatar # re: Why CoffeeScript is tough to maintain
by feidudu at 8/2/2012 8:39 PM

looks like all the smart guys never notice a simple fact - leaving so many half baked 'framework' or 'shortcuts' around when 'trying to make life easier', the fact itself will make majority's life much harder.

I do hope our car brake has 10+ ways to operate, and you have to use different mode because you happen to be forced to drive on different roads.

open source never wins over windows for this simple reason -- they makes things too many ways, thus makes people's life much harder than needed. M$, however evil, has forced a single (may not simple) standard thus makes people's life easy, and thus beat opensource to toilet.
Gravatar # re: Why CoffeeScript is tough to maintain
by anon at 8/16/2012 6:52 PM

Thanks for confirming that only idiots willingly program in Java and C#. How can you possibly be so freaked out by meaningful whitespace? Do you randomly indent code? Meaningful whitespace is a big part of why CoffeeScript is able to do what it does. "what parts of the code will get hit when the code spans a page" just blows my mind. What the I don't even. Are you programming on punch cards or something? I would love to see some of your "legacy" code, I bet it's just awful, like train wreck bad.

Neither PHP nor Ruby has meaningful whitespace, but thanks for pretending like you know something.

Love that you refer to "jashkenas from the CoffeeScript blog"; yeah he's only the guy who created the damn language.

Oh and finally, you should definitely create jShort. Even though I know you will fail before you even start, I would love to laugh at your attempts and it would be perfect for you since you ride the short bus.
Gravatar # re: Why CoffeeScript is tough to maintain
by renso at 10/18/2012 11:28 AM

Thanks for your feedback!
Gravatar # re: Why CoffeeScript is tough to maintain
by mpaine at 11/16/2012 7:06 PM

Sounds like you should be looking at Microsoft TypeScript.
Post A Comment