Python vs Ruby

From WikiVS, the open comparison website

Jump to: navigation, search
Python Ruby
Python
VS
Ruby
http://www.python.org http://www.ruby-lang.org

Python and Ruby are the two most popular dynamic programming languages used in high level application development. Developers often prototype using these two languages before implementing on compiled languages because of their modularity and object oriented features. Many use Python or Ruby instead of Perl as simple scripting languages. Python and Ruby are popular among web developers as well because of their rapid development cycle.

Contents

[edit] Philosophy

Python has been designed to emphasize programmer productivity and code readability. Python enforces correct indentation; in fact, indentation has semantic meaning in Python.

Ruby was designed, first and foremost, to make programming fun for its creator, with The Principle of Least Surprise and There's more than one way to do the same thing as guiding concepts:

Ruby inherited the Perl philosophy of having more than one way to do the same thing.

Yukihiro Matsumoto (Matz) , The Philosophy of Ruby

This principle is the reason why many ruby methods have multiple names.

Python rejects the principle of There's more than one way to do the same thing. Instead it was designed with There should be one-- and preferably only one --obvious way to do it.

[edit] Object Oriented Programming

Both Python and Ruby support object oriented programming. In Ruby, even global variables are actually embedded within the ObjectSpace object. Python doesn't have global variables, instead using attributes of module objects.

In Ruby, an instance of literally any type is an object. The same is true for Python. However, where in Ruby all functions and most operators are in fact methods, a number of Python functions are procedural functions rather than methods.


[edit] Functional Programming

Both support some functional programming constructs, but Ruby is arguably better suited to a functional programming style. Where Ruby offers highly flexible lambda handling, Python's lambdas are restricted to a single line of code; because every statement in Ruby is an expression, every statement has a return value; Ruby supports a nontrivial subset of Lisp-style macro capabilities; while Python's closure support is more limited than Ruby's thanks to its limited support for lexical scope.

On the other hand, as of version 1.8 -- the current stable release -- Ruby does not support tail-call optimization for recursive functions, whereas Python uses a decorator to implement tail-call optimization. Ruby 1.9, a development version that is scheduled to become the stable 2.0 release version soon, can currently be compiled to support tail-call optimization.

[edit] Speed

Python is generally regarded as executing code slightly faster than Ruby, as of Ruby version 1.8. This can be attributed in part to the fact that Python can be compiled into "bytecode" (.pyc) before the code is run. However, major speed improvements have been made to Ruby 1.9, rendering the difference negligible -- and some benchmarks actually show Ruby 1.9 performing better than Python's 3.0 beta.

Newer generation ruby parsers are working on improving Ruby's speed. The currently planned parser YARV is actually a VM that can also be used to execute precompiled bytecode.

[edit] Popularity

Python is generally more widely used than Ruby, according to most measures, but in the wake of the rising popularity of the Ruby on Rails Web application development framework Ruby's popularity too has seen rapid growth. In recent years, the number of Ruby-related books in bookstores has climbed rapidly, from a mere handful to dozens.

[edit] Links

Personal tools