Which is better Ruby or Python?
I’ve used both Ruby and Python in my work — and while they’re similar, they’re also different in some critical ways. It’s a popular question, but an important one, so let me example the difference between Ruby and Python.
To set the stage, I first learned web development through Python (and the Python framework called Django). After spending four years building Django apps, I got a job doing Ruby on Rails and expected the transition to be straightforward. That’s when it became clear to me that the two languages and frameworks are very different and it’s not so easy to jump from one to the other.
So…How are they different?
The Ruby on Rails web framework is built using the Ruby programming language while the Django web framework is built using the Python programming language.
This is where many of the differences lay. The two languages are visually similar but are worlds apart in their approaches to solving problems.
Ruby is designed to be infinitely flexible and empowering for programmers. It allows Ruby on Rails to do lots of little tricks to make an elegant web framework. This can feel even magical at times, but the flexibility can also cause some problems. For example, the same magic that makes Ruby work when you don’t expect it to can also make it very hard to track down bugs, resulting in hours of combing through code.
Python takes a more direct approach to programming. Its primary goal is to make everything visible to the programmer. This sacrifices some of the elegance that Ruby has but gives Python a big advantage when it comes to learning to code and debugging problems efficiently.
A great example that shows the difference is working with time in your application. Imagine you want to get the time one month from this very second. Here is how you would do that in both languages:
Ruby require 'active_support/all' new_time = 1.month.from_now
Python from datetime import datetime from dateutil.relativedelta import relativedelta new_time = datetime.now() + relativedelta(months=1)
Notice how Python requires you to import specific functionality from datetime and dateutil libraries. It’s explicit, but that’s great because you can easily tell where everything is coming from.
With the Ruby version, a lot more is hidden behind a curtain. We import some active_support library and now all of a sudden all integers in Ruby have these “.days” and “.from_now” methods. It reads well, but it’s not clear where this functionality came from within active_support. Plus, the idea of patching all integers in the language with new functionality is cool, but it can also cause problems.
Neither approach is right or wrong; they emphasize different things. Ruby showcases the flexibility of the language while Python showcases directness and readability.
Django and Rails are both frameworks that help you to build web applications. They have similar performance because both Ruby and Python are scripting languages. Each framework provides you all the concepts from traditional MVC frameworks like models, views, controllers, and database migrations.
Each framework has differences in how you implement these features, but at the core, they are very similar. Python and Ruby also have many libraries you can use to add features to your web applications as well. Ruby has a repository called Rubygems, and Python has a repository called the Package Index.
Python and Ruby have substantial communities behind them. Each community influences the direction of the language, updates, and the way software is built. However, Python has a much broader community than Ruby does. There are a ton of academic use cases in both math and science where Python has thrived, and it continues to grow because of that momentum. Python is also pre-installed on almost every Linux computer making it the perfect language for use on Linux servers (aka. The most popular servers in the world).
Ruby’s popularity kicked off when Rails came out in 2005. The community proliferated around Rails and has since been incredibly focused on web development. It has also become more diverse, but not near the level of diversity that Python has reached.
Who is using these programming languages? Quite a lot of companies. Both Ruby and Python are widespread in the tech world.
There are many famous websites built with Python including Google, Pinterest, Instagram, National Geographic, Mozilla Firefox, and the Washington Post. Similarly, there are just as many Ruby on Rails website examples. Notable companies using Ruby on Rails including Apple, Twitter, Airbnb, Shopify, Github, and Groupon.
Should I learn Python or Ruby first?
Ruby saw a spike in popularity between 2010-2016, but it seems like the industry is trending towards Python. Here’s one way to help you make a decision: If you already have a specific client, job, or project lined up that requires you to know Ruby, learn Ruby. If not, learn Python first. Keep in mind there is a difference between Python 2 and Python 3. If you’re new to coding then I’d recommend you start with the latest version — Python 3
Conclusion: Ruby vs. Python?
Anything you can do in Ruby on Rails you could also do in Python and Django. Which framework is better isn’t a question of capability. The better question might be: which language is better suited for your or your team?
If you plan on sticking with building web applications, then consider prioritizing Ruby on Rails. The community is good and they are always on the bleeding edge. If you are interested in building web applications but would like to learn a language that’s more widely applicable and proficient with handing data analytics than I’d recommend you learn Python.