Deirdre Saoirse Moen

Sounds Like Weird

Java is Aristocratic; Ruby is Democratic

10 October 2005

A week or so ago, I was trying to explain to someone (who is not a programmer) what the difference in object inheritance between Ruby and Java is. I explained duck typing, but the person still wasn’t getting at what I meant.

I blurted out something different. “Well, Java is aristocratic, and Ruby is democratic.” I went on to explain that Java, in order to determine what you’re capable of depends on what your parent was capable of, plus those special methods that make you you and not your parent. It doesn’t matter if some other kid can do the exact same thing (with the exact same code), if it doesn’t have your parent, Java will think it can’t do it. Thus, aristocratic, because capability is determined by inheritance.

In Ruby, all you ask is “can you do this?” by invoking the responds_to? method. If it does, you’re golden. Thus, Ruby is a meritocracy, which doesn’t, strictly speaking, equate to democracy.

While this may not seem like a big deal, I should point out that it can be. For example, for my first large C++ project, we used zero class libraries from other vendors because none were ready yet. However, when they started coming out, it would have required huge chunks of re-coding to incorporate into another library because the inheritance would have changed.

At the time, when working with Windows coders as a Mac developer, I was keenly aware of how different the object hierarchies were: on Windows, everything was a subclass of window: text panes, buttons, everything. On the Mac, none of the other visual elements were subclasses of windows.

So, in other words, if we’d moved our custom framework into another company’s, such as PowerPlant, we’d have had to do a lot of code changes — probably more than if we’d used a C library — because we’d have to have had everything inherited from the right classes to buy into the framework’s inheritance model.

Had we been using Ruby (which didn’t exist at the time), we might have been able to do this in small chunks rather than all at once — because Ruby cares about what you can do, not who your parents were.

One of the geniuses of Sun was not the language per se, but the idea of releasing frameworks that helped standardize the use of the language. There’s now a lot of competing frameworks, though, so that didn’t last long.

On a completely different note, a couple of weeks ago, we went out to dinner with our friends. One of the people made a comment about Java being slow doing something or other. The person across the table, who works for Sun, commented, “You do realize that Java is a language invented by a hardware vendor….”


Related Posts