Source: unsplash.com

Unlearn programming to learn Ruby

Why is the Ruby philosophy the exact opposite of other programming languages?

Tech - RubyCademy
Published in
3 min readOct 7, 2019

--

Introduction

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

The language is very permissive

Indeed, most 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.

Ok. 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 follows:

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 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 to a given program to respond to certain constraints imposed by the programming language.

So this adds layers between the developer's thoughts, the code, and the final program. On the 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 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'

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

Feel free to let a comment to share your way to express this need!

Conclusion

Ruby is a different programming language. The Core team genuinely believes in developer happiness. It allows you to express your thoughts as close as possible to human language.

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

You don’t have as many constraints as most programming languages. So take advantage of what Ruby gives you!

Ruby Mastery

We’re currently finalizing our first online course: Ruby Mastery.

Join the list for an exclusive release alert! 🔔

🔗 Ruby Mastery by RubyCademy

Also, you can follow us on x.com as we’re very active on this platform. Indeed, we post elaborate code examples every day.

💚

--

--