Byzantine Reality

Searching for Byzantine failures in the world around us

... And Then Came Ruby

I originally wanted to write a big long post about how I was stuck on the Java train my entire life and now I found Ruby and was in love and all that wonderful crap…but for some reason I got most of that out of my system the last time I complained about it. Therefore, I’ll just stick to some of the highlights and oddities that I’ve run into with Ruby and save all of us the time and grief involved.

Since I’m too scatterbrained to correctly sort this post into a “good” and “bad” section, I’ll just pseudo-randomly throw them out there.

  • Good: Ruby is less verbose than Java. This one isn’t too hard, considering that everyone on the damn planet is less verbose than Java, but Ruby is so much less verbose that it’s a very welcome thing to see.
  • Bad: I was under the original impression that do…while blocks and closures are basically the same thing in Ruby-syntax land, but some mild fiddling has shown that not to be the case and since I’m new to the language, I’m still learning which times get which. For example, if I want to open up a file and output everything in it, I just do this:
foo = open("ExecRuby.rb")
.each { |line|
puts line

While learning Ruby, this looks like you could also just do this to the same effect:

foo = open("ExecRuby.rb")
.each do |line|
puts line

Yet the first works and the second doesn’t (note that both “compile” fine). Again, this is just new-language-syndrome and I haven’t figured it out yet, but syntactically it feels like these would do the same thing (in fact, the second doesn’t do anything that I can tell). 

EDIT 09/25/08: This seems to be more of a fumbling on my part, as the comments indicate these should be identical.
  • Mostly good: Rails (maybe Ruby, not sure) has an open policy of not being thrilled about backwards compatibility. The argument given in the Agile Development with Rails book pretty much sells it as being against bloat: Do you really want to end up with what JavaBeans and XML looks like now after having to support every crappy choice made down the line? If you made a bad choice, get rid of it! I’m definitely against bloat (hence the possible Ruby conversion in the first place), but there’s the obvious problem: now I’m tied to my specific Ruby/Rails versions. This isn’t terrible, since Rails lets you package in the version of Rails needed to run so you don’t have to worry about manually fetching it, but what about a possible huge security vulnerability? If they only fix it in the newest version, you are pretty much screwed it seems.
  • Interesting: Method_missing has an incredible amount of potential (and likely danger that comes with potential). For those not familiar with it, here’s the executive summary: If you call an object’s method and it doesn’t exist, it gets caught by method_missing, who then can do whatever it feels like with it. Here’s two short little articles that explain it more with examples. The original article that sold me on it is implementing tab-completion for Ruby, which is insanely undoable in Java without the magic of Reflection (and it’s more complicated in Java, just look at how long that article is versus the first article I listed on method_missing).
  • Also interesting: Duck typing. Again, long story short: if I call a method on an object, the object doesn’t need to be of the correct type, it just needs to have the right method. Combine this with the crazy amount of overloading of standard classes you can do (the similarly dangerousmonkeypatching) and some interesting things can come out of it. So far it’s mostly that files, strings, and arrays can all be operated on in very similar manners, possibly cutting back on the DRYness involved.

I’d go on longer but I’m still new to Ruby-land and over the years Java is trying to keep on trucking by adapting little changes to try to catch up (see Java generics or Java closures). Will it be enough? Who the hell knows. But it should prove for an amusing ride at the least.

P.S. The type system seems to get everyone all crazy excited, but this amazing article can help out a bit on the education bit.