Mattan Griffel Co-founder of One Month. Faculty at Columbia Business School. I write about startups, technology, and philosophy.

Ruby vs. Python: What’s the Difference?

3 min read

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. 

Ruby vs. Python What's the Difference?
Ruby vs. Python What’s the Difference?

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 Language:

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.

Web Frameworks

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.

Community

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.

Usage

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.

RUBYPYTHON
LANGUAGE 
  • More magical
  • Created in 1995 by Yukihiro Matsumoto
  • More Direct
  • Created in 1991 by Guido Van Rossum
PROS
  • Tons of features out of the box for web development
  • Quick to embrace new things
  • Very easy to learn
  • A diverse community with big ties to Linux and academia
CONS
  • Can be very hard to debug at times
  • Often very explicit and inelegant to read
WEB FRAMEWORKS
  • Ruby on Rails-Started in 2005 by David Heinemeier Hansson
  • Django-Started in 2003 by Adrian Holovaty and Simon Willison
COMMUNITY
  • Innovates quicker but causes more things to break
  • Very web focused
  • Very stable and diverse but innovates slower
  • Used widely in academia and Linux
USAGE
  • Apple
  • Twitter
  • Github
  • Airbnb
  • Github
  • Groupon
  • Shopify
  • Google
  • Pinterest
  • YouTube
  • Dropbox
  • National Geographic
  • The Washington Post
Learn to Code Comment Avatar
Mattan Griffel Co-founder of One Month. Faculty at Columbia Business School. I write about startups, technology, and philosophy.

9 Replies to “Ruby vs. Python: What’s the Difference?”

  1. The magic of Ruby is quite cool but when learning a first language it can indeed be confusing. Having a more transparent logical structure is definitely helpful. That being said, I abide and love your conclusion: Rails rocks for web applications!

  2. A lot of Rails’s “magic” goes away when you simply consult the documentation, literally just search for “from_now” and you’ll find the class that defines it: ActiveSupport::Duration. If something seems magic, it’s because you don’t know how it works, learn how it works.

    Choose whatever popular programming things you want, but don’t fall into the trap of feeling like you know better because you read a thinkpiece that jives with your own biases. All of these frameworks have their highs and lows especially so when real people start using what you build with them. Just choose something and BUILD SHIT, fail, improve, fail, try again, learn, learn, learn. There is no magic, there is only work to be done.

    P.S. Don’t work too much, you’ll end up losing your mind one day reading a blog post like this and ranting in the comments like an insane person.

  3. Truly Excellent Post.
    It is really helpful to self learners who learning ruby and python programming languages..
    Thank you for sharing your great knowledge with us.
    Looking forward to your further tips on similar topics Thanks…
    I really appreciate it.

  4. Hello , I like your great and amazing content , if it possible can you give me an advice about ‘ what coding language should i start learning to develop andriod apps like GROUPON APP , and DUOLINGO APP , Thanks in advance , looking forward your reply because it’s valuable for me.

  5. The advice here is quality–learn what suits your projects. I use both on a daily basis. Spend your first 3 years mastering one language, then branch out. Once you know one pretty well, similar languages are easy to pick up.

    That said, I suspect a lot of the Python thumping is irrational–and really just because Google and YouTube use it. And even then, big players are constantly seeking alternatives–like Go. I suspect that because the languages and communities mostly share the same values and principles and their languages mostly share the same use cases. Object-oriented programming, interpreted languages, strong web-development communities. The Ruby people like making things simpler for developers at the cost of learning patterns and creating bugs. The Python people like making everything obvious and as uniformly-written as possible via a standard style guide. The Python way is more inconvenient for startups I’d say, who are trying to get to market as quickly as possible for the least money. The Ruby way is inconvenient for large projects where a few not-well-babysat developers will create some hard-to-find bugs deep within the project. Ruby you definitely need to talk about your own style guide, your own linters or else younger developers and more opinionated developers will wreak havoc.

    Ruby is easier for me to understand and faster for me to write. I think, knowing most humans, it’s objectively faster-to-write to a degree for most use cases. Being super-explicit with everything gets old fast (Python).

    In ruby:
    “`
    ## iterate with index
    ints.each_with_index do |val, idx|
    p(idx + val)
    end

    ## create new array from old
    ints.map { |val| int**2 }
    “`
    In python:
    “`
    ## iterate with index
    for idx, val in enumerate(ints):
    print(idx + val)

    ## create new list from old
    map(lambda val: val**2, ints)
    “`
    In python you’re indicating the types of objects involved in the methods, and you’re preserving the for loop structure in the first case to a degree. But, it’s just uglier. If you read the ruby above, it reads left-to-write as what process your code is actually performing. That said, you know less about what’s happening under the hood in the Ruby case.

    Functions like `str()` and `len()` that are just inexplicably functions and not methods in Python are annoying to me. Dealing with strings in ruby is slightly easier–the heredoc, regex, and interpolation are all less awkward. While there’s more options you have to memorize, enumerables are a step up in ruby. `map`, `each`, `inject`, `collect`, `all?` are super intuitive for common alghorithms in Ruby. The idea of private instance methods, attribute access and smallest interfaces necessary in your classes makes everything a little more sane as well (it answers which information and state can I access on the outside vs the inside?). Class methods and instance methods fit object-oriented programming well and that’s all you’ll use in Ruby. Static methods in python, in their definition, just look super awkward. In Ruby, if `self` is in front of the definition, you’re calling on the class, and if it’s not then you’re calling on an instance. In Python you pass in self for an instance method and you add double-underscore in the front for a static method.

    Indented/white-space-conscious languages are just annoying in my opinion. For what little space you gain back by getting to not write `end`, you have to fill your code with escapes and concatenation everywhere. We all indent, but it’s annoying that we all can’t cut-and-paste code into the interpreter.

    Rails is beyond Django in my view. These web development frameworks are designed to do one thing–lower the cost of development. Rails gets you way further for *most* projects than Django does out of the box. Yes, occasionally you won’t end up using its tools for everything and you’ll have to gut it for some weird API, or your boss wants you to use Angular with it. But for 9/10 web apps it cuts time. Routing in Rails makes REST and HTTP super easy to understand and implement with sanity.

    Often people point to dataframes as a reason to use Python. The flexibility within Ruby hash and array objects can get you a lot of the way there. Admittedly, I use Python mostly because of Pandas, SciPy and iPython. Plus, for the little but of data science I do, Python’s docs are a little bit more filled-out here. That said, Ruby’s SciRuby also adds dataframes among other tools and can pretty much do the same things.

    Both are going to be buggy because of the interpreter and flexibility but both are virtually equally slow.

    If you need speed and don’t have rapidly-scalable resources, then both Ruby and Python will be a bad choice. Use Go or C# or try Crystal. But these two live in the cloud, with easily-scalable resources so speed typically isn’t a problem worth complaining about. Great for an article on benchmarks and algorithms but not an issue in reality.

    They’re both good, but if Ruby gets a stronger data science community then that’s really all that lacks right now.

Leave a Reply

Your email address will not be published. Required fields are marked *