2012-02-11

Readability !== Comprehension: CoffeeScript Case

I am not exactly a Javascript guy, though I acknowledge the power and need for JS in today's web environment. It seems that the CoffeeScript (CS) language, which acts as a pre-processor to JS, gains some popularity in the industry.

CS removes most of the symbols like the braces and semicolons and adds whitespaces like Python; so much that it is possible to write almost complete English sentences (long one-liners) which will be processed into tens of lines of JS code.

While searching for information on CS, I've stumbled upon an interesting criticism here by Ryan Florence, which got me thinking.

While I am a fan of syntactic-sugars in my languages and powerful data operators like the generators and list-comprehensions, I found myself agreeing with many of the criticisms int the article. Especially the ideas that readability and comprehension are different things; and the fact that the symbols are faster than words.

I wouldn't declare CoffeeScript as a bad language to use based on this criticism though since most of the criticized points are optional in it; and I like coding in Python which shares many of those features. But the general idea of the power of the symbols seems to be a good one to meditate on. Maybe Python had got rid of its 'readable' syntax in favor of more symbolism while keeping its great syntactic-sugaring and crazy data operations, it would be an even better language for me :).

Alright, so this example is from the article....Which is more comprehensible?

JavaScript:
if (five && six && seven) doStuff();
CoffeeScript:
doSomething() if five and six and seven
Another one:
wash plate, brush, sink for key, plate of dishes when plate.dirty if meal.status is 'done'
That backwards 'if' statements and the use of 'and's 'or's etc. cannot be good for fast comprehension and debugging.

One of the comments (by James Treworgy) made total sense for me:

"Actually this is the thing that has kept me away from CS more than anything else. Comparison operators are at the root of mathematical equations which are the essence of computer programming: if x = y then .... Removing the visual cue seems pointless as best. It's less terse, and it confuses literals, variables, operators, and reserved words. 
Serious programmers go to a great deal of effort to identify and implement consistent patterns in their code to make it easily comprehensible. We use capital letters to mean specific things, and we use operators and braces and parenthesis to clearly define the intent of a given expression. At the essence of CS is a desire to make code read like English. 
But English is not code. It lacks adequate syntax to clearly express the kinds of things we express in code. Would a mathematician want his integral symbols replaced with the words "integral of" or his ^ notation replaced with "to the power of "? 
Doing that would only benefit people who aren't mathematicians. Likewise, I think trying to make computer code "readable" really means "make it readable to people who aren't comfortable with the language of computers." What is more readable to someone who doesn't feel comfortable with "!==" is less readable to someone who works with it every minute of every day."
Hmmm, interesting food for thought for me concerning the meaning of coding and the relationship of the coder with the code itself.

6 comments:

  1. "doSomething() if five and six and seven"

    That is enough to put me off entirely. It feels wrong, and it takes extra effort to mentally parse. In the Javascript example I see the condition first and can decide if I need to look at the call. In the CS case I see the call and then have to check if there are any conditions before deciding whether to check it out.

    ReplyDelete
  2. Use keywords people will use to conduct a search so you can be found.

    It is therefore important that you establish certain 'habits' early
    on when blogging to make your site more appealing.

    Promote and distribute your posts on to other social media platforms such as Facebook, Twitter and Linked - In.


    Also visit my site: blog writing

    ReplyDelete
  3. Use keywords people will use to conduct a search so you can be found.
    It is therefore important that you establish certain 'habits' early on when blogging to make your site more
    appealing. Promote and distribute your posts on to other
    social media platforms such as Facebook, Twitter and Linked - In.


    Also visit my website; blog writing

    ReplyDelete
  4. The same reason that people buy youtube views is why they buy Facebook fans.
    That is all performed by web phone, Skype, Google Hangout or by telephone.

    Also, economic growth is unlimited in the world and should not be restricted by
    worry about natural resources.

    ReplyDelete
  5. If it's important for you to have to ease and convenience of running all the different aspects of your site (design, hosting, and domain registry) through the same service, it will be worthwhile to pay a little extra for Weebly's registry service.
    People and businesses around the world connect through the World Wide Web
    on a continuous basis. A dependable on the web solution should construct their
    marketing and advertising plans based on a confident knowledge of the way
    their clients locate them.

    Also visit my webpage web design austin tx

    ReplyDelete
  6. Ηello! Quick question that's totally off topic. Do you know how to make your site mobile friendly? My weblog looks weird when browsing from my iphone 4. I'm trying to finԁ a theme or plugin that might be ablе tο
    coгrect this problem. If you hаve аny recommendatiоns, please share.
    Many thanks!

    my wеbsite home insurance companies

    ReplyDelete