DEV Community

Discussion on: Why I still love Ruby

Collapse
 
jonathans profile image
Jonathan Sundqvist

Compared to the mantra of python. "There should be one-- and preferably only one --obvious way to do it". I wonder if that has constrained python developers :)

Collapse
 
hopsoft profile image
Hopsoft

This is an interesting question. The two distinct philosophies is certainly the primary difference between these amazing languages IMO.

Collapse
 
benbot profile image
Benjamin Botwin

Matz (the creator of ruby) used to talk about the "Principle of least surprise" being this idea that if the way some language feature works doesn't surprise you, then you're happier for it.

Because of this idea Ruby has many MANY different obvious ways to do anything. This makes many different kinds of devs happy, because they can always write in the way that makes the most sense to them.

This is an amazing boon as a solo dev or a small team, but in larger settings this can be kind of a pain since a code base could become inconsistent pretty quickly unless the org enforces a kind of style.

Python takes the opposite approach.

That's probably why in the early 2010s there was a lot of (mostly comedic) volatility between the ruby and python communities

Collapse
 
jonathans profile image
Jonathan Sundqvist

"Principle of least surprise" maps pretty well onto there should ideally only be one way to do something. If there isn't several ways of doing something it's not surprising :).

I was reading some ruby a while ago, and stumbled upon. array << element. It took some serious googling to figure that one out, and I'm sure there are several ways you can write that too.

Thread Thread
 
benbot profile image
Benjamin Botwin

I think the approach that ruby took is one of individuality. Imaging that the "one preferred way" of adding elements to arrays was array << element.

You'd be surprised that something like array.push wasn't working, and even more surprised that array << element even existed.

Even though, in our hypothetical language, that's the only preferred way to push to arrays, it's still surprising.

If any of that made sense

Thread Thread
 
hopsoft profile image
Hopsoft

It's fascinating to see how something like "principle of least surprise" can be interpreted and addressed so differently. The Ruby and Python solutions for this could not be more different.

Thread Thread
 
benbot profile image
Benjamin Botwin

It’s especially interesting because both languages (python 2.7 at least) are pretty similar from a high level technical point of view.

Both OOP style languages
Both interpreted (usually)
Both very high level
Both dynamic
Both are even heavily used in web development

Collapse
 
notjames profile image
Jim Conner

I agree. There are some Python things that just drive me insane due to the inconsistencies of implementation namely between procedural and object oriented development. Python is an OK language, but given the choice, personally, I'll take Ruby over Python any day.

Collapse
 
strzibny profile image
Josef Strzibny

There should be one-- and preferably only one --obvious way to do it

Except for the Python dependency management ;)