Ruby Avoids Consistency like the Plague
March 8, 2013
Ruby Avoids consistency like the Plague
Ruby is such a great language in so many ways, it always feels especially disappointing when one discovers a way in which it lacks. I believe much of Ruby’s less noble attributes stem from a single source: Matz and company eschew consistency as if it were a disease.
Let’s take a simple example that occurred to me today as I was working on a reflection system for Ruby. It has probably slipped by every Rubyists on the planet, but once it is pointed out, it’s pretty obvious. A class has instance methods of which we can get a list via the #instance_methods method, as opposed to an instance of a class whose methods we can list via #methods. That in itself might be an acceptable naming system accept the instance also has a method called #instance_variables (not to mention a number of other “instance_” methods). Give it a moments though and it becomes clear that the terms don’t jive well. The problem lies in the fact that classes don’t actually have “instance methods” per-se. They have method definitions that become instance methods when a class is instantiated. It would have made much more sense for the class’s method to called #methods and the instance’s to be called #instance_methods. Or, at the very least, the class terminology could have used something else like #method_definitions.
Generally we developers just accept APIs as they a given us and go about using them without giving too much thought to the nomenclatures used. Unfortunately inconsistent terminology often leads to difficulties communicating with other developers, ultimately wasting time and energy. The above is just one example of such an inconsistency. But don’t bother telling Matz or the rest of the Ruby core team. They will just tell you “consistency is as a bad reason for language change”. Perhaps in the short-term that is true to avoid backward compatibility issues. In the long-run, however, it’s only a matter of time before people head to greener pastures.