10 Things I Hate About Ruby
1. initialize
To create a new object in Ruby you invoke the new
class method like so:
c = Car.new("Toyota")
Naturally you think the constructor would be defined in a method called new
, right? Or just maybe a method called Car
like in Java? But no, instead it has to be called initialize
like this:
class Car
def initialize(make)
@make = make
end
end
Would this have been so hard?
class Car
def new(make)
@make = make
end
end
2. Weak typing
As a library vendor, it scares the bejeezus out of me that anyone can pass anything to my methods and I’m expected to handle it. It’s like walking into McDonalds and ordering a Big Mac, and instead getting a Tofu burger; not very appetizing. Ruby’s thrown out the one piece of precondition checking most languages give you for free.
3. Automatic returns
Didn’t C teach us that unexpected results were confusing? This is Ruby’s equivalent of C’s a = b + a = c;
. Returns should be explicit. An explicit return is not hard to write, and it’s a lot easier to read and understand. Reducing finger typing and at the expense of increasing brain confusion is not a wise tradeoff. Languages should be concise only in so far as that improves clarity. When compactness comes at the expense of clarity, it’s a bad thing.
4. Global variables
Didn’t somebody tell me Ruby was an object-oriented language?
5. puts
Do we have to copy C’s most ungrammatical, pointless method names?
6. Zero-based arrays
C arrays began at zero to match memory addressing. In a weakly typed scripting language, there’s exactly no reason to do this. There hasn’t been for decades. Can’t we please start the arrays at 1 where God intended? Hasn’t anyone read Numerical Recipes? Aren’t we tired of fencepost errors yet?
7. elsif
Sorry. “elsif” is not a word in the English language, and it shouldn’t have been one in Ruby. Would typing one extra letter have been so onerous?
8. $_
Global variables suck. Did I say that already? Global variables you didn’t actually create and that pop up out of nowhere suck even worse. And global variables whose names are indistinguishable from line noise suck still more. Java’s verbose, but that verbosity is in the service of legibility. Ruby’s compactness all too often serves only to obfuscate.
9. Methods are public by default
Minimal interfaces to classes are important. The less a class promises, the easier it is to change, optimize, fix, and otherwise improve. Furthermore, the easier it is to learn and understand. Everything that can be private should be private.
Now of course you do need public methods. Not everything can be private. However this shouldn’t be the default. Marking a method public decreases the flexibility and increases the learning curve of the class. It should require an explicit decision from the programmer to do this. Ruby gets this exactly backwards. A programmer just banging out Ruby code is likely to create a class with nothing-but-public-members, without even thinking about it. That’s a bad thing.
10. No package access or friend functions.
There’s no access in-between public and private. All too often different classes in the same library/application/codebase need more detailed access to their other parts than the general public should have. Ruby provides no way to manage this.
In conclusion
I could go on (and I probably will) but that’s a nice round number of hates for now. I’m also keeping a list of things I love about Ruby as I learn the language. However, the things I hate hit 10 before the things I love. That’s not a good sign.
September 9th, 2020 at 6:59 am
I work with Ruby since 3 years and sometimes I thing it’s a good language, but sometimes
when I’m frustrated I thing it’s the most shit ever.
I’m really not able to get used to this strange syntax.
The syntax is inconsistent – sometimes it looks to be clear sometimes not.
For instance – sometimes you don’t have to use arguments in () but sometimes you must.
Names of methods are confusing – ‘alias’ and ‘alias_method’ are not doing the same.
There are traps everywhere.
This lang is not elegant or beauty – it’s a big mess.
Huge amount of gems are bullshit made by students.
Complementary tools like ‘Rubocop’ sometimes are helpful but they disturb rather than help.
Ruby made me realize that Java or even Cobol are not so bad.
April 30th, 2021 at 7:07 am
Ruby is by far the most garbage language I have ever had the honor of working with. Now I know not everyone is in Java or C++ but I simply love C++. Its so much clearer most of the time because it is explicit and the typesystem is just something to get used to. Types help more than they hinder. Besides, the programming languages are using types internally anyways so why not just operate on them as a Developer? Also I have to disagree on one of the points: Arrays should definitely start at 0, it would be catastrophic if they wouldn’t ๐ However that does not mean that I like ruby.
Monkey Patching is just another dumb thing as well as Duck-Typing. Overall Ruby is just Python but way worse. Who wants to write def and end all the time anyways? I also think that C++’s {} are way clearer and faster to type. Almost every editor you can find has parenthesesmatching but not every editor can match begin and end blocks. Ruby devs have to find an IDE that can do this. Overall the “Ruby Way” of doing things is so much different from other programming languages, I would even prever using Scratch over Ruby any day.