Python vs. Ruby: Which is best for web development?

These two are similar in some ways but are worlds apart in their approach to solving problems.
550 readers like this.
Top 4 JavaScript code editors

Opensource.com

Python and Ruby are among some of the most popular programming languages for developing websites, web-based apps, and web services.

In many ways, the two languages have a lot in common. Visually they are quite similar, and both provide programmers with high-level, object-oriented coding, an interactive shell, standard libraries, and persistence support. However, Python and Ruby are worlds apart in their approach to solving problems because their syntax and philosophies vary greatly, primarily because of their respective histories.

Which one to implement for web development requires some thought because all languages have strengths and weaknesses and your decision will have consequences.

The basics

Python was developed organically in the scientific space as a prototyping language that easily could be translated into C++ if a prototype worked. This happened long before it was first used for web development. Ruby, on the other hand, became a major player specifically because of web development; the Rails framework extended Ruby's popularity with people developing complex websites.

Which programming language best suits your needs? Here is a quick overview of each language to help you choose:

Approach: one best way vs. human-language

Python

Python takes a direct approach to programming. Its main goal is to make everything obvious to the programmer. In Python, there is only one "best" way to do something. This philosophy has led to a language strict in layout.

Python's core philosophy consists of three key hierarchical principles:

  • Explicit is better than implicit
  • Simple is better than complex
  • Complex is better than complicated

This regimented philosophy results in Python being eminently readable and easy to learn—and why Python is great for beginning coders. Python has a big foothold in introductory programming courses. Its syntax is very simple, with little to remember. Because its code structure is explicit, the developer can easily tell where everything comes from, making it relatively easy to debug.

Python's hierarchy of principles is evident in many aspects of the language. Its use of whitespace to do flow control as a core part of the language syntax differs from most other languages, including Ruby. The way you indent code determines the meaning of its action. This use of whitespace is a prime example of Python's "explicit" philosophy, the shape a Python app takes spells out its logic and how the app will act.

Ruby

In contrast to Python, Ruby focuses on "human-language" programming, and its code reads like a verbal language rather than a machine-based one, which many programmers, both beginners and experts, like. Ruby follows the principle of "least astonishment," and offers myriad ways to do the same thing. These similar methods can have multiple names, which many developers find confusing and frustrating.

Unlike Python, Ruby makes use of "blocks," a first-class object that is treated as a unit within a program. In fact, Ruby takes the concept of OOP (Object-Oriented Programming) to its limit. Everything is an object—even global variables are actually represented within the ObjectSpace object. Classes and modules are themselves objects, and functions and operators are methods of objects. This ability makes Ruby especially powerful, especially when combined with its other primary strength: functional programming and the use of lambdas.

In addition to blocks and functional programming, Ruby provides programmers with many other features, including fragmentation, hashable and unhashable types, and mutable strings.

Ruby's fans find its elegance to be one of its top selling points. At the same time, Ruby's "magical" features and flexibility can make it very hard to track down bugs.

Communities: stability vs. innovation

Although features and coding philosophy are the primary drivers for choosing a given language, the strength of a developer community also plays an important role. Fortunately, both Python and Ruby boast strong communities.

Python

Python's community already includes a large Linux and academic community and therefore offers many academic use cases in both math and science. That support gives the community a stability and diversity that only grows as Python increasingly is used for web development.

Ruby

However, Ruby's community has focused primarily on web development from the get-go. It tends to innovate more quickly than the Python community, but this innovation also causes more things to break. In addition, while it has gotten more diverse, it has yet to reach the level of diversity that Python has.

Final thoughts

For web development, Ruby has Rails and Python has Django. Both are powerful frameworks, so when it comes to web development, you can't go wrong with either language. Your decision will ultimately come down to your level of experience and your philosophical preferences.

If you plan to focus on building web applications, Ruby is popular and flexible. There is a very strong community built upon it and they are always on the bleeding edge of development.

If you are interested in building web applications and would like to learn a language that's used more generally, try Python. You'll get a diverse community and lots of influence and support from the various industries in which it is used.

User profile image.
Tom Radcliffe has over 20 years experience in software development and management in both academia and industry. He is a professional engineer (PEO and APEGBC) and holds a PhD in physics from Queen's University at Kingston. Tom brings a passion for quantitative, data-driven processes to ActiveState.

7 Comments

While the Scientific Python stack is certainly one of the language's most notable features today, it's history in web development is at least as long, with the still popular Plone CMS being based on the Zope object publishing system and the schemaless Zope Object Database, both of which were developed in the late 90's, around the same time as the foundations of the modern Scientific Python stack were starting to come together as Numeric and NumArray (prior to their merger into NumPy).

Dont forget flask.

Huuuu... "Ruby takes the concept of OOP (Object-Oriented Programming) to its limit"... well...

Can you explain where's the limit in Python ? Ever tried type(type) ? Or, type(sys.modules['sys']) ?

I wouldn't say that one of these languages is more OOP than the other !

The author didn't touch on perhaps the most important aspects of web development these days...performance and scalability. For most cloud based solutions either (or any) stack will work fine. But if you have a high traffic service and limited resources...which is better? Neither in my opinion, but it would have been nice to see some performance and scalability comparisons.

> But if you have a high traffic service and limited resources

Some of the RoR developers moved on to work on Elixir and the Phoenix Framework (http://www.phoenixframework.org/) built on it is amazing when it comes to high-demand sites. Long-running tasks, web-sockets, concurrency, all built in and with much of the same productivity benefits of RoR. Definitely worth checking out!

In reply to by chuckie (not verified)

Good overview! Thank you!

PHP

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.