✨ 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. 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:
- My main, more personal, reason
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.
-- Yukihiro "Matz" Matsumoto in Ruby Docs
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:
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
orPerson.new()
; -
Person.new("Sylwia", "Rubyist")
orPerson.new "Sylwia", "Rubyist"
; - or, in Rails:
has_many :friends, through: :discussions
, orhas_many(:friends,{through: :discussions})
.
Of course, there's the friendly style 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:
5.times do
puts "Ruby is great."
end
vs in JavaScript:
for (let counter = 1; counter <= 5; counter++) {
console.log("This could be better.");
}
Ruby looks and reads like English, decreasing the 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:
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 or JS 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
:
!'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
:
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:
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:
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 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 and Paul Ardeleanu discussed the day prior why Ruby rocks during the Vonage twitch Ruby mini-series. 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", which in turn reminded me of other lovely Ruby publications such as "99 Bottles of OOP" by Sandi Metz and or "Confident Ruby" 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 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 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.
-- Yukihiro "Matz" Matsumoto in Philosophy of Ruby, A Conversation with Yukihiro Matsumoto
Ruby cherishes kindness and that also extends to its community, which embraces the acronym 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, Michelle Nguyen or Yechiel Kalmenson are Rubyists? Or, that Ruby on Rails 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
Top comments (77)
Totally understand about the good points of Ruby, however don't count out PHP - it's got a lot better, and it's a much nicer language nowadays than it used to be, especially with "Rails-like" frameworks like Laravel !
Yes! Laravel makes PHP so much better. I've worked with both PHP without Laravel, cleaning up a nightmare application where the dev had multiple methods of the same exact code copied and pasted everywhere, and then went to a PHP project with Laravel (and devs using clean code pursuits haha) and it was night and day.
Yes I'm with you there, hundred percent, difference of night and day ...
PHP pre-Laravel tended to be a hackish, sort of an old-school "Perl" style mess, but if you look at code written in Laravel style - most of it is elegant, succinct, "OO" and so on ... I also tend to prefer Laravel's utility methods like \Arr, \Str and so on over PHP's built in methods just because of their logic and elegance ... and Laravel's collections are superb (plus the Eloquent ORM, and I could go on).
I agree that Laravel seems to have really transformed the PHP world - maybe you cannot solely credit Laravel for that (there have been other positive developments in PHP) but it's a big (if not the biggest) factor in that transformation.
Oh, interesting — what are other positive developments in PHP? Or, is there a blogger I could refer to to catch up on PHP news? :)
Well, performance is MUCH better than it used to be, PHP 7 and 8 made big strides in performance ... one other remarkable change is the move of PHP towards typing - type declarations/type checking.
Blogs, well of course there are many, we talked about Spatie, so here you go: spatie.be/blog
What's new in PHP 8:
stitcher.io/blog/new-in-php-8
Cool, now I’m excited! I’ll give it a try and report back ✨ thank you!
Haha okay, yes you should be!
Laravel is a great framework with a lively community & a vibrant ecosystem, they're innovating a lot - for example, recently I came across a version that runs "serverless" on AWS Lambda (vapor.laravel.com), check it out if you're into that kind of stuff.
And remember the name Taylor Otwell, he's the creator (twitter.com/taylorotwell), you'll see him mentioned quite often.
This does sound like a nightmare — and it's exactly what I understood PHP to be. I'm happy to learn that there is a better world out there! I'm excited to explore it. Thank you!
Oh really? Interesting, I'll give it a try, then. I was very discouraged by everything I saw so far from PHP and I'm happy to discover my own ignorance there. Are there any Laravel authors/devs that you'd especially recommend I check out if I'm just beginning there?
You should check out spatie and beyond code. They are building really great packages for the Laravel ecosystem!
Thank you!! I’ll check it out!
Ah right, yes Spatie is a good example of folks building nice stuff in the Laravel community!
No, still the same pile of garbage with unpredictable behaviour and full of exploits under the hood
Oh, really ... proof? Anyway I'm not going to enter into this sort of discussion, the only thing I know is that it's a useful tool and people get stuff done using it, nothing is perfect but millions of users/devs can't be that wrong.
Always the same "argument" (because there is no other): "mumumu, lot of people use it so it's good"
en.wikipedia.org/wiki/Argumentum_a...
Okay, what's the quality of your argument then? I don't have a nice Latin proverb to characterize it, but maybe "baseless claims" will do. I didn't say that I like PHP because "people" are using it or "everybody" is using it, it's because I'm using it productively myself and because I'm getting stuff done with it ... couldn't care less really about all of these language/stack/platform "mine is better than yours" wars.
What a great post!
Ruby was the first language I learned, and the one that caused me to fall in love with programming! I even got to meet Matz personally at RubyConf 2017 and thank him personally!
Unfortunately, I never really got the chance to work with Ruby professionally, but it's still my first love and my go-to for personal projects.
Maybe one day... 🤞
WOW! So ironic that while you are known in the tech online community for your expertise in Ruby and Rails, you don't get to code in it professionally. In all honesty, when I had some gloomy moments a year ago, I thought that I could make my life more beautiful by switching full-time to Ruby, "just like Yechiel" — the power of personal brand 😂
I was supposed to go to RubyConf last year but the pandemic happened. Oh well.
Lol oh man! I chose Rabbi on Rails for my blog when I was at Flatiron because the pun was too good to pass on, little did I realize how much it would define me years later 😅
You know, it's not like you haven't written AMAZING posts about Ruby/Rails recently 😂 I don't think it's solely the nickname but your general expertise and passion for the language 💖
Thanks! That means a lot coming from a great teacher of Ruby like you!
Hopefully we can meet up at RubyConf 2021? 🤞🤞🤞
Simplicity, just the necessary words to be easy to read.
No
return
keyword.No
self.age
to access instance attributes/methods.No weird method names (like
isAdult
).Trying to do the same in other languages seems that I'm writing unnecessary symbols.
Ruby is so readable and clean 💖
Thank you for this example, it is something everyone can understand from the get-go.
x.do
is probably more similar toIn terms of English, it reads the same as the ruby. "Do this block of code, while this condition".
It's a bad comparison.. I don't think I have ever needed to do something like this in js. If for example, I know I should do something 5 times based on the length of an array, I would be doing
myArray.forEach((item, index) => {....})
. (I imagine this is the equivalent ofeach_with_index
you mention too).I also find ruby, python and the like difficult to read because there aren't braces!! Creating a new instance of a class in a lot of languages look like this
let jen = new Person("Jen")
which is more "like English" over Person.new "Jen".Some of your examples for array manipulation do look complicated, but they're quite outdated. Newer versions of ES, and libraries are a lot nicer to work with.
I get why a lot of people love ruby, unfortunately I don't see/benefit the upsides since I've been writing js for a while now. Some of the things you mention can be easily remedied, and really I don't see very much any more. If you're writing JS in an OO way, then SOLID is 100% possible, and is quite common. IDEs and linters will weed out anything that isn't SOLID. But it's quite common to see JS written in a FP way - especially now that React is pushing for more FP, and serverless code.
I used to hate JS for a long time. ECMA6 and beyond had made it a joy to write though.. saddens me to see JS slander heh
Thank you for taking this time to write this comment. I totally feel what you’re saying.
My second love is JS (and especially React) — in fact, majority of my work has been done in JS. The examples I chose were definitely tongue-in-cheek and I’m sad that this was not more apparent. Well, maybe inspired by my post you’ll write a similar on about OOJS, just like I did in response to my friend 😂
I’m not here to dispute which language is better or more effective, or to “convert” anyone. As you see in the last part of the post, the real reasons why I love Ruby are subjective and personal and it’s fine if you feel another way about it!
I think it depends on the background. In my case, English is my second language and I learnt programming in Spanish. So when I see:
I kind of read it literally: "define variable, control condition and make sure it's increased"
While with:
I read as: "print something five times".
It's just like reading some text.
I don't want to mean disrespect to JS because I've worked with it and it's nice but I think Sylwia made a good point.
I started working with ruby about a year ago when I joined a company that was using ruby on rails, I had no prior knowledge in ruby but it only took a few days to get acquainted with the syntax.
Since then I have found so many things in ruby that just amaze me and simplify my life on a daily basis.
It is also worth noting that writings tests in ruby is way easier than in most other languages and I am yet to find a lib in other languages that magically works like search_cop.
TESTS! I forgot about how fun and stress-free testing in Ruby is. Thank you. Maybe this is going to be next blog material.
Do you have any Ruby favorite tricks and tips? Any method(s) that deserve special appreciation?
Time.now.tomorrow
,Time.now.yesterday
, or using.first
,.second
(I remember I told so many people the first time I found this)I took me a bit of time however to grasp the
unless this do that
orreturn this if that
then another statement after this.I still use rails for any new projects I create
DATES. That's another one that I forgot — and such an easy one to contrast with JS:
It's interesting that you mention this syntax as baffling for you:
For me this is the specific feature that felt like I'm playing with lego. When I later learned JS, I've developed a strong preference for refactoring if/else statements this way as well and literally everyone compliments me on this :D I wish all JS devs were trained in Ruby first so they'd write less of a spaghetti code.
It took me a while to grasp it but once I understood it I really loved it. Thanks for the article it looks interesting.
To be honest I tried to get into Ruby many years ago and didn't click with it. Surprisingly I am really enjoying Elixir though that is supposed to have some similar syntax. PHP, JS and C# always came more naturally to me than Ruby. Just an opinion...
I’ve heard amazing things about Elixir and I’m curious to check it out!
Different things click for different folks ¯_(ツ)_/¯
Great post. It's definitely wonderful having a variety of programming languages and Ruby has certainly had an impact. Rails also pushed web development forward a notch or two as well.
Sadly, I'm here representing the evil empire and their offspring, C#. While opinions abound, I think there is an excellent argument for it being one of the best languages ever written. It is constantly changing and making my job easier and more fun.
Regardless of whether it's Ruby or C#, at least we found something that brings us joy. That's a win for everyone.
I agree! I would love to one day learn some C# but now I’ve just taken up Go (and next will be laravel following the recommendations of the folks in this thread).
I have been writing some JS and a lot of Python due to company preferences, I keep wanting to go back to ruby everytime something is overly complicated.
however my levels of overly complicated are now quite sensible because of Ruby, ruby truly cares about you as a rubyist and your happiness and makes so much things easier, I really like that about Ruby.
I miss ruby.
Also, you made me look up the 10xEngineer again, I got angry, I might write some ruby to feel happy again.
I love this comment! You made me laugh 😂
^ that is soooo relatable. I also work a lot with other languages and frameworks and Ruby projects always feel like a safe happy place I can come and breathe. In the darkest moments when debugging the spaghetti code, just think about Ruby 💖
😂 This brought to my mind the Italian commercial "Ti piace vincere facile" (it is not 100% correct Italian, quite similar to "You like to win easy," error included).
Thank you for this! I just watched this commercial 😂
The syntax. It's so beautiful... I've used many languages over the years and none is easier to read than Ruby, that's just so important when you have to debug other people's code. I started learning Ruby because of college project using Rails like 10 years ago and it's been my preferred framework for web apps and APIs.
Wow! If only I came across rails 10 years ago! I’m happy that you got a decade of kindness ✨
Thank you for this wholesome message
Some comments may only be visible to logged-in visitors. Sign in to view all comments.