Monday, December 17, 2012

CoffeeScript > JavaScript

There is one thing that is missing in coffeescript vs javascript comparison on coffeescript.org. In coffee almost all the braces are optional and therefore it's "easy-on-the-eye", but (!) there's also a huge benefit of omitting braces - you don't have to match them.

Like this:

abc = (function() {
  $.ajax({
    url: "/cgi-bin/someapp/someurl.php",
    data: ({
      someparam: "somevalue",
      anotherparam: "anothervalue"
    }),
    success: function(data) {
      somehandler = function() {
        alert("bl");
      };
      for(var i=0; i < 10; i++) {
        somehandler(i);
// WTF below this line
      }
    }
  })
})()

And... last four lines are easily understood in this short piece of code or if the code was written two minutes ago. It will be not, however, 3 months after that.

No comments:

Post a Comment