My Digital Junk Drawer

For years I’ve been working in languages that are loaded with “punctuation”. Semicolons, parenthesis, curly braces are just everywhere. Between C#, JavaScript and CSS, I think I reach for the opening and closing curly braces more than any other key on my keyboard. I recently decided to learn Ruby on Rails 1 and have found the sparse use of curly braces, parenthesis and other puctuation in Ruby is a refreshing change compared to what I’m used to. With the built-in CoffeeScript support in rails I’ve also seen that I can have the same thing for my javascript.

I may go into CoffeeScript in more detail at a later date, but for now I’ll just point out that CoffeeScript is a language that compiles into javascript, and offers a cleaner and more succinct syntax so it is easier (and more fun) to write. An example is the fastest way to illustrate the point. Using the test console right on the web site, I wrote a simple piece of code that looked like this:

multiples = (num * 2 for num in [1..10])
alert m for m in multiples

And it compiled into this:

var m, multiples, num, _i, _len;

multiples = (function() {
  var _results;
  _results = [];
  for (num = 1; num <= 10; num++) {
    _results.push(num * 2);
  }
  return _results;
})();

for (_i = 0, _len = multiples.length; _i < _len; _i++) {
  m = multiples[_i];
  alert(m);
}

Which one would you rather write? That’s what I thought! Go check it out


  1. I plan to write more about my experience and resources I found helpful in learning Rails when I have gotten a little further into the process. 

  1. avanslaars posted this
Blog comments powered by Disqus