1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

How Does Ruby Compare to Python?

By

Ruby vs. Python

Python and Ruby are quite similar both in their object oriented features and their uses. Both are heavily object oriented; you can't do much in either Python or Ruby without dealing with objects and classes.

Though Ruby's object oriented view is thought of as more "pure," the differences are often of semantics rather than anything practical. The real differences between Python and Ruby lie in how they are executed and their syntax. Ruby is an interpreted language. Python compiles code to a virtual machine language much like Java, making it more efficient than Ruby.

Closing the Gap

However, the gap between the two languages is closing in this respect; future versions of Ruby will be executed on a virtual machine. In fact, the soon-to-be-released Ruby version 1.9 will use a virtual machine compiler. Currently, though, there are only alternative Ruby virtual machines available, such as JRuby (which runs on the Java virtual machine).

Python's Strict Syntax

The most striking difference between Ruby and Python is the syntax. The philosophies behind the Python and Ruby syntaxes are quite different. Python tries to make everything as clear and regular looking as possible. That strive for clarity means that symbols are avoided wherever possible (for example, variable names won't have $ or % symbols before them) and you are limited to one statement of code per line.

These rigid restrictions on syntax make all Python code look the same. Two different programs created by two different Python programmers will look almost identical because there is often only one way to arrange the code.

Ruby's Stance on Syntax

Ruby's stance on syntax, however, is much more similar to Perl's than to Python's. The syntax is very free, allowing you to put multiple statements on the same line and letting you indent your code however you like. Though this can lead to some messy looking code, that can easily be avoided by careful arrangement.

  1. About.com
  2. Technology
  3. Ruby
  4. Beginning Ruby
  5. How Does Ruby Compare to Python? - Ruby vs Python

©2014 About.com. All rights reserved.