Python Programming Portal
Python Programming Portal
J2EE curve
Add Site Feed
Python vs Ruby PDF Print E-mail
Written by Sandeep Gohad   
Thursday, 29 September 2005

According to  Brian, Python programs run faster than Ruby. He tried to implement the Edit-Distance algorithm in three different ways in both Python and in Ruby and he conclude that the python is very much faster than Ruby. Lets see  the comparison.


Python and Ruby are both object oriented languages that provide a smooth transition from procedural to OO programming styles.Both languages are high level, GarbageCollected, and DynamicallyTyped. Both provide an interactive shell, standard libraries, and persistence support. Lets compare them.

  • Introduction :

Python is an object-oriented interpreted scripting language started in 1990 essentially for distributed systems management tasks.It qickly became popular for a wide range of programming tasks. It became more popular in 1995 because of its web related programs. It's design in the most general sense  and has borrowed ideas from scripting languages like Perl and Tcl also from object oriented languages like C++ and Smalltalk with hints of functional languages like LISP.

Ruby is a relatively new programming language, though it was created in 1995 in Japan. It is an interpreted, scripting, pure object-oriented language. It is heavily based on Perl , infact its more powerful than Perl and more objectoriented than Python. It mainly focuses on its design that is object-oriented programming The syntax was inspired by Ada, and there are lots of features borrowed from object-oriented language like Smalltalk.

  • OO :

There has been much debate if Python is truly a pure object oriented language. Python is a pure object oriented language as every variable is a reference to an object. Python allows both procedural and object oriented designs. It is possible to write functions in addition to methods. The programmer is required to use functions because there is much built-in functionality in python.

Ruby is pure object oriented language . In Ruby everything is an object. There are no built-in types like int in Java. The part which is different from Python is the fact that all operations are messages to objects. that is there are no functions, only methods.

  • Inheritance :

Python's inheritance model allows for multiple inheritance.

Ruby features single inheritance only. For multiple inheritance, Ruby has the concept of modules.
(similar to interfaces in Java)

  • Access Protection :

Python initially had no access protection, a mechanism has been added called name mangling which renames class members starting with \ " (two underscores) to\ ". Thus references to members outside the class cannot get the same mangled names.

Ruby supports private, protected and public types of access (like java)to the elements of a class. By default all methods are public except the initialize method and all instance variables are private.

  • Dynamic Typing :

In both Ruby and Python, all types are dynamic. So there is no need to give types to variables when you initialize them and no question of declaring variables. The disadvantage of dynamic typing is that the compiler cannot statically check whether there will be typing errors in the program, which could result in errors at run-time.

  • Syntax :

Both Python and Ruby were designed from the ground up as simple scripting languages, both are very comparable in syntactic simplicity.
One of the main advantages of Ruby is the simplicity and readability of its syntax. Ruby code is far less cryptic than python.

  • Features :
  1. Higher-Order Functions : Both Python and Ruby feature higher-order functions which represented as objects. Python uses lambda expressions while Ruby usesprocedure objects.
  2. Arrays and hashes : Ruby supports Arrays and associative arrays (Hash). Python has Lists and Tuples which are the same as arrays.
  3. Memory management : Ruby has a mark and sweep garbage collector, while Python has a reference counting garbage collector.
  4. Parallel assignment : Threading is optional in python but available on many common platforms with some threading support. Ruby claims to do Operating System independent threading.
  5. Regular expressions: Python has support for regular expression through a library object, Ruby has extensive regular expression support.
  6. Exception handling : Both languages support exception handling like in Java.
  7. Package support : Python has package support, Ruby does not.
  8. Serialization: Both languages support serialization.
  9. Portability: Both languages are portable across most platforms.
  10. Libraries : Both Ruby and Python have extensive built-in libraries, but Python has edge over Ruby.
  11. Documentation : Both languages allow you to generate automatic documentations.

Overall There is not much difference between Ruby and Python.
But I think The advantage of Python is that there are a lot of libraries readily available , which are not so readily available for Ruby also Ruby is not properly documented compared to Python. Both languages have nice features, which one to choose is your decision .

Reference:
>>A Ruby a day!
>>The Python Reference Manual
>>Ruby : The Pragmatic Programmer's Guide

Comments

You must javascript enabled to use this form

'Ruby code is far less cryptic than python.'

What? Really wtf?

ruby uses @ @@ < other punction 'line noize' there are lots of optional things like parens around function calls, default to using $_, multiple ways to define blocks, it requires an extra line 'end' to close most blocks, it also seems to use lots of abbreviations

The Python mantra there is one obvious way to do it (which is followed fairly well) makes it one of the least cryptic, most readable syntaxes out there.

Ruby is far better than perl or c. But Python and Ruby are comparable or if anything Python is slightly more readable/less cryptic than ruby.

Posted by norm, on 04/17/2007 at 23:04

nice comparison but Hey, you have not covered

Posted by Pratap, on 11/24/2005 at 12:54

I keep meaning to get into Ruby but I rarely have the time these days.
Incidentally I've made a Python IDE review you may be interested in seeing. You can get to it via my blog or directly here:
blog.straw-dogs.co.uk/python-ide-review

Posted by Straw Dogs Python Blog, whose homepage is here on 10/03/2005 at 07:28

I think Python is a better choice. Ruby is growing more aggressively compared to python, Python needs some strong backing from giants like IBM, Oracle, although Google, Yahoo use python a lot in their search engines, programs etc, but they are not contributing much for the promotion of the language.

Posted by Ram, on 09/30/2005 at 03:37

 1 
Page 1 of 1 ( 4 Comments )
©2007 MosCom

You are not authorized to leave comments. Please login first.

Add Python Site Feed
Latest
Popular
Go to top of page  Home | Content | Resources | Contact Us | Blogs |

Copyright 2004 Rightrix Solutions. All rights reserved. All product names are trademarks of their respective companies.
Views expressed at PythonThreads.com reflect the views of the authors alone, and do not necessarily reflect those of PythonThreads.com.

Terms of Use          Privacy Policy
PythonThreads.com - Python Programming Language Portal