Why do you love Ruby, actually? An ode.
Tags: ruby, discuss, rails, codenewbie
Published: 2021-02-21 22:46:03

✨ **tl;dr** ✨ I love Ruby and I'm curious to learn what makes it special to YOU (and if/what other languages you know to see what your point of comparison is)

---

I had a chat last week with a very kind friend who’s been in tech for quite a few years now. We both agreed we wouldn't be sad if PHP disappeared overnight and we also had no wish to come anywhere near .NET. We talked about our languages of choice and when I mentioned Ruby, he responded that he feels “meh” about it! He “just doesn’t understand what the Ruby phenomenon is about” 😩

Now, you need to know that I don't usually engage in debates like "which language is the most superior", "why VSCode is/not great" or "why you should/not use vim" because I am too much of a [1xEngineer](https://1x.engineer/). I didn’t think I had strong opinions on others’ programming language preferences. Why, then, was I so shocked to learn that he was mildly disinterested in my most beloved language? And why is Ruby my *most beloved language* to begin with?  

I asked my friends why they love Ruby and also thought about it for a bit myself. I'm dividing this post in two main parts: 
- Crowdsourced reasons, which include these points:
  - [Built-in methods](#the-wealth-of-builtin-methods)
  - [Syntax](#the-readable-syntax)
  - [Error messages](#error-messages-that-are-actually-helpful)
  - [Monkey Patching](#the-effortlessness-of-monkeypatching)
  - [Ecosystem and community](#the-whole-ecosystem-and-community)
  - [Syntax](#the-readable-syntax)
- [My main, more personal, reason](#my-main-reason-ruby-is-all-in-for-inclusion)

---
When chatting with friends and students, I noticed a few prevailing themes which I’m presenting below.

### ✨ the wealth of built-in methods 
Ruby seems to have a method for every occasion and many aliases constantly joining that party. For instance, `each` is the basic enumerable method but there's also `each_with_index`. There's a `size` method for arrays but if you have an experience with another language and `length` and `count` seem more intuitive, please don't stress: the former is an alias and the latter is more versatile but also works on arrays. 

Here's a quote from Yukihiro "Matz" Matsumoto, the creator of Ruby, that explains the design principle behind making Ruby so intuitive and seemingly "simple":

>Make Ruby natural, not simple, in a way that mirrors life. (...) Ruby is simple in appearance, but is very complex inside, just like our human body. 
> 
> -- <cite>Yukihiro "Matz" Matsumoto in [Ruby Docs](https://www.ruby-lang.org/en/about/)</cite>


If I were a 10xEngineer, I'd go out of my way to prove that Ruby is the best by making pointless comparisons to another language (JavaScript, for instance, which is always an easy target), just like this:
- `last` in Ruby vs `.slice(-1)` in JS
- `.shuffle` in Ruby vs [in JS](https://medium.com/@khaledhassan45/how-to-shuffle-an-array-in-javascript-6ca30d53f772):
- `each_slice` in Ruby vs [in JS](https://stackoverflow.com/questions/10249658/equivalent-of-ruby-enumerableeach-slice-in-javascript)

I, however, trust that awesomeness of the gifts Ruby showers us with will speak for itself. 

---

### ✨ the readable syntax
While other languages require you to explicitly write `()` or `{}`, in Ruby you can either skip them or choose more visually-pleasing solutions. For instance, you can write:
- `Person.new` or `Person.new()`;
- `Person.new("Sylwia", "Rubyist")` or `Person.new "Sylwia", "Rubyist"`; 
- or, in Rails: `has_many :friends, through: :discussions`, or `has_many(:friends,{through: :discussions})`.

Of course, there's the friendly [style guide](https://rubystyle.guide/) that hints at which syntax is the most readable but that is a result of a community agreement and not a rule imposed on everyone by default. 

But there's more to Ruby's awesome syntax: you don't need to be proficient in it (or, in English for that matter) to know what's happening here:

```ruby
5.times do 
  puts "Ruby is great."
end
```

vs in JavaScript:

```js
for (let counter = 1; counter <= 5; counter++) {
 console.log("This could be better.");
}
```

Ruby looks and reads like English, decreasing the [cognitive load](https://en.m.wikipedia.org/wiki/Cognitive_load) on a very tired person who's working long hours under time pressure or who experiences occasional anxiety. This straightforward syntax is also a reason why Ruby is pleasant-ish to debug, which leads us to the next point...

---

### ✨ error messages that are actually helpful
When dealing with errors, Ruby gives you the whole traceback and a helpful suggestion when there’s a chance of a typo:
![irb showing a traceback of a "NameError:undefined local variable or method 'arr' for main:Object" followed by a suggestion: "Did you mean?  array"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7n2420022vot0zptxjgx.png)
Believe me, these helpful suggestions have saved me so many times. 

---

### ✨ the effortlessness of monkey-patching

If Ruby were a human, it would be a trusting person treating you like an adult who knows what you are doing. Case in point: monkey-patching of classes and methods. Just tell Ruby what you want to see happen. 

**note:** This is also doable in other languages like [Go](https://bou.ke/blog/monkey-patching-in-go/) or [JS](https://www.audero.it/blog/2016/12/05/monkey-patching-javascript/) but it takes more effort.

There are no limits to what can be overwritten. For instance, I could overwrite the `!` unary operator that returns the boolean value opposite to that of the `self`. In case of strings, which in Ruby are always truthy, it would always return `false`:

```ruby
 !'Hello!'
 # => false
 !''
 # => false
```

So now imagine a dystopian scenario, in which someone is blindly in love with Ruby and is a person with slightly authoritarian tendencies. In such a world, negating the awesomeness of Ruby would just not be possible. They could first define a punishment in the form of an instantly-dreaded `Falsehood Error`:

```ruby
class FalsehoodError < StandardError  
  def initialize(object)
    message = "Cannot be negated: '#{object}.'"
    super(message)
  end
end
```

And then throw it onto folks who dare to call the `!` method onto a string containing the ultimate truth about Ruby:

```ruby
class String

  def !@
    raise FalsehoodError, self if self == "Ruby is the most awesome language in the world"
    false 
  end
end
```

You could extend it further by also overwriting the `!!` message so it checks for the reverse of these statements (only Ruby should be perceived as the most awesome language) but even now, if someone promoted Ruby heresies, they'd be reminded of the one true stance:
![irb window showing "true" for the expression "!JavaScript is the most awesome language in the world" and throwing a FalsehoodError for "!Ruby is the most awesome language in the world"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywuhlx8bflhq21wqy3qv.png)

Of course, this could be devastating in results because the bang-based unary operators pertain to the datatype and not the value of the object and this could mess up our app logic. However, it’s a good example that Ruby trusts you and gives you tools to do whatever you wish, even if the wish is to learn from mistakes.

---

### ✨ the whole ecosystem and community
Ruby seems to have [a gem for everything](https://rubygems.org/gems/dad_jokes) and there are also similarly friendly, straightforward and well-documented libraries like Rails, Sinatra, or Hanami. 

Funny enough, as I was writing this post, I noticed that [Ben Greenberg](https://twitter.com/RabbiGreenberg) and [Paul Ardeleanu](https://twitter.com/pardel) discussed the day prior why Ruby rocks during the [Vonage twitch Ruby mini-series](https://www.youtube.com/watch?v=DS5V37k1EP0&feature=emb_title). The wealth of the ecosystem was one of the main points they mentioned. They referred the delightful Ruby books like ["Why's poignant guide to Ruby"](https://poignant.guide/), which in turn reminded me of other lovely Ruby publications such as ["99 Bottles of OOP"](https://sandimetz.com/99bottles) by Sandi Metz and or ["Confident Ruby"](https://store.avdi.codes/#rrWapR) by Avdi Grimm. Even though these are programming books, you read them with pleasure (Avdi's book is especially great for the geeks and sci-fi aficionados). The joy of coding in Ruby emanates through these books. 

At some point, Ben asked whether this amazing ecosystem extends to the community as well. Thinking about this made me realize that in trying to "defend" Ruby, I was completely missing the point of why I love Ruby so much. This also coincided with a lovely message from my friend [Michelle Nguyen](https://twitter.com/Michelle_Nguy) about the inclusive aspect of how Ruby was designed.

---

## My main reason: Ruby is all in for inclusion

Before switching my career to tech, I was a human rights advocate in Poland, a linguist and a researcher pursuing my PhD in sociology of nation. In other words, I care deeply about what makes some people belong and how we exclude others on a social, economic, or linguistic level. I bring this lens everywhere, and the tech world is no exception.

Learning to code is difficult in and of itself. Imagine learning to code in a foreign language while holding a full-time job and having very little financial security. That was me after I migrated to the US. Needless to say, I was stressed. I think of myself as a fast learner, especially when it comes to language-like systems, but my initial attempts to learn python or JavaScript were short-lived and unsuccessful. When trying to decide if a career is for you, one takes every failure or obstacle as a testament to that they're not fit for it. Same was with me: I could not make sense of all these brackets and of the unclear method names (splice?) -- and the error messages told me nothing.

I imagine that if you learned Math in English, some programming concepts make more sense. I was totally swept off my feet when I discovered that `variable` and `constant` are the same as the Math concepts I know "in Polish". However, because I didn't know/need this terminology in English and in my mind "Math" and "programming" occupied completely different domains, it took me two years to put these pieces together. It would have been much easier to understand JS fundamentals.

But then, I stumbled upon Ruby and while I was still confused at times, I was never completely lost. It felt like Ruby had my back. **I cherish the fact that it reads like English, that it requires minimal cognitive load, that it offers helpful suggestions when you just made a typo.** I think that the convention over configuration and the strong preference for [SOLID](https://www.digitalocean.com/community/conceptual_articles/s-o-l-i-d-the-first-five-principles-of-object-oriented-design) make the code more **intuitive and organized**. 

And all this is not a coincidence -- Ruby was designed this way.
>I wanted to minimize my frustration during programming, so I want to minimize my effort in programming. That was my primary goal in designing Ruby. I want to have fun in programming myself. After releasing Ruby and many people around the world got to know Ruby, they said they feel the way I feel. They came up with the phrase the principle of least surprise. 
> 
> -- <cite>Yukihiro "Matz" Matsumoto in [Philosophy of Ruby, A Conversation with Yukihiro Matsumoto](https://www.artima.com/intv/ruby.html)</cite>

**Ruby cherishes kindness** and that also extends to its community, which embraces the acronym [MINASWAN](https://en.wiktionary.org/wiki/MINASWAN), which  stands for 'Matz is nice and so we are nice". I mean, can it be a coincidence that some of the most wholesome people on  tech twitter like Ben Greenberg, [Ben Halpern](https://twitter.com/bendhalpern), Michelle Nguyen or [Yechiel Kalmenson](https://twitter.com/yechielk) are Rubyists? Or, that [Ruby on Rails Link](https://www.rubyonrails.link/) is such a lovely slack community? 

I do think that kind communities attract kind folks so perhaps that’s the key to my story: I assumed that the friend, being the kind person that he is and having been exposed to Ruby, would love the language. His mild disinterest came as a surprise because he’s been so far the first friendly person seemingly immune to Ruby’s charms.

**tl;dr: Both Ruby and its community are thoughtful and caring  and that's why I feel so strongly that everyone should 💖 LOVE 💖 it.**

---
Photo by Chevanon Photography from [Pexels](pexels.com)