CSC/ECE 517 Fall 2009/wiki1a 11 f1,: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 13: | Line 13: | ||
To make methods and instance variables private in Python, one '''always''' needs to write __ in front of the name. In Ruby, instance variables are private by default. Methods defined after the method call private are private. | To make methods and instance variables private in Python, one '''always''' needs to write __ in front of the name. In Ruby, instance variables are private by default. Methods defined after the method call private are private. | ||
===Functions and methods === | |||
There are no separate functions and methods in Ruby; all of them are methods. In Python, there are separate methods and functions as shown in the example below. | |||
Ruby: | |||
<pre> | |||
string = 'Hello world' | |||
puts string.count('o'), string.length # prints 2, 11 | |||
</pre> | |||
Python | |||
<pre> | |||
string = 'Hello world' | |||
print string.count('o'), len(string) # prints 2, 11 – why not string.len()? | |||
</pre> |
Revision as of 04:00, 5 September 2009
Ruby and Python are both scripting languages whose popularity has sky rocketed in recent years. Both languages are High-level, Garbage-collected, and Dynamically-typed. Both provide an interactive shell, standard libraries, and persistence support. So, what are the differences?
Points of comparison:
- Language Features
- Web programming environments
- Features exclusive to each
- Advantages of each over statically typed languages
- Projects environments suited to each
Language Features
Private methods and variables
To make methods and instance variables private in Python, one always needs to write __ in front of the name. In Ruby, instance variables are private by default. Methods defined after the method call private are private.
Functions and methods
There are no separate functions and methods in Ruby; all of them are methods. In Python, there are separate methods and functions as shown in the example below. Ruby:
string = 'Hello world' puts string.count('o'), string.length # prints 2, 11
Python
string = 'Hello world' print string.count('o'), len(string) # prints 2, 11 – why not string.len()?