How I abandoned Ruby in favor of Python, working on a backend



An article by Benoit Zen, a software developer at Sqreen, was translated for you. Benoit is working on a backend web service and recently switched from Ruby to Python.

In 2008, when I was still a software developer, my two friends decided to start a company, naming it Feedbooks. Their goal was to create high-quality e-books that any person could quickly find and download (if desired, share with friends). The project was presented to them as a digital samizdat library.

A website that would become the face of a service should have been quick, efficient and easy to manage. At about that time, the Ruby on Rails demo video “How to create a blog in 15 minutes” appeared, after which the founders firmly decided to work with it.

Skillbox recommends: a two-year hands-on course “I am a web developer PRO” .

We remind: for all readers of "Habr" - a discount of 10,000 rubles when recording for any Skillbox course on the promotional code "Habr".


After a few weeks, they needed help, and they turned to me.

Like many developers of my generation, I worked with PHP and Mysql, sometimes even adding my own contribution to open source CMS. In the task, I was all very familiar, except, in fact, Ruby. I had never even heard of him (remember, it’s about 2008, the translator’s note). In general, I started working with Ruby and spent the next ten years with him.

Why Ruby?


The fact is that it is a very expressive language. Its main creator set as its goal to make programmers happy when working with Ruby. And he got his way. Virtually every element here is an object. The Ruby virtual machine translates the syntax into a real instruction. It is constantly improving, so that the generated code gets better with each new version. Ruby is easy to analyze, change something, or even create specialized interfaces.

At its core, Ruby on Rails is a set of DSL and infrastructure for easy creation of model-driven web applications. Today it is especially adapted and good for creating applications in which business logic and modeling will play an important role.

In my Sqreen company, I worked with Ruby on the backend. But then, pretty quickly, the decision came to use Python.

Love Ruby, but switch to Python, why?


First, our backend is a bundle of several services, some of which are open to the world, some - not. The first thing a client sees is a corporate static site that is generated using Jekyll. Then the toolbar opens - this is a dynamic React application. The panel works with a dedicated API, we call it “backend for the external interface”. He is our main.

Initially, it was decided that we would not write APIs in different languages, since we would like them to all correspond to specific business logic and models. In addition, at the very beginning of the journey, we understood that, at least, the backend for agents should be easily scalable in order to support an expanding customer base.

Unfortunately, Rails was too slow. Of course, it is not the only one; there is a mass of microframes for Ruby, including the famous Sinatra.

But we still decided to choose Python. There are two main reasons. First, our management was quite familiar with it, since previously many products were developed in Python. Secondly, we needed deep data analysis, which Ruby does not do very well. And the choice was obvious.

Getting started with Python


At this stage, I had almost no experience with Python - before I wrote on it only small scripts that helped the overall implementation of the project. I had to quickly master everything and accelerate the development of the API, on which we worked. Fortunately, the basic components do not depend on what language you use: HTTP / HTML / JSON / REST - they all remain the same. The ability of applications to communicate with the web at a lower level is implemented in Ruby using Rack . As it turned out, Rack has a lot taken from Python, so it wasn’t very hard to work.

But what about the language? Ruby is an object-oriented language, Python is also object-oriented. But the difference between these two languages ​​is significant. So, Ruby describes blocks using keywords, in Python, spaces are used for this. I had to get used to it, and I prefer the Ruby path from its begin / rescue / end. However, Python allows you to write more efficient code that works quickly.

What did I personally do to quickly understand the Python syntax? The main thing - I started practicing with Python Koans , an open source project that allows you to learn Python by providing more and more complex unit tests.

Python Koans introduces the various features of the language, the documentation is very detailed here.

In addition, I also study the Python documentation - it is extremely complete with this language. The language is divided into modules, each of which is provided with a detailed explanation. It includes the answer why the module exists, what problem it is trying to solve and how to implement all this.

Advice to those who want to go to Python


If you're a Ruby developer who thinks about switching to Python, just do it, you might like it. However, it is necessary to remember that before you begin to open up new opportunities, you will have to learn a lot of features of the language. A good starting point is an interactive tutorial and documentation. In addition, training should be supported by practice, you should immediately begin to implement a real application.
Skillbox recommends:


Also popular now: