In my continuing objections against Ruby, I've been studying the core API docs on
http://www.ruby-doc.org/core/It seems to be quite a mixed bag. A few classes seem quite reasonable but most are cluttered with obscure methods with opaque names. Let me give you a few examples:
What do you think String.tr(...) does? What about Date.amjd()? Nope, I've not got a clue either.
If you want to know when a file was last modified, which of these is clearer: mtime() or lastModified()? When you're reading code, looking for bugs or trying to modify someone else's creation, clarity is important. You read code far more often than you write it, saving a few keystrokes during authorship may impress your script-kiddy friends but it won't impress your boss when it takes ten times longer to understand afterwards, especially when you have to keep referring to the API docs to tell you what the 'hton' method does.
If all this wasn't frustrating enough, there are aliases to confuse you. What's wrong with having one method name to perform one function? Isn't Queue.pop enough? What's the point in having an alias for it called 'deq'? Whatever happened to DRY?
By far one of the worst classes in Ruby for method names, repetition and bad organisation is the Array class. It has an 'each_index' method which is the same as looping 'n' times where 'n' is the length of the array. Array.fetch(-1, nil) does the same thing as array.last(), array[-1] or array.at(-1). Abbrev is a method that only works if each of the elements in the array is a string. From an OO point of view, the Array class shouldn't have methods that deal with specific array structures and content. The same applies to the 'assoc' method. Both of these (and more, e.g. transpose) belong in separate classes. Pop and delete_at(-1) do the same thing and there seem to be at least half a dozen ways of appending something to an array.
On the whole, Ruby doesn't seem to me to be very object oriented. Yes everything is an object and there are classes and inheritance but OO goes way beyond those basic components. It's about sensible organisation and separation of concerns. It's about clarity and simplicity wherever possible, it's an entire programming paradigm, not just a language feature set.
Labels: development, OO, programming, ruby