Unlearn programming to learn Ruby - Mehdi Farsi

By Mehdi Farsi

Source: unsplash.com
Mehdi Farsi

Ruby is a different programming language for at least 2 reasons:

The language is very permissive

Indeed, most of the languages are restrictive.

They create constraints for developers for their “safety”.

On the other hand, Ruby is a permissive language backed by a set of design principles (duck typing, etc..).

The decision to follow these design principles (or not) is the responsibility of the developer.

The vocabulary of the language is human-friendly

In most programming languages, the language is seen as an intermediary between the machine and the developer

In Ruby, the language is apprehended as a way for the developer to express ideas in a human-friendly way — The famous Developer Happiness first adage.


So, how about slightly reshaping your way of thinking when using Ruby to enable your full potential?

The way Ruby responds to a problem

When the Ruby Core Team implements a feature, it’s always focused on developer usability.

That’s why the language seems so natural to use

list_cart unless @cart.include? 'pineapple'

Here, we can read this code as following:

List the content of the cart unless the cart includes a pineapple.

In this statement, Ruby provides 3 tools:

  • the unless keyword
  • the one-liner syntax
  • the include? method

All these tools can be combined together to provide a natural syntax close to what your mind can express to solve this problem.

I guess you get the point here.

So, why do we need to unlearn programming to learn Ruby?

Learn to unlearn programming

The sentence is exaggerated..

You don’t need to “unlearn” programming.

Because Ruby implements all the tools and concepts of CompSci.

Here, I want more to talk about learning to “think” like a Rubyist and not like a developer.

In general, a developer adapts his way of thinking a given program to respond to certain constraints imposed by the programming language.

So this adds layers between the developer thoughts, the code and the final program.

In contrary, Ruby tends to remove the barrier between developer thoughts and the code.


Now let’s see how to reshape your way of thinking.

To to do so, there is a simple exercise that you can quickly implement:

Try to transcribe your thoughts in Ruby code.

For example, how would you write the code for the following need in Ruby?

When the user receives a message then we send an email to this user.

Another way to express this need

Send an email to the user if the user receives a message.

Keep your focus on the statement — and not the methods and objects you need to define for this statement.

For example, here I didn’t define list_cart and @cart in the above section.

list_cart unless @cart.include? 'pineapple'

In another time, you’ll implement what you need to make this sentence understandable by your computer.

I’d love to learn from your way to implement the above need.

So feel free to let a comment to share your way to express this need.


Ruby is a different programming language.

The Core team genuinely believes in developer happiness.

It helps you to express your thoughts as close as possible of human language.

That’s why you should tend to learn and use the tools provided by the language as much as possible to transcribe you thought in Ruby code.

You don’t have so much constraints like most of the languages.

So take advantage of what Ruby gives you!