Is it hard to switch between Python and Ruby? - Questers

Is it hard to switch between Python and Ruby?

As we celebrate the 27th anniversary of the first release of Ruby, we publish an insightful article about how hard it is to switch from Python to Ruby. Our special guest author is our colleague Alexander Lazarov, Software Engineer at Funding Circle’s team at Questers, who has shared his personal experience with shifting from Python to Ruby. Read on what he shared:

Alexander LazarovWithin the dynamic IT sector, it is important for a software engineer to be flexible and be able to quickly learn new technologies. However, it is not very easy to keep up with all the different packages and modules and even syntax differences. That’s why most programmers usually specialise in just one or two programming languages, learning and exploring all the opportunities the chosen language is giving them. If you have decided to explore Python or Ruby, I’ll try to make a quick overview of the differences and similarities between the two languages, as well as share my experience so far in switching from the first to the second one.

If you are reading this article, I assume you have some basic knowledge of Python and Ruby and what are they most powerful to be used for. So, let’s get to the question of the article - is it difficult to switch between Python and Ruby? Should you have some experience with Python and have been writing in several other languages through the years (just like me), Ruby may not seem that hard to swallow, but still, it may be quite the challenge. What makes switching harder or easier is the differences between the languages. In other words, the bigger the difference – the bigger the challenge.

Python and Ruby are tremendously good examples of that. A widely accepted opinion is that the two languages are very similar, with simple syntax and sharing a lot of common characteristics – they are both cross-platform, high-level scripting languages, both of them are dynamically typed, and, of course, they both support object-oriented programming. Also, the two languages are a good option for building a web application, but it’s not their sole purpose, and they can be used for a wide range of projects.

But are they really that similar? From my experience with both of them, I think this is as much right as it is not. Yes, their syntax is simple and similar, but there are features which differ and may easily confuse a person who reads through the code’s logic. They, indeed, share a lot of common characteristics, but there are some differences as well.

For example, the Ruby method may return a value without a return statement. This is something that cannot be done in Python without a return or yield statement.

Another interesting aspect to mention is the ability to develop web applications. Yes, both languages are suitable for building web apps, and both languages have great frameworks for this purpose (Django for Python and Ruby on Rails for Ruby), but again, the devil is in the details. Django is using the MVT model, while RoR is using MVC. A little explanation for those who may not be familiar with the models: The MVC has a controller that drives both model and view. Also, the view defines how the user data will be presented, and we have to write the control-specific code. The MVT, on the other hand, has views for receiving HTTP requests and returning HTTP responses, the templates define how the user data will be presented and the control part is handled by the framework. This leads to a slight difference in the structure of the projects, and you may need to pay a little bit more attention at the beginning.

Other key differences between the two languages are the inheritance, support of lambda functions and structuring. What do I mean by those? Regarding inheritance, Python supports multiple inheritances, while Ruby only a single inheritance. The support of lambdas illustrates the fact that Python supports only one-line lambda functions, while Ruby supports larger ones. And with regards to the structuring - Ruby has methods and Python has functions.

As I mentioned earlier, both languages may support a wide range of projects, but they tend to be used for different purposes. While Python is better geared for AI, machine learning, data science, etc., Ruby is more suitable for functional programming and web development.

When I started at Funding Circle and had to switch to Ruby, my main focus was getting used to the Ruby syntax. This was needed, but it was the wrong approach because I didn’t get a broader look at the language. The logic might be similar, but still, the differences are there.

A quick example to support this statement is the use of the parameter “self”. In Python, “self” refers to the object itself, while in Ruby “self” may also refer to the parent class, depending on its position inside the code and the methods. And I learned that not long ago! Imagine my confusion while reading the code. As I’m not that experienced with Django particularly, learning the Rails framework was simultaneously new and not new to me. When I started working on my first web task, I was going around the Rails structure for quite some time until I started getting used to it.

In conclusion, I’d say the following - Python and Ruby are both powerful languages with similar features, but the transition between them shouldn’t be taken lightly and you should pay attention to the details. If you already know one of them and you’re wondering if you should learn the other, my advice is to do it! It will give you a different perspective and develop your coding skills.


Interested in switching to Ruby? Check out our career opportunities with this programming language here.