I’ve been away in Ruby land for a while, and now that I’m doing (a little) bit of Java at my job, I find it so infuriating. For example, we have a logger class that I can call like so:

  1. log.debug("foo");

Fine and dandy. But say I want to output whether something is true or false, like whether something is null. My instinct (Ruby-encouraged) is to do this:

  1. log.debug(foo != null);

“Oh no”, says the compiler, “you can’t do that! That’s a boolean! I need a string!”

$&^!@&^%#@(

Frickin’ Java! Just turn it into a string! Call its toString method. Holy crap do some work for me! The other problem I have is with null. This thing is a special beast in Java. Doing something like this will yield a spectacular failure:

  1. Object foo = null;
  2. System.out(foo.toString());

So I have to check whether something is null before I convert it to a string. This gets real ugly real fast:

  1. Object foo = null;
  2. System.out((foo == null) ? "null" : foo.toString());

Except that I don’t even think this’ll work because Java (maybe, I can’t remember) evaluates both parts of the ? : construct. So we’re left with this:

  1. Object foo = null;
  2. if (foo == null)
  3. System.out("null");
  4. else
  5. System.out(foo.toString());

Jeez! Took long enough. Here it is in Ruby:

  1. foo = nil
  2. print foo

Ruby, my terse friend, you are just great! Duck typing is the future!

Technorati Tags: ,