New Location

My website has moved to http://www.jasonwhaley.com. Please visit there for the latest and only remain here for legacy content.

Wednesday, November 11, 2009

But... why ruby?

"One Language A Year" - or at least that's what the Programmatic Programmer reckons one should do. I've spent the majority of this year doing non development work. For any coding work I have done, I've gone back to my workhorses of bash, java, and python. This effectively means that in the three years I've worked as a software engineer (or similar) I've remained a three-trick pony. Although with that said, if I decided to actually go learn C++, I would know the gamut of the predominant languages used within Google, so I'm not fairing too badly.

Still, learning a language teaches one new idioms, new ways of solving problems, and increasing the toolset available with which to solve problems. For those reasons I'm going to allow myself to pick up another language. However since there is only two months left in this year and I'm super busy with non development work, I'm not going to learn a full language and become somewhat familiar with its accompanying sets of frameworks, libraries, and APIs in two months. Instead, I'm going to take a minimalist approach and take a one day at a time shot at learning ruby. I'll be spending a single solitary hour on hacking ruby code each working day. Doing that from now until the end of the year should possibly teach me enough of the language to claim I know it on the surface and will let me know whether or not I want to continue with it in 2010.

But... why ruby?

  1. Everyone who I know that has picked up ruby has only good things to say about the language and API. I'm not counting rails here... just ruby the language.
  2. It looks more flexible than my current dynamic language of choice, python. For example, one sees tons of material about writing DSLs in ruby. For all of python's goodness, it doesn't feel like a good language to facilitate writing DSL's. I welcome any objections to that assertion, of course.
  3. The ruby developer community where I live is strong. Hashrocket, a pretty well known ruby (on rails) shop is a 7 minute bike ride away. There's nothing better than sharing with and learning from a kick ass group of tightly knit developers.
  4. I want something that isn't tied to JVM. I could have cheated with my selection and chosen something like Groovy or Scala, but I want something completely different. Scala is interesting and there are some neat functional idioms and concurrency support features intrinsic to the language that would be useful, but I'll save it until next year. For now I want to see what world is like outside of java land.
Of course, one needs a non-trivial project in order to pickup a language and its platform. I learned java pretty much by attempting to hack on the Netflix Prize as part of my Master's thesis. It's a fun problem and will probably allow me to flex a majority of ruby features in attempting to solve it again.

Day one was yesterday. I spent the first 25 minutes going through the Ruby in 20 Minutes tutorial (yeah... I'm slow) and the next 35 minutes starting to write a module/class to read in comma delimited files from the Netflix Prize dataset that identify a user id, rating, and timestamp for all ratings on a given movie.

In doing so, I managed to explore the following basics in Ruby

  • File I/O (or at least reading files)
  • The CSV module
  • Iteration
  • Attributes
My initial first thoughts?

  • irb is a pretty neat interpreter. I'm a huge fan of the interactive python interpreter (and even bigger fan of bpython). The only thing missing here is the ability to see rdoc from irb - probably due to the fact that rdoc isn't stored as a member of any modules or classes the way that docstrings are in python (and accessible via .__doc__)
  • Attributes are awesome way to remove boilerplate property code. It just reduces the noise of having tons of getX() and setX(Object x) implementations and calls to access the internal members of objects in Java.
  • Reading in a file in ruby was just as easy and straightforward in ruby as in python. That's always a joy.
  • The shorthand iteration of an enumeration threw me at first, but perhaps it's just a rubyism that will grow on me as I find out how to use it effectively.
    file.each { |line| extract_rating_from_line } 
    just didn't seem quickly intuitive the way that an equivalent list comprehension in python would
    [extract_rating_from_line(line) for line in file.readlines()]
    or perhaps I'm just too used to python at this point.

Hopefully after this evening I'll have at least a working module and some classes for parsing ratings from those text files and get to explore some things like exception handling.

0 comments: