Python vs Ruby

TL;DR: I like python (mostly because I’m fairly proficient with it) but have a lot of respect for ruby.  However, the two languages are actually really similar at lower levels.

This might be a less typical “vs” article.  Really, I don’t enjoy language wars.  I believe that each language is a tool that solves particular problems well.  There are also some higher level things to consider like the value of consistency in a project meaning that if a project has 95% of it’s code in <insert horribly offensive programming language>, then writing the remaining 5% in <insert programming language of choice> actually clashes with the rest of the project, making the code difficult to support.  So, here is my pros/cons list for ruby and python as of this date (technology changes fast, so these could be wrong by the time I’m done posting).

 Python

ProsCons
PEP8:
Style guide compliance ensures similar coding styles, which makes it easier to read
Python3:
Massive/fundamental change is hard. Python 3 is having a hard time getting a foot hold.
White space:
Using white space for code blocks is pretty natural and easy for editors to assist with
White space:
Using white space for code blocks can make spotting start/end of code blocks less obvious to the human eye
PIP/easy_install:
Easy method for obtaining code shared with the community
PIP/easy_install:
Having a Sys Admin background, I despise multiple package managers.

Ruby

ProsCons
rspec:
Python has unittest, but I find rspec to be more user friendly (possibly due to lack of experience).
Style guide:
There really are no tools for programmatically checking style guide.
White space:
Using white space for code blocks is pretty natural and easy for editors to assist with
White space:
Using white space for code blocks can make spotting start/end of code blocks less obvious to the human eye
gems:
Easy method for obtaining code shared with the community
gems:
Having a Sys Admin background, I despise multiple package managers.
Ruby on Rails:
Having supported Ruby-on-Rails, I know how horrible it is (was?).

Conclusion

As it is pretty apparent, both languages really are pretty similar.  So similar, in fact, that if you take the bytecode of each interpreter, you can reconstruct the code in the opposite language.  Given the animosity I’ve seen in chat rooms, hallway conversations, and various comments on webpages, it is fitting to call this act of crossover unholy.

Obviously, there are a lot of things I did not cover (quantity of libraries available, quality of libraries, overall adoption of language, career opportunities for each language, etc.).  The items above are the key things that are effecting my decision today to lean towards python instead of ruby, given everything else is equal.  That being said, I find myself being thrown into ruby pretty deep with projects like puppet and vagrant being at the center of my world these days.

Closing Thought

When all you have is a hammer, every problem is a nail.  But when you have a full arsenal of tools, you can get stuck in analysis paralysis trying to decide what tool to use to solve the problem.  I’d much rather have more tools in my toolbox than I know what to do with than to not have the required tools when I need them.  Probably time to learn some more languages (like go or C++).

2 thoughts on “Python vs Ruby

  1. I’d disagree that Ruby doesn’t have a style guide.

    Rubocop (https://github.com/bbatsov/rubocop), for example, serves as a great tool to analyze the code you’ve written and its based on the Ruby community style guide. Sure the language doesn’t enforce the style, and that flexibility shows with Rubocop (turning off and on certain ‘cops’), but its a tool none-the-less.

  2. Thanks for the link Yvo. I was unaware of Rubocop. It seems like the style guide compliance is more baked into Python than Ruby (for better or worse). I’ll definitely be playing with Rubocop on my next ruby project!

Comments are closed.