Ruby vs Python: In-Depth Comparison for web development in 2018

Igor Zats
Igor Zats
Technical Writer

Let's talk about two different programming languages. “Which one is better?” you'll hear this question time by time. So we are going to make as a straight answer as it possible. Both of these languages have their own pros and cons. If you are not familiar with Python or Ruby, it will be nearly impossible to choose the best one for you. If you used both of them a little bit, you can notice where they are similar, and where they are different.

In this article, we are going to highlight and compare Ruby and Python by their functionality, performance capability in accordance with their purposes. But first, a little bit of history!

Table of contents

    What is Ruby?

       Ruby is a programming language that was born in 1993. One of the points of Ruby is that everything (I mean, absolutely everything) is an object. Yes, we know that a lot of programming languages has an object-oriented approach, but their data type is still primitive. Ruby is focused on human, on the way the human cares about programming. Yukihiro Matsumoto (the creator of Ruby) adheres his own philosophy, where the language is a tool for people and should be designed for them to use.  These languages can be used for general purposes and it fits a lot of industries.

    Advantages and disadvantages of Ruby

    So why may you prefer Ruby? This programming language provides you with a great combination of well-made toolkits, uncompromising code libraries and a pretty pragmatic approach to development. Furthermore, the community basically consists of experienced software engineers that prefer qualitative development, which is frequently has been seen in other communities.

    Let’s check figure out the best qualities of Ruby:

    • Libraries. As a Ruby user, you have access to the third-party module called gem, and this module can bring you anything you can think about. All these libraries are available for free on rubygems.org.

    • Community. We can safely say that there is at least one Ruby community in every city around the world.

    • Tools. Ruby opens a great toolkit that will help you to provide more features in a short time. Ruby comes with a classic structure for web applications, so each common pattern is dedicated for you.

    • Qualitativecode. If you take a look at NodeJS or PHP equivalents of third-party code, you’ll notice that Ruby code is spectacularly higher.

    • Productive. This language is pretty succinct, and if you combine this to the army of third-party libraries and you’ll get numerous development features for free almost instantly. We can safely say that Ruby is the most productive programming language.

    • Good for test automation. The community is big enough for test automation, in our opinion it is very valuable when it comes to the delivery of qualitative software and Ruby libraries helping a lot.

    It’s not a secret that every programming language contains its own disadvantages, let’s learn about Ruby’s case:

    • Poor documentation. You may find some difficulties while looking for a comprehensive documentation. Especially when you are looking for a documentation related to less popular gems or libraries with mixins issues (which is common for Rails).

    • Multithreading.  Despite the fact that Ruby supports multithreading, some of its I/O libraries are don’t because they are using Global Interpreter Lock. In other words, you have to be careful, otherwise, you’ll get queued requests up behind your current requests, which may cause a lot of performance issues.

    • Runtime Speed. This is the strongest argument against Ruby that can be considered as a slow programming language. It is hard to disagree, especially if you compare runtime speed with GoLang or NodeJS.

    • ActiveRecord. It is heavily used in the RoR world but it depends on a lot of ruby gems. In our opinion, ActiveRecord is a great design pattern but the biggest disadvantage that we can see is that the domain will be densely associated to the persistence mechanism. Such an environment can lead to really bad architecture decisions.

    • Boot Speed. The boot speed of framework could become a nuisance for a developer that works with Rails. Including the number of files and dependencies, it is not so hard to imagine the amount of time needed to start. Recent versions of Ruby on Rails somewhat fixed this problem with the Spring, though.

    Famous Ruby websites

    • GitHub

    • Airbnb

    • Kickstarter

    • Basecamp

    What is Python Used For

    The first implementation of Python was born in 1989 in the Netherlands by Guido van Rossum.

    If you have a suspicion about the name: yes, it was named for the famous British TV show Monty Python. This programming language is open source. Python has an impressive community and developing not the least because of it. People were appreciated for the job that van Rossum did and he was elected as a dictator of Python forever.

        Python is not that object-oriented as Ruby, but still can be. The motto is “A simple thing is better than a complex thing. A complex thing is better than a complicated thing”. It uses the whitespace in order to control the flow in your program. This could be actually useful and significant: if things can be indented in different ways, their meaning in a program will be also different. You can understand the logic of a program that was written in Python and what is going on with a single look if you understand the structure.

    Advantages and disadvantages of Python

    Let’s figure out why you should use Python and why it is cool:

    • It is extensible. Python can be extended to a variety of languages. For example, you can write a block of your code in C or C++, which is pretty handy when it is needed for your project.

    • Libraries. Python comes with an extensive library. This means that the library contains code for different purposes like documentation, regular expressions, databases, email, threading, web browsers, CGI, image manipulation and so on. As a programmer, you don’t have to write the new code manually for these purposes.

    • It is productive. The fact that Python is simple and comes with extensive libraries makes Python programmer is at least a bit more productive than those who work with C++ or Java.

    • Internet of Things and related opportunities.  Python runs such platforms like RaspberryPi and it definitely has the bright future for the Internet of Things.

    • Simplicity. While working with languages like Java, you have to create a whole class just to print “Hello World”. You can do this only with a print statement in Python.

    Well, looks like Python is a great choice, but what about its notable drawbacks?

    • Design Restrictions. We know that Python is dynamically typed programming language. In other words, you don’t have to declare the type of each variable when you write the code. Python uses duck-typing, which means that if something looks like a duck, acts like a duck, it must be a duck, eventually. But it can lead to runtime errors, though.

    • Speed limitations. As we know, Python code can be executed line by line. But since it is interpreted it can lead to slow execution, which is not necessarily a big problem, though, except the case where speed is important for your project.

    • Redundant simplicity. It’s not a joke. Such simplicity can become a problem. For example, if you switch to Java after years with Python, you’ll see that Java’s verbosity is unnecessary.

    • Browser and mobile computing drawbacks. Despite the fact that Python is a brilliant server-side programming language, you can barely see it on the client-side of the project as well as on the smartphone-based apps. For example, you can check out the application called Carbonelle, which is built with Python.

    • Weak database access layers. Python’s database access layers are weaker than Open Database Connectivity and Java Database Connectivity due to poor development. As a consequence, you’ll rarely see Python’s database access layers in biggest enterprises.

    Famous Python Websites

    • YouTube

    • Google (widely used in a lot of apps)

    • Reddit

    • Instagram

    Ruby vs Python: In-depth Comparison

    Looks like we got to know our rivals and we are ready to proceed with our comparison. There are a lot of criterions related to such areas as web development, data science, market, functional programming, desktop application development and so on. Let’s start with a simple part and figure out similarities and differences between Ruby and Python.

    Similarities & Differences

    As I mentioned before, both of those languages are object-oriented languages. Whenever you use python or ruby, you'll work with standard libraries, stable support, and interactive shell. If you are looking for a language for web development, Ruby and Python are also a brilliant choice. You will feel the magic, especially while working with web frameworks because of Rails for Ruby and Django for Python. The only difference is that Django is more about the scientific (e.g. academic) niche, while Rails is a little bit more popular in web development.

    First of all, notice that these languages are pretty similar but very different in the ways they are solving problems.

    Python always takes a more straightforward way of programming. It was designed in order to make all the stuff as obvious as it possible for the programmer. To achieve this goal, it sacrifices a part of the elegant tone that Ruby has, but as a Python user, you'll have all the benefits when you have to debug some problems or learn to current code.

    Ruby is a very flexible and powerful tool for the programmer. With Ruby on Rails, you can implement tons of tricks that will make your web framework notably elegant. Sometimes its approach will look more intuitively, almost magical. Notice that the flexibility is not always good. Today your code works the way you want in the part where it less expected. That leaves you with a really good impression. But when the situation is opposite and your code doesn't work the way you want in the part where it most expected, you can spend hours tracking down the bugs.

    Let's take a look on a simple example of Fibonacci sequence performance:

    Python:

    Ruby:

     

    Notice: you can write such code in many different ways. Presented methods are true.

     

       This example shows why Python is so Pythonic and why Ruby is so... Ruby. If you focus on the Ruby code, you'll notice that it's hard to read, despite the fact that it is more elegant. At the same time, Python code is quite easy to read and follow!

        Python gives you a wide range of ways to do one thing. What about a simple copying a list? We have at least four approaches to do this:

       

       Remember that in most cases you have the only one right decision. That's all depends on the situation. If you look at the second example, you'll notice that it is easy to read and can be used instantly. However, the latter two snippets are bad: you have to list comprehensions, which is not always readable, and you have to use the additional library.

    Libraries

    Ruby comes with a big number of useful libraries for a wide range of purposes. We'll give them a few minutes:

    1. Better_errors. This is a standard error page that gives you an important information;

    2. Devise. This library will speed up your work with HTTP authentication and let you pick whatever you need;

    3. Cancancan. This is a hidden gem from the neglected project called cancan. With this library you can specify what a user is allowed to do on your website;

    4. Delayed_job. If you need to send a big number of letters to a big number of people, with this library you can extract this job into a background;

    5. Paperclip. With paperclip, you can simplify your work with attachments that have to be processed in different ways.

    Commonly used libraries in Python:

    Python comes with a wide range of useful libraries as well! The most popular of them are:

    1. Requests. The popular HTTP lib. This one is must have for each and every Python developer that allows sending grass-fed and organic HTTP/1.1 requests;

    2. Scrapy. If you are looking the best way to implement webscraping then Scrapy is a must-have library for you;

    3. wxPython. This library is a great alternative to tkinter if you are looking for a great gui toolkit;

    4. SQLAlchemy. This one is a matter of dispute in the world of database libraries. Some people hate it, some people love it;

    5. Pillow. If you are working with images, then this one is the top dog! Pillow is a good fork for the Python Imaging Library and it is more user-friendly.

    As we can see, both languages are unique in their own way, let's take a look at how are they similar and how are they different exactly!

    Open-source projects

    Open source projects can be a very useful tool for a programmer who wants to understand languages advantages and possibilities. Let's take a look at the best Python and Ruby open source projects.

    Python:

    1. Home assistant (v0.6+). This automation platform is written in Python 3 that allows the user to control and track as well as to set up automate control;

    2. Pytorch. Dynamic neural networks and tensors in Python with a great GPU acceleration that is integrated deeply into Python;

    3. Kinto. A simple JSON storage with sharing and synchronization features;

    4. Mailpile. Fast, free, modern, friendly and open email client that comes with privacy and encryption features;

    5. InstaPy. A simple Instagram bot that comes with automation script that hits likes, following and comments.

    Ruby:

    1. GitLab. This is a well-made, friendly platform where programmers can work together and use tons of helpful features;

    2. Discourse. A good alternative to your favorite forum. This discussion platform is also tracking recent updates in real time! The user can easily log in with an account on Google, Twitter, Facebook, etc;

    3. Diaspora. A modern social network that is developed completely by volunteers since 2012;

    4. Spree. A simple and flexible platform with which you can easily set up your own e-shop;

    5. Refinery CMS. A useful CMS with an extendable and modular management system.

    Popularity

    Python has a reputation as a fastest-growing programming language nowadays. Let’s looks at some numbers from high-income countries like Germany, Canada, United Kingdom, and the United States, which traffic makes about 70% of sites like Stack Overflow. There also a lot of contributors from China, Brazil, India, and Russia.

    Python has been growing quickly in the last years. Summer 2017 was the first time, when Python became one of the visited tag on sites like GitHub and Stack Overflow. This language was the most requested within the United Kingdom and the United States and entered the top 2 in most countries (next to JS and Java). This is pretty impressive, because back to 2012, Python even wasn’t in the top 5.

    Such state of affairs can be related to the seasonal nature of Java’s traffic. Due to the fact that it is taught in different undergraduate courses, it rises during the spring and fall and drops in the summer. In the current situation Python can be either overtaken by Java or stay in the lead in autumn 2018 and Python is clearly can be the most popular programming language in the winter of 2018.

    What about Ruby? In accordance with Tiobe index, Ruby has risen to the 9th spot with a 2.744% rating. At the beginning of 2018 int was out ot the top 10 for a few month. For example, in autumn 2017 it was in 13th place. The Tiobe index is based on a special formula that assessing number of searches on one or another programming language in the most used search engines.=

    Ruby benefited because of the framework called Ruby on Rails, so developers can easily build web applications and web pages. However, people keep switching from Ruby to other programming languages (Python is not an exception) after its peak in 2008. The way Ruby become adult is a good sign and a comeback is possible. Despite the fact that it took almost ten years to come back to top 10 list and it was a pretty tough period for Ruby.

    Community

    Both Python and Ruby supported by large communities. There are dozens of thousands of developers who run the communities with global, regional and even local events. Let’s start with Python.

    Most of the members of Python’s community are related to PSF (Python Software Foundation). This is a non-profit community, which mission is to “protect, promote and advance the Python language, to facilitate and support an international and diverse community of Python.” Any person that uses Python and has an interest in its community can join the Python Software Foundation as an active member. The PSF has its own hierarchy of members:

    • Basic member

    • Sponsor member

    • Supporting member

    • Contributing member

    • Managing member

    • and fellows

    Ruby has a growing and vibrant community as well and it is pretty friendly towards users of any skill level. Ruby’s community has several places to start:

    • Newsgroups and mailing lists, where users can get answers on their questions, and get in touch with a huge assortment of lists in several languages.

    • User groups. Your local user group is a great place to communicate with other developers. These groups are well organized and feature monthly meetings on a regular basis.

    • Ruby core. A great place to follow recent development updates.

    • IRC. The IRC channel is a great way to communicate with other developers.

    For Startups

    Startup should grow as fast as possible, while the team will develop a product that can be potentially sold on the market, and this is not a common case for the majority of projects.

    That’s why most startups are tech projects. As an online businessman, you are not limited by space or time, and your customer can use or buy the product anytime they want, and it doesn’t matter where you are from. But that’s not all. There are a lot of different factors that separate startups from other companies, let’s learn about them.

    1. Time. Most of the startups need to make decisions quickly: looking for investors and partners is a key factor.

    2. Budget. At the beginning of the journey, the financial part is especially significant. Those who had an experience in such already know that it’s not so easy to allocate capital for startup and how essential it is.

    3. Profitability. 9 of 10 times startup hope that its product will start to generate profit as fast as possible. Without such a rush, they would not grow nor survive.

    Let’s figure out how Python and Ruby can be handy when it comes to startups:

    1. Python is an innovative programming language. There are a lot of people prefer Python and it is easy to understand why. There a lot of major-league companies like Instagram, Quora, and Google that rely on Python. It’s because Python is a versatile and innovative programming language that allows the user to elevate and scale his service.

    2. Python is a user-friendly language. It is widely used in the software are due to the fact that it is simple and intuitive. Both of these factors are often deciding among startup communities that choose Python as the main programming language.

    3. Python is everywhere. This programming language is widely spread from Youtube to Reddit. Furthermore, its popularity is still growing. As a wise person, you should pick up a programming language that will stay around.

    4. Python is scalable. This aspect is very important for a startup to adapt to the current situation, and your startup should be able to handle such dynamics.

    5. Python and big data. If you want to start a media streaming project or a big social network, you should know that such a project are basically web-based, and as we know, the web is driven by big data. This means that you’ll face difficult and complex processing. Fortunately, Python is well-equipped for such challenges and that’s why it is a good language for beginners.

    What about Ruby? It is known that any startup has its own set of characteristics. Each tech stack should be as powerful as it possible in order to move a startup from “idea” to “implementation” point. Let’s take a look at what we can do with Ruby and why it can be good for a startup.

    1. Security and stability. With Ruby, you are free from glitches and you get a stable performance.

    2. Agile app development. Forget about delays in production and e-mail trails.

    3. Scalable, robust and flexible framework. Ruby on Rails is good for different startups ideas that imply the scalability.

    4. Quick MVP development. You can implement your application easily and test the feasibility.

    5. Robust community. If you have any question, you have thousands of Rubists to ask it.

    Multithreading

    Multithreading, as well as parallel processing, are pretty interesting for this article because they show a notable challenge. Let’s learn about how multithreading works in Ruby and Python and how it will affect a programmer’s decision to pick one or another for a project.

    Both Python and Ruby come with a standard implementation (CPython and MRI), and both of the abuse a GIL (Global Interpreter Lock). This mechanism performs scheduling and time slicing of threads. Let’s figure out how it works: each thread has its own access to the GIL for some time, then does some work, and eventually releases it. At this time, each and every other thread is on the hold r

    Multithreading and parallel processing projects are of special interest to me because they present an Along the way, I learned a bit about how threading works in these languages, and how it may affect a developer's decision to use them for a project.

    In Ruby and Python's standard implementations (MRI and CPython, respectively), the languages make use of a Global Interpreter Lock (GIL). The GIL mechanism performs timeslicing and scheduling of threads. Here's how it works: Each thread has exclusive access to the GIL for a bit of time, does some work, and releases it. Meanwhile, every other thread is on hold, waiting to get a chance to access the GIL. When the GIL is released, a random thread will get to access it and start running.

    There are two major advantages to using this system. The first is that you can write code in these languages that use threading, and it will run on an operating system that does not natively support threading with no modifications needed. The second is that, because only one thread is running at a time, there are no thread safety issues, even when working with a non-thread safe library.

    There are some major downsides, though. The biggest one is that multiple threads will never run at the same time. While your application may look like it is running in parallel, in reality, the process never has more than one thread, and it is just wildly bouncing around within one thread doing different things. This brings us to our second issue, which is speed. You will not see any speed advantage on multicore or multiprocessor machines because only one thread is running at a time; you will see a slowdown due to the context switching costs.

    The use of the GIL makes a threaded application a bad idea in many (if not most) cases. Fortunately, there are options. For one thing, the GIL is not mandated by the language specifications. There are some implementations that do not use the GIL (JRuby and IronRuby, for example). Also, you can easily fall back on the process model that Ruby and Python both support, using the traditional fork/join mechanisms. While it may not be ideal (or possible) to use a different implementation or write your application to rely upon forking, it is good that there are alternatives to make truly parallel programs possible in Ruby and Python.

    Django vs Rails

       As I mentioned above, Django and Rails are built-in web frameworks that help the developer to build web apps. The performance is similar: both of these languages are scripting. Django and Rails have the same concepts that traditional MVC web framework has: database migrations, controllers, views, and models. In other words, they have the same core, but you can implement mentioned features in different ways. You can add some features to your application using tons of provided libraries.

    Ruby or Django: Usage

    Both of these languages are widely used all around the world. Google, Instagram, Mozilla, and National Geographic are big fans of Python. Companies like Twitter, Airbnb, and Apple are giving their preference to Ruby. Python has a lesser web presence with Django than Rails. So if you are mostly digging into web development, Ruby may be the force that you are looking for. Python is a language for your general purposes that comes with tons of tools outside the web that can be used in scientific technologies, statistics, and physics.

    If you look at the rate below, you'll see that in the general selection Python has the 4th place and holds 0.32% of the market, while Ruby holds the only 8th place (0.11%).

    Ranking

    Technology

    Domains

    Market Share

    1

    PHP

    7,284,388

    71.13%

    2

    ASP.NET

    2,750,859

    26.86%

    3

    Java

    45,172

    0.44%

    4

    Python

    32,821

    0.32%

    5

    C#

    30,720

    0.30%

    6

    C++

    24,343

    0.24%

    7

    Perl

    12,746

    0.12%

    8

    Ruby

    11,683

    0.11%

    9

    Objective-C

    7,911

    0.08%

    10

    Scala

    7,817

    0.08%

    Directly or indirectly, this statistics shows us that Python holds 0.22% more market share than Ruby and 21,138 domains more, respectively. Looks like Python has a good market position. But if we take a look from the point of view of frameworks and libraries, the situation is nearly opposite:

    Ranking

    Technology

    Domains

    Market Share

    1

    Bootstrap

    4,170,956

    57.80%

    2

    React

    805,905

    11.17%

    3

    JQuery 1.11.1

    535,329

    7.42%

    4

    AngularJS

    305,791

    4.24%

    5

    JQuery 2.1.1

    265,610

    3.68%

    6

    Ruby on Rails

    256,970

    3.56%

    7

    Raven.js

    136,667

    1.89%

    8

    Laravel

    102,125

    1.42%

    9

    Progress Telerik UI for ASP.NET AJAX

    98,084

    1.36%

    10

    DoubleClick Hosted JavaScript libraries

    90,992

    1.26%

    11

    Slimbox

    61,691

    0.85%

    12

    Django

    53,160

    0.74%

    As we can see, the web framework Ruby on Rails holds 3.56% of the framework market, while Django from Python holds only 0.74%, which is 203,810 domains less!

    Ruby or Python: who is the winner?

       I'm going say it again: it all depends on a specific situation. Ask yourself “What I want to achieve?”, “What is my main goal?”, “What kind of features will help me right now?”. Sometimes you'll want to use Python, sometimes you'll want to use Ruby. However, these languages are based on opposing philosophies as well as their communities. For example, Ruby on Rails is constantly changing and modified, while Python community is a little bit more conservative and prefers stability. In other words, new editions, features, and modifications are added slowly. Furthermore, a lot of new features in Python was originally tested in Ruby!

       The debate keeps going because all the arguments for Ruby and Python are endless and all of them are right. Both of these languages have their own advantages and disadvantages. The only thing that I can say is that Python and Ruby have their own areas, so they are changing in their own way. By and large, it's more about the taste and your own preference. If you want to understand, which one is better for you, try both!

    Conclusion

       The truth is simple: anything you do with Ruby and Rails you can perform in Python's Django. If you understand the semantic core, you'll be able to feel the difference. Try to focus on their area. If you are a web app developer, Ruby on Rails will help you, as well as its community. If you want to build a web app and to learn a programming language for general purposes – try Python. You'll open the world of a Python community that is supported and influenced by a wide range of different industries where Python is used in. Furthermore, you can switch them easily: most of the stuff that you learn in Ruby can be used in Python and vice versa. It works for Rails and  Django too!

     


    Average rating:1of

    Comments

    Leave a comment