Coffeescript: Joyful and Unreadable

Leave a Reply

Comment as a guest.

  1. Odds are you aren’t Ruby enough 🙂 Really though, yes there’s a lot happening, but that’s some what the beauty of it. Translating that in to it’s JavaScript equivalent would make for a very unreadable and unenjoying experience.
    We as Rubyists are spoiled with beautiful syntax and I know I personally have trouble looking at syntax such as JavaScripts.

  2. I felt the same way until I started using Coffeescript. Once I actually sunk my teeth into it, it became very readable, very quickly. Beyond that, not having to mess around with all kinds of closures and verbose looping mechanisms meant that character-for-character, more of my code is business logic. Your examples up there feel very clean to me.
    Try comparing the equivalent handwritten JS to the Coffeescript examples up there. I think you’ll find that they aren’t very readable (though they’ll be more comfortable, since you know Javascript already).

  3. For me, it’s all about how clearly the code communicates the intent of what’s going on.  That first example I would read as “call getRecentPosts and with the result call reset on myself with a new Post for each post”.  I can easily understand the essential intent because it’s not hidden behind a bunch of syntax noise and hoops I have to jump through to make the language happy (eg var self = this).  It may be that after trying coffeescript for awhile it will read more naturally for you as the other commenter suggests.  

  4. I would try writing something a little different to start with CoffeeScript. You’re example you listed as evidence to your code being dense looks an awful lot like the wordpress api is partially at fault here. Backbone is another culprit for making your code seem dense. Try CoffeeScript/jQuery by itself and I’d be willing to bet you’d find it more enjoyable. I mean, the title to this post is CoffeeScript: Joyful and Unreadable. It really should be CoffeeScript, Backbone, and the WordPress JSON Api: Joyful and Unreadable. Not really a fair assessment.

Sliding Sidebar