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 :
- Higher-Order Functions : Both Python and Ruby feature higher-order functions which represented as objects. Python uses lambda expressions while Ruby usesprocedure objects.
- Arrays and hashes : Ruby supports Arrays and associative arrays (Hash). Python has Lists and Tuples which are the same as arrays.
- Memory management : Ruby has a mark and sweep garbage collector, while Python has a reference counting garbage collector.
- 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.
- Regular expressions:Â Python has support for regular expression through a library object, Ruby has extensive regular expression support.
- Exception handling : Both languages support exception handling like in Java.
- Package support : Python has package support, Ruby does not.
- Serialization: Both languages support serialization.
- Portability: Both languages are portable across most platforms.
- Libraries : Both Ruby and Python have extensive built-in libraries, butÂ Python has edge over Ruby.
- 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 .
Latest posts by Content Team (see all)
- IndicThreads Pune 2016 To Equip Developers For A New Age Of Software Development - May 27, 2016
- Java Garbage Collectors – Moving to Garbage First (G1) Collector - May 25, 2016
- Using Lambdas and Streams in Java 8 - May 18, 2016