<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nutmeg</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nutmeg"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Nutmeg"/>
	<updated>2026-05-06T14:57:26Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17938</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 f1,</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17938"/>
		<updated>2009-09-07T03:12:38Z</updated>

		<summary type="html">&lt;p&gt;Nutmeg: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ruby and Python are both scripting languages whose popularity has sky rocketed in recent years. Both languages are &lt;br /&gt;
[http://en.wikipedia.org/wiki/High_level_language High-Level], [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) Garbage-collected], and [http://en.wikipedia.org/wiki/Dynamically_typed#Dynamic_typing Dynamically-typed]. Both provide an interactive shell, standard libraries, and persistence support. So, what are the differences?&lt;br /&gt;
&lt;br /&gt;
[[Image:svg2raster.png|frame|alt=Puzzle globe logo|Ruby Logo]]&lt;br /&gt;
[[Image:python.png|frame|alt=Puzzle globe logo|Python Logo]]&lt;br /&gt;
&lt;br /&gt;
Points of comparison:&lt;br /&gt;
* Language Features: Ruby vs Python&lt;br /&gt;
* Programming environments&lt;br /&gt;
* Features exclusive to each of Ruby and Python&lt;br /&gt;
* Advantages of Ruby/Python over statically typed languages&lt;br /&gt;
* Project environments suited to each&lt;br /&gt;
&lt;br /&gt;
==Language Features: Ruby vs Python==&lt;br /&gt;
&lt;br /&gt;
===Access Protection ===&lt;br /&gt;
&lt;br /&gt;
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. One of the differences of Ruby compared to Python is that Ruby keeps all of its instance variables completely private to the class and only exposes them through accessor methods (attr_writer, attr_reader, etc).&lt;br /&gt;
&lt;br /&gt;
Python's property descriptors are similar, but come with a tradeoff in the development process. If one begins in Python by using a publicly exposed instance variable and later changes the implementation to use a private instance variable exposed through a property descriptor, code internal to the class may need to be adjusted to use the private variable rather than the public property. Ruby removes this design decision&lt;br /&gt;
&lt;br /&gt;
===Functions and methods ===&lt;br /&gt;
In Ruby, the part which is different from Python is the fact that all operations are messages to objects. There are no separate functions and methods; all of them are methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Python, there are separate methods and functions as shown in the example below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
print string.count('o'), len(string)  # prints 2, 11 – why not string.len()?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby has reference to class in class body ===&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass&lt;br /&gt;
    initialize_magick()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Rubys variant is cleaner, as the magic stuff is done in the class definition, so you see that it’s being done when you look at the class.&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass:&lt;br /&gt;
    pass&lt;br /&gt;
initialize_magick(MyClass)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But it’s really not a big deal, because calling the initialise method after the class or as a decorator is really not a major drawback.&lt;br /&gt;
&lt;br /&gt;
=== Self Reference ===&lt;br /&gt;
In Python, one needs to write ''self'' as the first parameter of a method definition (alike Perl). Furthermore, Python doesn’t  require the variable name to be self. In Ruby, ''self'' is automatically available in a similar fashion as in C++.&lt;br /&gt;
&lt;br /&gt;
Additionally, the method call ''self.method'' can be shortened to ''method'', as ''self'' is the default receiver.&lt;br /&gt;
&lt;br /&gt;
=== Ruby continuations vs Python Generators ===&lt;br /&gt;
&lt;br /&gt;
Continuation is a &amp;quot;pointer&amp;quot; to the current position in your program, including calling stack and all variables. You can reuse that pointer to &amp;quot;go back in time&amp;quot; when needed. Continuations are useful when it comes to ''usecases''.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def loop&lt;br /&gt;
  cont=nil&lt;br /&gt;
  for i in 1..4&lt;br /&gt;
    puts i&lt;br /&gt;
    callcc {|continuation| cont=continuation} if i==2&lt;br /&gt;
  end&lt;br /&gt;
  return cont&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python doesn't support full continuations or even coroutines; instead it supports &amp;quot;generator&amp;quot; functions which create a kind of limited coroutine.&lt;br /&gt;
A generator in python is implemented as a special syntax for creating an instance of an iterator object, which returns the values returned by the &amp;quot;function&amp;quot; definition you provide. Python generators are easy and clean.&lt;br /&gt;
The equivalent code for the above code segment, in python is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from generator_tools import copy_generator&lt;br /&gt;
&lt;br /&gt;
def _callg(generator, generator_copy=None):&lt;br /&gt;
    for _ in generator: # run to the end&lt;br /&gt;
        pass&lt;br /&gt;
    if generator_copy is not None:&lt;br /&gt;
        return lambda: _callg(copy_generator(generator_copy))&lt;br /&gt;
&lt;br /&gt;
def loop(c):&lt;br /&gt;
    c.next() # advance to yield's expression&lt;br /&gt;
    return _callg(c, copy_generator(c))&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    def loop_gen():&lt;br /&gt;
        i = 1&lt;br /&gt;
        while i &amp;lt;= 4:&lt;br /&gt;
            print i&lt;br /&gt;
            if i == 2:&lt;br /&gt;
                yield&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
    c = loop(loop_gen())&lt;br /&gt;
    print(&amp;quot;c:&amp;quot;, c)&lt;br /&gt;
    for _ in range(2):&lt;br /&gt;
        print(&amp;quot;c():&amp;quot;, c())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indentation===&lt;br /&gt;
&lt;br /&gt;
Python uses whitespace indentation, rather than curly braces or keywords, to delimit statement blocks (a feature also known as the off-side rule). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.&lt;br /&gt;
On the other hand, ruby doesn't need any indentation although it can be optionally used for clarity.&lt;br /&gt;
&lt;br /&gt;
=== Other Differences ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby&lt;br /&gt;
!  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Higher-Order Functions&lt;br /&gt;
|  Implemented with procedure objects&lt;br /&gt;
|  Implemented as lambda expressions&lt;br /&gt;
|-&lt;br /&gt;
|  Arrays and hashes&lt;br /&gt;
|  supports Arrays and associative arrays (Hash)&lt;br /&gt;
|  has Lists and Tuples which are the same as arrays.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Memory management&lt;br /&gt;
|  has a mark and sweep garbage collector&lt;br /&gt;
|  has a reference counting garbage collector.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Parallel assignment&lt;br /&gt;
|  claims to do Operating System independent threading.&lt;br /&gt;
|  Threading available on many common platforms with some threading support&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Package support &lt;br /&gt;
| Not available&lt;br /&gt;
| Available&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Programming Environments ==&lt;br /&gt;
&lt;br /&gt;
===Development Environments===&lt;br /&gt;
Both languages provide interactive shells (type &amp;quot;python&amp;quot; or &amp;quot;irb&amp;quot;) and high-level persistence support. Multiple IDEs are available for Python, including GUI debuggers. A gdb-style debugger is available for each language. Python has a RefactoringBrowser, BicycleRepairMan. RubyLanguage now has a [http://www.kmc.gr.jp/proj/rrb/index-en.html RubyRefactoringBrowser]&lt;br /&gt;
&lt;br /&gt;
Both languages are supported by Emacs modes. Python can be used as an elisp replacement - see Pymacs. The current Ruby implementation is closely tied to Unix, making Windows performance and ports to new platforms problematic. There is an EclipseIde for Ruby. RubyCocoa adds support for Ruby to ProjectBuilder/ExCode on MacOsx. &lt;br /&gt;
&lt;br /&gt;
===Web Programming Environments ===&lt;br /&gt;
Both Ruby and Python have a large number of web programming environments/ application frameworks. They are exhaustively listed and compared [http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Python here]. For brevity, we compare ruby's [http://en.wikipedia.org/wiki/Ruby_on_rails Ruby on Rails] with python's [http://en.wikipedia.org/wiki/Django_(web_framework) Django].  The need was to compare two frameworks which were developed independent of each other and not based or influenced on the other. Hence the choice of django was made, as other web python frameworks like pylons and web2py are based  on rails. &lt;br /&gt;
&lt;br /&gt;
Django is a complete Python web application framework while rails is an agile web programming environment built in Ruby which greatly simplifies MVC framework development. Ruby OO programming topics in conjunction with various Rails recipes are considered a much lighter, simpler and faster development experience than other current enterprise frameworks provided today.&lt;br /&gt;
&lt;br /&gt;
The table below compares them.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby on Rails&lt;br /&gt;
!  Django&lt;br /&gt;
|-&lt;br /&gt;
|  Language&lt;br /&gt;
|  Ruby&lt;br /&gt;
|  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Ajax&lt;br /&gt;
|  Prototype, script.aculo.us&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  MVC framework&lt;br /&gt;
|  ActiveRecord, Action Pack&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  MVC Push/Pull&lt;br /&gt;
|  Push&lt;br /&gt;
|  Push 	 	 	 	 	&lt;br /&gt;
|-&lt;br /&gt;
| i18n &amp;amp; l10n?&lt;br /&gt;
| Localization, Plug-in &lt;br /&gt;
| Yes &lt;br /&gt;
|-&lt;br /&gt;
|  ORM&lt;br /&gt;
|  ActiveRecord&lt;br /&gt;
|  Django ORM&lt;br /&gt;
|-&lt;br /&gt;
|  Testing framework(s)&lt;br /&gt;
|  Unit Tests, Functional Tests and Integration Tests&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  DB migration framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  No (plugin exists, might be merged into trunk when more stable and feature complete)&lt;br /&gt;
|-&lt;br /&gt;
|  Security Framework(s)&lt;br /&gt;
|  Plug-in&lt;br /&gt;
|  ACL-based&lt;br /&gt;
|-&lt;br /&gt;
|  Template Framework(s)  &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  Caching Framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  Form Validation Framework(s) &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Features exclusive to each of Ruby and Python==&lt;br /&gt;
&lt;br /&gt;
===Python Advantages===&lt;br /&gt;
* Python has multiple inheritance &lt;br /&gt;
* Python has docstrings : Docstrings makes it possible to attach documentation directly to the classes and methods. That’s a nice documentation plus, and makes things like the Python interpreters ''help()'' function really useful. &lt;br /&gt;
&lt;br /&gt;
===Ruby Advantages===&lt;br /&gt;
* Ruby blocks are much more powerful than Python lambdas and they are integrated pervasively into the language. They also allow interaction between the block and the container.&lt;br /&gt;
* Metaprogramming (modifying classes on the fly) is easier in Ruby than in Python. Interestingly, in the Ruby community this is considered a powerful feature and used frequently, whereas the Python community tends to think of it as a last resort.&lt;br /&gt;
* Ruby is very good at creating domain-specific mini-languages. This is a consequence of the easy metaprogramming and optional parentheses on function calls.&lt;br /&gt;
&lt;br /&gt;
==Advantages of Ruby/Python over statically typed languages==&lt;br /&gt;
&lt;br /&gt;
The term Dynamic language refers to high level programming language that allows the programmer to modify the code during run time. The modifications may include addition of new blocks of code or modifications to objects during execution or changing the type of objects. Statically typed languages such as Java or C# have type checking performed during compile-time as opposed to run-time and an objects type cannot be changed. Programmers should declare the types they intend a method or function to use and the compiler will not permit the programmer to ignore this type. Apart from being dynamically typed, there are many features provided by dynamic languages that aren’t to be found in Static languages. These include blocks and closures, metaprogramming, and unbounded polymorphism and support for multiple programming paradigms. These features lend certain advantages to a dynamic language which are listed below: &lt;br /&gt;
&lt;br /&gt;
===Purely Object Oriented===&lt;br /&gt;
Ruby does not have primitives. everything, including integers are full fledged objects.&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  0.zero?    This evaluates to a true&lt;br /&gt;
  1.zero?    This evaluates to a false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Typed features===&lt;br /&gt;
With Static typing in Java and C#, programmers should declare the types they want a method or function to use while with Ruby you don't declare types for variables or functions. In Ruby objects are strongly and dynamically typed.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int val1=5;&lt;br /&gt;
String value=String.valueOf(val1);&lt;br /&gt;
if(value.equals(&amp;quot;5&amp;quot;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val1=5&lt;br /&gt;
value=str(val1)&lt;br /&gt;
if value == &amp;quot;5&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Verbosity===&lt;br /&gt;
Statically typed languages tend to be more verbose. &lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
BufferedReader file1=new BufferedReader(new FileReader(Filename));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file=open(Filename);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Relaxed syntax===&lt;br /&gt;
Ruby and Python are flexible with respect to syntax. For example,&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat = Cat.new  &lt;br /&gt;
cat = Cat.new()  &lt;br /&gt;
cat = Cat.new();  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===More compact code===&lt;br /&gt;
'''Java''':  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (int i = 0; i &amp;lt; 100; i++) &lt;br /&gt;
{}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
100.times { |i| }  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Default Arguments===&lt;br /&gt;
Ruby and Python allows you to define default values to method arguments while Java does not. &lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def calc_cube(x=2,y=3)&lt;br /&gt;
  val=x**y&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Checked Exceptions ===&lt;br /&gt;
Checked exceptions force every method to deal with (catching or throwing) all exceptions that its child calls or may call.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
If in the program, a method calls run as follows, A1() -&amp;gt; A2() -&amp;gt; A3() -&amp;gt; A4() and if A4() throws an Exception, and it is caught by A1(), then A2(), A3() must also throw the same Exception. &lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
Exceptions propagate upwards and A2() and A3() do not need to throw the Exception. &lt;br /&gt;
===Duck Typing===&lt;br /&gt;
Ruby doesn't care about an object's class, just whether it has a method of the name used in the method call. For this reason, the dynamic approach has earned the name duck typing.&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Duck &lt;br /&gt;
	def sound&lt;br /&gt;
         puts &amp;quot;Quack&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Class Frog&lt;br /&gt;
	def sound&lt;br /&gt;
	 puts &amp;quot;Croak&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def noises(duck)&lt;br /&gt;
 duck.sound&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duckA=Duck.new&lt;br /&gt;
frogB=Frog.new&lt;br /&gt;
&lt;br /&gt;
noises(frogB)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Result''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;Croak&amp;quot; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Environments Suited to Each==&lt;br /&gt;
&lt;br /&gt;
Python is useful for rapid prototyping, web scripting, XML processing, database applications, GUI applications, scientific computations. Python can be used for large and complex software systems. YouTube, for instance, runs mainly on Python, and it is preferred language at organizations including Google, NASA and Industrial Light and Magic. Specialized Python libraries and frameworks exist for scientific programming, data manipulation, Web services, XML interchange and many other things.&lt;br /&gt;
&lt;br /&gt;
Ruby is useful for typical scripting language applications such as text processing and middleware programs. It is suitable for small, ad-hoc scripting tasks that previously may have been solved with Perl. Ruby has first-class regular expressions, which makes text processing scripts easy to write. Ruby is also suitable for larger software systems. It’s most successful application is in the Ruby on Rails web framework. Websites like Twitter and Hulu use the Ruby on Rails web development framework in production environments.&lt;br /&gt;
Ruby can also be used as a high-level API wrapper (or domain-specific language) around some C library. Other uses for Ruby is in test/behavior driven development and when you need to create an &amp;quot;internal&amp;quot; domain-specific language.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[http://ruby.about.com/od/beginningruby/a/WhatIsRuby.htm What Is Ruby?]&lt;br /&gt;
&lt;br /&gt;
*[http://blog.ianbicking.org/ruby-python-power.html Ruby, Python, &amp;quot;Power&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
*[http://python.about.com/od/gettingstarted/ss/whatispython_3.htm What is Python?]&lt;br /&gt;
&lt;br /&gt;
*[http://johan.kiviniemi.name/blag/ruby-vs-python/  Ruby vs. Python Johan Kiviniemi's series of tubes]&lt;br /&gt;
&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby (programming language)]&lt;br /&gt;
&lt;br /&gt;
*[http://www.c2.com/cgi/wiki?PythonVsRuby Python Vs Ruby]&lt;/div&gt;</summary>
		<author><name>Nutmeg</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17937</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 f1,</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17937"/>
		<updated>2009-09-07T03:02:52Z</updated>

		<summary type="html">&lt;p&gt;Nutmeg: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ruby and Python are both scripting languages whose popularity has sky rocketed in recent years. Both languages are &lt;br /&gt;
[http://en.wikipedia.org/wiki/High_level_language High-Level], [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) Garbage-collected], and [http://en.wikipedia.org/wiki/Dynamically_typed#Dynamic_typing Dynamically-typed]. Both provide an interactive shell, standard libraries, and persistence support. So, what are the differences?&lt;br /&gt;
&lt;br /&gt;
[[Image:svg2raster.png|frame|alt=Puzzle globe logo|Ruby Logo]]&lt;br /&gt;
[[Image:python.png|frame|alt=Puzzle globe logo|Python Logo]]&lt;br /&gt;
&lt;br /&gt;
Points of comparison:&lt;br /&gt;
* Language Features: Ruby vs Python&lt;br /&gt;
* Programming environments&lt;br /&gt;
* Features exclusive to each of Ruby and Python&lt;br /&gt;
* Advantages of Ruby/Python over statically typed languages&lt;br /&gt;
* Project environments suited to each&lt;br /&gt;
&lt;br /&gt;
==Language Features: Ruby vs Python==&lt;br /&gt;
&lt;br /&gt;
===Access Protection ===&lt;br /&gt;
&lt;br /&gt;
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. One of the differences of Ruby compared to Python is that Ruby keeps all of its instance variables completely private to the class and only exposes them through accessor methods (attr_writer, attr_reader, etc).&lt;br /&gt;
&lt;br /&gt;
Python's property descriptors are similar, but come with a tradeoff in the development process. If one begins in Python by using a publicly exposed instance variable and later changes the implementation to use a private instance variable exposed through a property descriptor, code internal to the class may need to be adjusted to use the private variable rather than the public property. Ruby removes this design decision&lt;br /&gt;
&lt;br /&gt;
===Functions and methods ===&lt;br /&gt;
In Ruby, the part which is different from Python is the fact that all operations are messages to objects. There are no separate functions and methods; all of them are methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Python, there are separate methods and functions as shown in the example below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
print string.count('o'), len(string)  # prints 2, 11 – why not string.len()?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby has reference to class in class body ===&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass&lt;br /&gt;
    initialize_magick()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Rubys variant is cleaner, as the magic stuff is done in the class definition, so you see that it’s being done when you look at the class.&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass:&lt;br /&gt;
    pass&lt;br /&gt;
initialize_magick(MyClass)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But it’s really not a big deal, because calling the initialise method after the class or as a decorator is really not a major drawback.&lt;br /&gt;
&lt;br /&gt;
=== Self Reference ===&lt;br /&gt;
In Python, one needs to write ''self'' as the first parameter of a method definition (alike Perl). Furthermore, Python doesn’t  require the variable name to be self. In Ruby, ''self'' is automatically available in a similar fashion as in C++.&lt;br /&gt;
&lt;br /&gt;
Additionally, the method call ''self.method'' can be shortened to ''method'', as ''self'' is the default receiver.&lt;br /&gt;
&lt;br /&gt;
=== Ruby continuations vs Python Generators ===&lt;br /&gt;
&lt;br /&gt;
Continuation is a &amp;quot;pointer&amp;quot; to the current position in your program, including calling stack and all variables. You can reuse that pointer to &amp;quot;go back in time&amp;quot; when needed. Continuations are useful when it comes to ''usecases''.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def loop&lt;br /&gt;
  cont=nil&lt;br /&gt;
  for i in 1..4&lt;br /&gt;
    puts i&lt;br /&gt;
    callcc {|continuation| cont=continuation} if i==2&lt;br /&gt;
  end&lt;br /&gt;
  return cont&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python doesn't support full continuations or even coroutines; instead it supports &amp;quot;generator&amp;quot; functions which create a kind of limited coroutine.&lt;br /&gt;
A generator in python is implemented as a special syntax for creating an instance of an iterator object, which returns the values returned by the &amp;quot;function&amp;quot; definition you provide. Python generators are easy and clean.&lt;br /&gt;
The equivalent code for the above code segment, in python is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from generator_tools import copy_generator&lt;br /&gt;
&lt;br /&gt;
def _callg(generator, generator_copy=None):&lt;br /&gt;
    for _ in generator: # run to the end&lt;br /&gt;
        pass&lt;br /&gt;
    if generator_copy is not None:&lt;br /&gt;
        return lambda: _callg(copy_generator(generator_copy))&lt;br /&gt;
&lt;br /&gt;
def loop(c):&lt;br /&gt;
    c.next() # advance to yield's expression&lt;br /&gt;
    return _callg(c, copy_generator(c))&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    def loop_gen():&lt;br /&gt;
        i = 1&lt;br /&gt;
        while i &amp;lt;= 4:&lt;br /&gt;
            print i&lt;br /&gt;
            if i == 2:&lt;br /&gt;
                yield&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
    c = loop(loop_gen())&lt;br /&gt;
    print(&amp;quot;c:&amp;quot;, c)&lt;br /&gt;
    for _ in range(2):&lt;br /&gt;
        print(&amp;quot;c():&amp;quot;, c())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indentation===&lt;br /&gt;
&lt;br /&gt;
Python uses whitespace indentation, rather than curly braces or keywords, to delimit statement blocks (a feature also known as the off-side rule). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.&lt;br /&gt;
On the other hand, ruby doesn't need any indentation although it can be optionally used for clarity.&lt;br /&gt;
&lt;br /&gt;
=== Other Differences ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby&lt;br /&gt;
!  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Higher-Order Functions&lt;br /&gt;
|  Implemented with procedure objects&lt;br /&gt;
|  Implemented as lambda expressions&lt;br /&gt;
|-&lt;br /&gt;
|  Arrays and hashes&lt;br /&gt;
|  supports Arrays and associative arrays (Hash)&lt;br /&gt;
|  has Lists and Tuples which are the same as arrays.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Memory management&lt;br /&gt;
|  has a mark and sweep garbage collector&lt;br /&gt;
|  has a reference counting garbage collector.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Parallel assignment&lt;br /&gt;
|  claims to do Operating System independent threading.&lt;br /&gt;
|  Threading available on many common platforms with some threading support&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Package support &lt;br /&gt;
| Not available&lt;br /&gt;
| Available&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Programming Environments ==&lt;br /&gt;
&lt;br /&gt;
===Development Environments===&lt;br /&gt;
Both languages provide interactive shells (type &amp;quot;python&amp;quot; or &amp;quot;irb&amp;quot;) and high-level persistence support. Multiple IDEs are available for Python, including GUI debuggers. A gdb-style debugger is available for each language. Python has a RefactoringBrowser, BicycleRepairMan. RubyLanguage now has a [http://www.kmc.gr.jp/proj/rrb/index-en.html RubyRefactoringBrowser]&lt;br /&gt;
&lt;br /&gt;
Both languages are supported by Emacs modes. Python can be used as an elisp replacement - see Pymacs. The current Ruby implementation is closely tied to Unix, making Windows performance and ports to new platforms problematic. There is an EclipseIde for Ruby. RubyCocoa adds support for Ruby to ProjectBuilder/ExCode on MacOsx. &lt;br /&gt;
&lt;br /&gt;
===Web Programming Environments ===&lt;br /&gt;
Both Ruby and Python have a large number of web programming environments/ application frameworks. They are exhaustively listed and compared [http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Python here]. For brevity, we compare ruby's [http://en.wikipedia.org/wiki/Ruby_on_rails Ruby on Rails] with python's [http://en.wikipedia.org/wiki/Django_(web_framework) Django].  The need was to compare two frameworks which were developed independent of each other and not based or influenced on the other. Hence the choice of django was made, as other web python frameworks like pylons and web2py are based  on rails. &lt;br /&gt;
&lt;br /&gt;
Django is a complete Python web application framework while rails is an agile web programming environment built in Ruby which greatly simplifies MVC framework development. Ruby OO programming topics in conjunction with various Rails recipes are considered a much lighter, simpler and faster development experience than other current enterprise frameworks provided today.&lt;br /&gt;
&lt;br /&gt;
The table below compares them.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby on Rails&lt;br /&gt;
!  Django&lt;br /&gt;
|-&lt;br /&gt;
|  Language&lt;br /&gt;
|  Ruby&lt;br /&gt;
|  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Ajax&lt;br /&gt;
|  Prototype, script.aculo.us&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  MVC framework&lt;br /&gt;
|  ActiveRecord, Action Pack&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  MVC Push/Pull&lt;br /&gt;
|  Push&lt;br /&gt;
|  Push 	 	 	 	 	&lt;br /&gt;
|-&lt;br /&gt;
| i18n &amp;amp; l10n?&lt;br /&gt;
| Localization, Plug-in &lt;br /&gt;
| Yes &lt;br /&gt;
|-&lt;br /&gt;
|  ORM&lt;br /&gt;
|  ActiveRecord&lt;br /&gt;
|  Django ORM&lt;br /&gt;
|-&lt;br /&gt;
|  Testing framework(s)&lt;br /&gt;
|  Unit Tests, Functional Tests and Integration Tests&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  DB migration framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  No (plugin exists, might be merged into trunk when more stable and feature complete)&lt;br /&gt;
|-&lt;br /&gt;
|  Security Framework(s)&lt;br /&gt;
|  Plug-in&lt;br /&gt;
|  ACL-based&lt;br /&gt;
|-&lt;br /&gt;
|  Template Framework(s)  &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  Caching Framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  Form Validation Framework(s) &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Features exclusive to each of Ruby and Python==&lt;br /&gt;
&lt;br /&gt;
===Python Advantages===&lt;br /&gt;
* Python has multiple inheritance &lt;br /&gt;
* Python has docstrings : Docstrings makes it possible to attach documentation directly to the classes and methods. That’s a nice documentation plus, and makes things like the Python interpreters ''help()'' function really useful. &lt;br /&gt;
&lt;br /&gt;
===Ruby Advantages===&lt;br /&gt;
* Ruby blocks are much more powerful than Python lambdas and they are integrated pervasively into the language. They also allow interaction between the block and the container.&lt;br /&gt;
* Metaprogramming (modifying classes on the fly) is easier in Ruby than in Python. Interestingly, in the Ruby community this is considered a powerful feature and used frequently, whereas the Python community tends to think of it as a last resort.&lt;br /&gt;
* Ruby is very good at creating domain-specific mini-languages. This is a consequence of the easy metaprogramming and optional parentheses on function calls.&lt;br /&gt;
&lt;br /&gt;
==Advantages of Ruby/Python over statically typed languages==&lt;br /&gt;
&lt;br /&gt;
The term Dynamic language refers to high level programming language that allows the programmer to modify the code during run time. The modifications may include addition of new blocks of code or modifications to objects during execution or changing the type of objects. Statically typed languages such as Java or C# have type checking performed during compile-time as opposed to run-time and an objects type cannot be changed. Programmers should declare the types they intend a method or function to use and the compiler will not permit the programmer to ignore this type. Apart from being dynamically typed, there are many features provided by dynamic languages that aren’t to be found in Static languages. These include blocks and closures, metaprogramming, and unbounded polymorphism and support for multiple programming paradigms. These features lend certain advantages to a dynamic language which are listed below: &lt;br /&gt;
&lt;br /&gt;
===Purely Object Oriented===&lt;br /&gt;
Ruby does not have primitives. everything, including integers are full fledged objects.&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  0.zero?    This evaluates to a true&lt;br /&gt;
  1.zero?    This evaluates to a false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Typed features===&lt;br /&gt;
With Static typing in Java and C#, programmers should declare the types they want a method or function to use while with Ruby you don't declare types for variables or functions. In Ruby objects are strongly and dynamically typed.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int val1=5;&lt;br /&gt;
String value=String.valueOf(val1);&lt;br /&gt;
if(value.equals(&amp;quot;5&amp;quot;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val1=5&lt;br /&gt;
value=str(val1)&lt;br /&gt;
if value == &amp;quot;5&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Verbosity===&lt;br /&gt;
Statically typed languages tend to be more verbose. &lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
BufferedReader file1=new BufferedReader(new FileReader(Filename));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file=open(Filename);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Relaxed syntax===&lt;br /&gt;
Ruby and Python are flexible with respect to syntax. For example,&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat = Cat.new  &lt;br /&gt;
cat = Cat.new()  &lt;br /&gt;
cat = Cat.new();  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===More compact code===&lt;br /&gt;
'''Java''':  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (int i = 0; i &amp;lt; 100; i++) &lt;br /&gt;
{}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
100.times { |i| }  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Default Arguments===&lt;br /&gt;
Ruby and Python allows you to define default values to method arguments while Java does not. &lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def calc_cube(x=2,y=3)&lt;br /&gt;
  val=x**y&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Checked Exceptions ===&lt;br /&gt;
Checked exceptions force every method to deal with (catching or throwing) all exceptions that its child calls or may call.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
If in the program, a method calls run as follows, A1() -&amp;gt; A2() -&amp;gt; A3() -&amp;gt; A4() and if A4() throws an Exception, and it is caught by A1(), then A2(), A3() must also throw the same Exception. &lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
Exceptions propagate upwards and A2() and A3() do not need to throw the Exception. &lt;br /&gt;
===Duck Typing===&lt;br /&gt;
Ruby doesn't care about an object's class, just whether it has a method of the name used in the method call. For this reason, the dynamic approach has earned the name duck typing.&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Duck &lt;br /&gt;
	def sound&lt;br /&gt;
         puts &amp;quot;Quack&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Class Frog&lt;br /&gt;
	def sound&lt;br /&gt;
	 puts &amp;quot;Croak&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def noises(duck)&lt;br /&gt;
 duck.sound&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duckA=Duck.new&lt;br /&gt;
frogB=Frog.new&lt;br /&gt;
&lt;br /&gt;
noises(frogB)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Result''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;Croak&amp;quot; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Environments Suited to Each==&lt;br /&gt;
&lt;br /&gt;
Python is useful for rapid prototyping, web scripting, XML processing, database applications, GUI applications, scientific computations. Python can be used for large and complex software systems. YouTube, for instance, runs mainly on Python, and it is preferred language at organizations including Google, NASA and Industrial Light and Magic. Specialized Python libraries and frameworks exist for scientific programming, data manipulation, Web services, XML interchange and many other things.&lt;br /&gt;
&lt;br /&gt;
Ruby is useful for typical scripting language applications such as text processing and middleware programs. It is suitable for small, ad-hoc scripting tasks that previously may have been solved with Perl. Ruby has first-class regular expressions, which makes text processing scripts easy to write. Ruby is also suitable for larger software systems. It’s most successful application is in the Ruby on Rails web framework. Websites like Twitter and Hulu use the Ruby on Rails web development framework in production environments.&lt;br /&gt;
Ruby can also be used as a high-level API wrapper (or domain-specific language) around some C library. Other uses for Ruby is in test/behavior driven development and when you need to create an &amp;quot;internal&amp;quot; domain-specific language.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
*[http://ruby.about.com/od/beginningruby/a/WhatIsRuby.htm What Is Ruby?]&lt;br /&gt;
&lt;br /&gt;
*[http://blog.ianbicking.org/ruby-python-power.html Ruby, Python, &amp;quot;Power&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
*[http://python.about.com/od/gettingstarted/ss/whatispython_3.htm What is Python?]&lt;br /&gt;
&lt;br /&gt;
*[http://johan.kiviniemi.name/blag/ruby-vs-python/  Ruby vs. Python Johan Kiviniemi's series of tubes]&lt;br /&gt;
&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby (programming language)]&lt;/div&gt;</summary>
		<author><name>Nutmeg</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17934</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 f1,</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17934"/>
		<updated>2009-09-07T02:52:53Z</updated>

		<summary type="html">&lt;p&gt;Nutmeg: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ruby and Python are both scripting languages whose popularity has sky rocketed in recent years. Both languages are &lt;br /&gt;
[http://en.wikipedia.org/wiki/High_level_language High-Level], [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) Garbage-collected], and [http://en.wikipedia.org/wiki/Dynamically_typed#Dynamic_typing Dynamically-typed]. Both provide an interactive shell, standard libraries, and persistence support. So, what are the differences?&lt;br /&gt;
&lt;br /&gt;
[[Image:svg2raster.png|frame|alt=Puzzle globe logo|Ruby Logo]]&lt;br /&gt;
[[Image:python.png|frame|alt=Puzzle globe logo|Python Logo]]&lt;br /&gt;
&lt;br /&gt;
Points of comparison:&lt;br /&gt;
* Language Features: Ruby vs Python&lt;br /&gt;
* Programming environments&lt;br /&gt;
* Features exclusive to each of Ruby and Python&lt;br /&gt;
* Advantages of Ruby/Python over statically typed languages&lt;br /&gt;
* Project environments suited to each&lt;br /&gt;
&lt;br /&gt;
==Language Features: Ruby vs Python==&lt;br /&gt;
&lt;br /&gt;
===Access Protection ===&lt;br /&gt;
&lt;br /&gt;
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. One of the differences of Ruby compared to Python is that Ruby keeps all of its instance variables completely private to the class and only exposes them through accessor methods (attr_writer, attr_reader, etc).&lt;br /&gt;
&lt;br /&gt;
Python's property descriptors are similar, but come with a tradeoff in the development process. If one begins in Python by using a publicly exposed instance variable and later changes the implementation to use a private instance variable exposed through a property descriptor, code internal to the class may need to be adjusted to use the private variable rather than the public property. Ruby removes this design decision&lt;br /&gt;
&lt;br /&gt;
===Functions and methods ===&lt;br /&gt;
In Ruby, the part which is different from Python is the fact that all operations are messages to objects. There are no separate functions and methods; all of them are methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Python, there are separate methods and functions as shown in the example below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
print string.count('o'), len(string)  # prints 2, 11 – why not string.len()?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby has reference to class in class body ===&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass&lt;br /&gt;
    initialize_magick()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Rubys variant is cleaner, as the magic stuff is done in the class definition, so you see that it’s being done when you look at the class.&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass:&lt;br /&gt;
    pass&lt;br /&gt;
initialize_magick(MyClass)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But it’s really not a big deal, because calling the initialise method after the class or as a decorator is really not a major drawback.&lt;br /&gt;
&lt;br /&gt;
=== Self Reference ===&lt;br /&gt;
In Python, one needs to write ''self'' as the first parameter of a method definition (alike Perl). Furthermore, Python doesn’t  require the variable name to be self. In Ruby, ''self'' is automatically available in a similar fashion as in C++.&lt;br /&gt;
&lt;br /&gt;
Additionally, the method call ''self.method'' can be shortened to ''method'', as ''self'' is the default receiver.&lt;br /&gt;
&lt;br /&gt;
=== Ruby continuations vs Python Generators ===&lt;br /&gt;
&lt;br /&gt;
Continuation is a &amp;quot;pointer&amp;quot; to the current position in your program, including calling stack and all variables. You can reuse that pointer to &amp;quot;go back in time&amp;quot; when needed. Continuations are useful when it comes to ''usecases''.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def loop&lt;br /&gt;
  cont=nil&lt;br /&gt;
  for i in 1..4&lt;br /&gt;
    puts i&lt;br /&gt;
    callcc {|continuation| cont=continuation} if i==2&lt;br /&gt;
  end&lt;br /&gt;
  return cont&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python doesn't support full continuations or even coroutines; instead it supports &amp;quot;generator&amp;quot; functions which create a kind of limited coroutine.&lt;br /&gt;
A generator in python is implemented as a special syntax for creating an instance of an iterator object, which returns the values returned by the &amp;quot;function&amp;quot; definition you provide. Python generators are easy and clean.&lt;br /&gt;
The equivalent code for the above code segment, in python is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from generator_tools import copy_generator&lt;br /&gt;
&lt;br /&gt;
def _callg(generator, generator_copy=None):&lt;br /&gt;
    for _ in generator: # run to the end&lt;br /&gt;
        pass&lt;br /&gt;
    if generator_copy is not None:&lt;br /&gt;
        return lambda: _callg(copy_generator(generator_copy))&lt;br /&gt;
&lt;br /&gt;
def loop(c):&lt;br /&gt;
    c.next() # advance to yield's expression&lt;br /&gt;
    return _callg(c, copy_generator(c))&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    def loop_gen():&lt;br /&gt;
        i = 1&lt;br /&gt;
        while i &amp;lt;= 4:&lt;br /&gt;
            print i&lt;br /&gt;
            if i == 2:&lt;br /&gt;
                yield&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
    c = loop(loop_gen())&lt;br /&gt;
    print(&amp;quot;c:&amp;quot;, c)&lt;br /&gt;
    for _ in range(2):&lt;br /&gt;
        print(&amp;quot;c():&amp;quot;, c())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indentation===&lt;br /&gt;
&lt;br /&gt;
Python uses whitespace indentation, rather than curly braces or keywords, to delimit statement blocks (a feature also known as the off-side rule). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.&lt;br /&gt;
On the other hand, ruby doesn't need any indentation although it can be optionally used for clarity.&lt;br /&gt;
&lt;br /&gt;
=== Other Differences ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby&lt;br /&gt;
!  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Higher-Order Functions&lt;br /&gt;
|  Implemented with procedure objects&lt;br /&gt;
|  Implemented as lambda expressions&lt;br /&gt;
|-&lt;br /&gt;
|  Arrays and hashes&lt;br /&gt;
|  supports Arrays and associative arrays (Hash)&lt;br /&gt;
|  has Lists and Tuples which are the same as arrays.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Memory management&lt;br /&gt;
|  has a mark and sweep garbage collector&lt;br /&gt;
|  has a reference counting garbage collector.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Parallel assignment&lt;br /&gt;
|  claims to do Operating System independent threading.&lt;br /&gt;
|  Threading available on many common platforms with some threading support&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Package support &lt;br /&gt;
| Not available&lt;br /&gt;
| Available&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Programming Environments ==&lt;br /&gt;
&lt;br /&gt;
===Development Environments===&lt;br /&gt;
Both languages provide interactive shells (type &amp;quot;python&amp;quot; or &amp;quot;irb&amp;quot;) and high-level persistence support. Multiple IDEs are available for Python, including GUI debuggers. A gdb-style debugger is available for each language. Python has a RefactoringBrowser, BicycleRepairMan. RubyLanguage now has a [http://www.kmc.gr.jp/proj/rrb/index-en.html RubyRefactoringBrowser]&lt;br /&gt;
&lt;br /&gt;
Both languages are supported by Emacs modes. Python can be used as an elisp replacement - see Pymacs. The current Ruby implementation is closely tied to Unix, making Windows performance and ports to new platforms problematic. There is an EclipseIde for Ruby. RubyCocoa adds support for Ruby to ProjectBuilder/ExCode on MacOsx. &lt;br /&gt;
&lt;br /&gt;
===Web Programming Environments ===&lt;br /&gt;
Both Ruby and Python have a large number of web programming environments/ application frameworks. They are exhaustively listed and compared [http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Python here]. For brevity, we compare ruby's [http://en.wikipedia.org/wiki/Ruby_on_rails Ruby on Rails] with python's [http://en.wikipedia.org/wiki/Django_(web_framework) Django].  The need was to compare two frameworks which were developed independent of each other and not based or influenced on the other. Hence the choice of django was made, as other web python frameworks like pylons and web2py are based  on rails. &lt;br /&gt;
&lt;br /&gt;
Django is a complete Python web application framework while rails is an agile web programming environment built in Ruby which greatly simplifies MVC framework development. Ruby OO programming topics in conjunction with various Rails recipes are considered a much lighter, simpler and faster development experience than other current enterprise frameworks provided today.&lt;br /&gt;
&lt;br /&gt;
The table below compares them.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby on Rails&lt;br /&gt;
!  Django&lt;br /&gt;
|-&lt;br /&gt;
|  Language&lt;br /&gt;
|  Ruby&lt;br /&gt;
|  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Ajax&lt;br /&gt;
|  Prototype, script.aculo.us&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  MVC framework&lt;br /&gt;
|  ActiveRecord, Action Pack&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  MVC Push/Pull&lt;br /&gt;
|  Push&lt;br /&gt;
|  Push 	 	 	 	 	&lt;br /&gt;
|-&lt;br /&gt;
| i18n &amp;amp; l10n?&lt;br /&gt;
| Localization, Plug-in &lt;br /&gt;
| Yes &lt;br /&gt;
|-&lt;br /&gt;
|  ORM&lt;br /&gt;
|  ActiveRecord&lt;br /&gt;
|  Django ORM&lt;br /&gt;
|-&lt;br /&gt;
|  Testing framework(s)&lt;br /&gt;
|  Unit Tests, Functional Tests and Integration Tests&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  DB migration framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  No (plugin exists, might be merged into trunk when more stable and feature complete)&lt;br /&gt;
|-&lt;br /&gt;
|  Security Framework(s)&lt;br /&gt;
|  Plug-in&lt;br /&gt;
|  ACL-based&lt;br /&gt;
|-&lt;br /&gt;
|  Template Framework(s)  &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  Caching Framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  Form Validation Framework(s) &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Features exclusive to each of Ruby and Python==&lt;br /&gt;
&lt;br /&gt;
===Python Advantages===&lt;br /&gt;
* Python has multiple inheritance &lt;br /&gt;
* Python has docstrings : Docstrings makes it possible to attach documentation directly to the classes and methods. That’s a nice documentation plus, and makes things like the Python interpreters ''help()'' function really useful. &lt;br /&gt;
&lt;br /&gt;
===Ruby Advantages===&lt;br /&gt;
* Ruby blocks are much more powerful than Python lambdas and they are integrated pervasively into the language. They also allow interaction between the block and the container.&lt;br /&gt;
* Metaprogramming (modifying classes on the fly) is easier in Ruby than in Python. Interestingly, in the Ruby community this is considered a powerful feature and used frequently, whereas the Python community tends to think of it as a last resort.&lt;br /&gt;
* Ruby is very good at creating domain-specific mini-languages. This is a consequence of the easy metaprogramming and optional parentheses on function calls.&lt;br /&gt;
&lt;br /&gt;
==Advantages of Ruby/Python over statically typed languages==&lt;br /&gt;
&lt;br /&gt;
The term Dynamic language refers to high level programming language that allows the programmer to modify the code during run time. The modifications may include addition of new blocks of code or modifications to objects during execution or changing the type of objects. Statically typed languages such as Java or C# have type checking performed during compile-time as opposed to run-time and an objects type cannot be changed. Programmers should declare the types they intend a method or function to use and the compiler will not permit the programmer to ignore this type. Apart from being dynamically typed, there are many features provided by dynamic languages that aren’t to be found in Static languages. These include blocks and closures, metaprogramming, and unbounded polymorphism and support for multiple programming paradigms. These features lend certain advantages to a dynamic language which are listed below: &lt;br /&gt;
&lt;br /&gt;
===Purely Object Oriented===&lt;br /&gt;
Ruby does not have primitives. everything, including integers are full fledged objects.&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  0.zero?    This evaluates to a true&lt;br /&gt;
  1.zero?    This evaluates to a false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Typed features===&lt;br /&gt;
With Static typing in Java and C#, programmers should declare the types they want a method or function to use while with Ruby you don't declare types for variables or functions. In Ruby objects are strongly and dynamically typed.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int val1=5;&lt;br /&gt;
String value=String.valueOf(val1);&lt;br /&gt;
if(value.equals(&amp;quot;5&amp;quot;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val1=5&lt;br /&gt;
value=str(val1)&lt;br /&gt;
if value == &amp;quot;5&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Verbosity===&lt;br /&gt;
Statically typed languages tend to be more verbose. &lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
BufferedReader file1=new BufferedReader(new FileReader(Filename));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file=open(Filename);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Relaxed syntax===&lt;br /&gt;
Ruby and Python are flexible with respect to syntax. For example,&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat = Cat.new  &lt;br /&gt;
cat = Cat.new()  &lt;br /&gt;
cat = Cat.new();  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===More compact code===&lt;br /&gt;
'''Java''':  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (int i = 0; i &amp;lt; 100; i++) &lt;br /&gt;
{}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
100.times { |i| }  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Default Arguments===&lt;br /&gt;
Ruby and Python allows you to define default values to method arguments while Java does not. &lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def calc_cube(x=2,y=3)&lt;br /&gt;
  val=x**y&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Checked Exceptions ===&lt;br /&gt;
Checked exceptions force every method to deal with (catching or throwing) all exceptions that its child calls or may call.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
If in the program, a method calls run as follows, A1() -&amp;gt; A2() -&amp;gt; A3() -&amp;gt; A4() and if A4() throws an Exception, and it is caught by A1(), then A2(), A3() must also throw the same Exception. &lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
Exceptions propagate upwards and A2() and A3() do not need to throw the Exception. &lt;br /&gt;
===Duck Typing===&lt;br /&gt;
Ruby doesn't care about an object's class, just whether it has a method of the name used in the method call. For this reason, the dynamic approach has earned the name duck typing.&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Duck &lt;br /&gt;
	def sound&lt;br /&gt;
         puts &amp;quot;Quack&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Class Frog&lt;br /&gt;
	def sound&lt;br /&gt;
	 puts &amp;quot;Croak&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def noises(duck)&lt;br /&gt;
 duck.sound&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duckA=Duck.new&lt;br /&gt;
frogB=Frog.new&lt;br /&gt;
&lt;br /&gt;
noises(frogB)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Result''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;Croak&amp;quot; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Environments Suited to Each==&lt;br /&gt;
&lt;br /&gt;
Python is useful for rapid prototyping, web scripting, XML processing, database applications, GUI applications, scientific computations. Python can be used for large and complex software systems. YouTube, for instance, runs mainly on Python, and it is preferred language at organizations including Google, NASA and Industrial Light and Magic. Specialized Python libraries and frameworks exist for scientific programming, data manipulation, Web services, XML interchange and many other things.&lt;br /&gt;
&lt;br /&gt;
Ruby is useful for typical scripting language applications such as text processing and middleware programs. It is suitable for small, ad-hoc scripting tasks that previously may have been solved with Perl. Ruby has first-class regular expressions, which makes text processing scripts easy to write. Ruby is also suitable for larger software systems. It’s most successful application is in the Ruby on Rails web framework. Websites like Twitter and Hulu use the Ruby on Rails web development framework in production environments.&lt;br /&gt;
Ruby can also be used as a high-level API wrapper (or domain-specific language) around some C library. Other uses for Ruby is in test/behavior driven development and when you need to create an &amp;quot;internal&amp;quot; domain-specific language.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/beginningruby/a/WhatIsRuby.htm What Is Ruby?]&lt;br /&gt;
&lt;br /&gt;
[http://blog.ianbicking.org/ruby-python-power.html Ruby, Python, &amp;quot;Power&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
[http://python.about.com/od/gettingstarted/ss/whatispython_3.htm What is Python?]&lt;br /&gt;
&lt;br /&gt;
[http://johan.kiviniemi.name/blag/ruby-vs-python/  Ruby vs. Python Johan Kiviniemi's series of tubes]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby (programming language)]&lt;/div&gt;</summary>
		<author><name>Nutmeg</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17649</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 f1,</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17649"/>
		<updated>2009-09-05T21:52:23Z</updated>

		<summary type="html">&lt;p&gt;Nutmeg: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ruby and Python are both scripting languages whose popularity has sky rocketed in recent years. Both languages are &lt;br /&gt;
[http://en.wikipedia.org/wiki/High_level_language High-Level], [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) Garbage-collected], and [http://en.wikipedia.org/wiki/Dynamically_typed#Dynamic_typing Dynamically-typed]. Both provide an interactive shell, standard libraries, and persistence support. So, what are the differences?&lt;br /&gt;
&lt;br /&gt;
[[Image:svg2raster.png|frame|alt=Puzzle globe logo|Ruby Logo]]&lt;br /&gt;
[[Image:python.png|frame|alt=Puzzle globe logo|Python Logo]]&lt;br /&gt;
&lt;br /&gt;
Points of comparison:&lt;br /&gt;
* Language Features: Ruby vs Python&lt;br /&gt;
* Web programming environments&lt;br /&gt;
* Features exclusive to each of Ruby and Python&lt;br /&gt;
* Advantages of Ruby/Python over statically typed languages&lt;br /&gt;
* Project environments suited to each&lt;br /&gt;
&lt;br /&gt;
==Language Features==&lt;br /&gt;
&lt;br /&gt;
===Access Protection ===&lt;br /&gt;
&lt;br /&gt;
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. One of the differences of Ruby compared to Python is that Ruby keeps all of its instance variables completely private to the class and only exposes them through accessor methods (attr_writer, attr_reader, etc).&lt;br /&gt;
&lt;br /&gt;
Python's property descriptors are similar, but come with a tradeoff in the development process. If one begins in Python by using a publicly exposed instance variable and later changes the implementation to use a private instance variable exposed through a property descriptor, code internal to the class may need to be adjusted to use the private variable rather than the public property. Ruby removes this design decision&lt;br /&gt;
&lt;br /&gt;
===Functions and methods ===&lt;br /&gt;
In Ruby, the part which is different from Python is the fact that all operations are messages to objects. There are no separate functions and methods; all of them are methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Python, there are separate methods and functions as shown in the example below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
print string.count('o'), len(string)  # prints 2, 11 – why not string.len()?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby has reference to class in class body ===&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass&lt;br /&gt;
    initialize_magick()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Rubys variant is cleaner, as the magic stuff is done in the class definition, so you see that it’s being done when you look at the class.&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass:&lt;br /&gt;
    pass&lt;br /&gt;
initialize_magick(MyClass)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But it’s really not a big deal, because calling the initialise method after the class or as a decorator is really not a major drawback.&lt;br /&gt;
&lt;br /&gt;
=== Self Reference ===&lt;br /&gt;
In Python, one needs to write ''self'' as the first parameter of a method definition (alike Perl). Furthermore, Python doesn’t  require the variable name to be self. In Ruby, ''self'' is automatically available in a similar fashion as in C++.&lt;br /&gt;
&lt;br /&gt;
Additionally, the method call ''self.method'' can be shortened to ''method'', as ''self'' is the default receiver.&lt;br /&gt;
&lt;br /&gt;
=== Ruby continuations vs Python Generators ===&lt;br /&gt;
&lt;br /&gt;
Continuation is a &amp;quot;pointer&amp;quot; to the current position in your program, including calling stack and all variables. You can reuse that pointer to &amp;quot;go back in time&amp;quot; when needed. Continuations are useful when it comes to ''usecases''.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def loop&lt;br /&gt;
  cont=nil&lt;br /&gt;
  for i in 1..4&lt;br /&gt;
    puts i&lt;br /&gt;
    callcc {|continuation| cont=continuation} if i==2&lt;br /&gt;
  end&lt;br /&gt;
  return cont&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python doesn't support full continuations or even coroutines; instead it supports &amp;quot;generator&amp;quot; functions which create a kind of limited coroutine.&lt;br /&gt;
A generator in python is implemented as a special syntax for creating an instance of an iterator object, which returns the values returned by the &amp;quot;function&amp;quot; definition you provide. Python generators are easy and clean.&lt;br /&gt;
The equivalent code for the above code segment, in python is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from generator_tools import copy_generator&lt;br /&gt;
&lt;br /&gt;
def _callg(generator, generator_copy=None):&lt;br /&gt;
    for _ in generator: # run to the end&lt;br /&gt;
        pass&lt;br /&gt;
    if generator_copy is not None:&lt;br /&gt;
        return lambda: _callg(copy_generator(generator_copy))&lt;br /&gt;
&lt;br /&gt;
def loop(c):&lt;br /&gt;
    c.next() # advance to yield's expression&lt;br /&gt;
    return _callg(c, copy_generator(c))&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    def loop_gen():&lt;br /&gt;
        i = 1&lt;br /&gt;
        while i &amp;lt;= 4:&lt;br /&gt;
            print i&lt;br /&gt;
            if i == 2:&lt;br /&gt;
                yield&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
    c = loop(loop_gen())&lt;br /&gt;
    print(&amp;quot;c:&amp;quot;, c)&lt;br /&gt;
    for _ in range(2):&lt;br /&gt;
        print(&amp;quot;c():&amp;quot;, c())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indentation===&lt;br /&gt;
&lt;br /&gt;
Python uses whitespace indentation, rather than curly braces or keywords, to delimit statement blocks (a feature also known as the off-side rule). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.&lt;br /&gt;
On the other hand, ruby doesn't need any indentation although it can be optionally used for clarity.&lt;br /&gt;
&lt;br /&gt;
=== Other Differences ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby&lt;br /&gt;
!  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Higher-Order Functions&lt;br /&gt;
|  Implemented with procedure objects&lt;br /&gt;
|  Implemented as lambda expressions&lt;br /&gt;
|-&lt;br /&gt;
|  Arrays and hashes&lt;br /&gt;
|  supports Arrays and associative arrays (Hash)&lt;br /&gt;
|  has Lists and Tuples which are the same as arrays.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Memory management&lt;br /&gt;
|  has a mark and sweep garbage collector&lt;br /&gt;
|  has a reference counting garbage collector.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Parallel assignment&lt;br /&gt;
|  claims to do Operating System independent threading.&lt;br /&gt;
|  Threading available on many common platforms with some threading support&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Package support &lt;br /&gt;
| Not available&lt;br /&gt;
| Available&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Web Programming Environments ==&lt;br /&gt;
&lt;br /&gt;
Both Ruby and Python have a large number of web programming environments/ application frameworks. They are exhaustively listed and compared [http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Python here]. For brevity, we compare ruby's [http://en.wikipedia.org/wiki/Ruby_on_rails Ruby on Rails] with python's [http://en.wikipedia.org/wiki/Django_(web_framework) Django].  The need was to compare two frameworks which were developed independent of each other and not based or influenced on the other. Hence the choice of django was made, as other web python frameworks like pylons and web2py are based  on rails. &lt;br /&gt;
&lt;br /&gt;
Django is a complete Python web application framework while rails is an agile web programming environment built in Ruby which greatly simplifies MVC framework development. Ruby OO programming topics in conjunction with various Rails recipes are considered a much lighter, simpler and faster development experience than other current enterprise frameworks provided today.&lt;br /&gt;
&lt;br /&gt;
The table below compares them.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby on Rails&lt;br /&gt;
!  Django&lt;br /&gt;
|-&lt;br /&gt;
|  Language&lt;br /&gt;
|  Ruby&lt;br /&gt;
|  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Ajax&lt;br /&gt;
|  Prototype, script.aculo.us&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  MVC framework&lt;br /&gt;
|  ActiveRecord, Action Pack&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  MVC Push/Pull&lt;br /&gt;
|  Push&lt;br /&gt;
|  Push 	 	 	 	 	&lt;br /&gt;
|-&lt;br /&gt;
| i18n &amp;amp; l10n?&lt;br /&gt;
| Localization, Plug-in &lt;br /&gt;
| Yes &lt;br /&gt;
|-&lt;br /&gt;
|  ORM&lt;br /&gt;
|  ActiveRecord&lt;br /&gt;
|  Django ORM&lt;br /&gt;
|-&lt;br /&gt;
|  Testing framework(s)&lt;br /&gt;
|  Unit Tests, Functional Tests and Integration Tests&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  DB migration framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  No (plugin exists, might be merged into trunk when more stable and feature complete)&lt;br /&gt;
|-&lt;br /&gt;
|  Security Framework(s)&lt;br /&gt;
|  Plug-in&lt;br /&gt;
|  ACL-based&lt;br /&gt;
|-&lt;br /&gt;
|  Template Framework(s)  &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  Caching Framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  Form Validation Framework(s) &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Advantages of Ruby/Python over statically typed languages==&lt;br /&gt;
&lt;br /&gt;
The term Dynamic language refers to high level programming language that allows the programmer to modify the code during run time. The modifications may include addition of new blocks of code or modifications to objects during execution or changing the type of objects. Statically typed languages such as Java or C# have type checking performed during compile-time as opposed to run-time and an objects type cannot be changed. Programmers should declare the types they intend a method or function to use and the compiler will not permit the programmer to ignore this type. Apart from being dynamically typed, there are many features provided by dynamic languages that aren’t to be found in Static languages. These include blocks and closures, metaprogramming, and unbounded polymorphism and support for multiple programming paradigms. These features lend certain advantages to a dynamic language which are listed below: &lt;br /&gt;
&lt;br /&gt;
===Purely Object Oriented===&lt;br /&gt;
Ruby does not have primitives. everything, including integers are full fledged objects.&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  0.zero?    This evaluates to a true&lt;br /&gt;
  1.zero?    This evaluates to a false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Typed features===&lt;br /&gt;
With Static typing in Java and C#, programmers should declare the types they want a method or function to use while with Ruby you don't declare types for variables or functions. In Ruby objects are strongly and dynamically typed.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int val1=5;&lt;br /&gt;
String value=String.valueOf(val1);&lt;br /&gt;
if(value.equals(&amp;quot;5&amp;quot;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val1=5&lt;br /&gt;
value=str(val1)&lt;br /&gt;
if value == &amp;quot;5&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Verbosity===&lt;br /&gt;
Statically typed languages tend to be more verbose. &lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
BufferedReader file1=new BufferedReader(new FileReader(Filename));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file=open(Filename);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Relaxed syntax===&lt;br /&gt;
Ruby and Python are flexible with respect to syntax. For example,&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat = Cat.new  &lt;br /&gt;
cat = Cat.new()  &lt;br /&gt;
cat = Cat.new();  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===More compact code===&lt;br /&gt;
'''Java''':  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (int i = 0; i &amp;lt; 100; i++) &lt;br /&gt;
{}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
100.times { |i| }  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Default Arguments===&lt;br /&gt;
Ruby and Python allows you to define default values to method arguments while Java does not. &lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def calc_cube(x=2,y=3)&lt;br /&gt;
  val=x**y&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Checked Exceptions ===&lt;br /&gt;
Checked exceptions force every method to deal with (catching or throwing) all exceptions that its child calls or may call.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
If in the program, a method calls run as follows, A1() -&amp;gt; A2() -&amp;gt; A3() -&amp;gt; A4() and if A4() throws an Exception, and it is caught by A1(), then A2(), A3() must also throw the same Exception. &lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
Exceptions propagate upwards and A2() and A3() do not need to throw the Exception. &lt;br /&gt;
===Duck Typing===&lt;br /&gt;
Ruby doesn't care about an object's class, just whether it has a method of the name used in the method call. For this reason, the dynamic approach has earned the name duck typing.&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Duck &lt;br /&gt;
	def sound&lt;br /&gt;
         puts &amp;quot;Quack&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Class Frog&lt;br /&gt;
	def sound&lt;br /&gt;
	 puts &amp;quot;Croak&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def noises(duck)&lt;br /&gt;
 duck.sound&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duckA=Duck.new&lt;br /&gt;
frogB=Frog.new&lt;br /&gt;
&lt;br /&gt;
noises(frogB)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Result''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;Croak&amp;quot; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Environments Suited to Each==&lt;br /&gt;
&lt;br /&gt;
Python is useful for rapid prototyping, web scripting, XML processing, database applications, GUI applications, scientific computations. Python can be used for large and complex software systems. YouTube, for instance, runs mainly on Python, and it is preferred language at organizations including Google, NASA and Industrial Light and Magic. Specialized Python libraries and frameworks exist for scientific programming, data manipulation, Web services, XML interchange and many other things.&lt;br /&gt;
&lt;br /&gt;
Ruby is useful for typical scripting language applications such as text processing and middleware programs. It is suitable for small, ad-hoc scripting tasks that previously may have been solved with Perl. Ruby has first-class regular expressions, which makes text processing scripts easy to write. Ruby is also suitable for larger software systems. It’s most successful application is in the Ruby on Rails web framework. Websites like Twitter and Hulu use the Ruby on Rails web development framework in production environments.&lt;br /&gt;
Ruby can also be used as a high-level API wrapper (or domain-specific language) around some C library. Other uses for Ruby is in test/behavior driven development and when you need to create an &amp;quot;internal&amp;quot; domain-specific language.&lt;/div&gt;</summary>
		<author><name>Nutmeg</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17648</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 f1,</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17648"/>
		<updated>2009-09-05T21:47:37Z</updated>

		<summary type="html">&lt;p&gt;Nutmeg: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ruby and Python are both scripting languages whose popularity has sky rocketed in recent years. Both languages are &lt;br /&gt;
[http://en.wikipedia.org/wiki/High_level_language High-Level], [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) Garbage-collected], and [http://en.wikipedia.org/wiki/Dynamically_typed#Dynamic_typing Dynamically-typed]. Both provide an interactive shell, standard libraries, and persistence support. So, what are the differences?&lt;br /&gt;
&lt;br /&gt;
[[Image:svg2raster.png|frame|alt=Puzzle globe logo|Ruby Logo]]&lt;br /&gt;
[[Image:python.png|frame|alt=Puzzle globe logo|Python Logo]]&lt;br /&gt;
&lt;br /&gt;
Points of comparison:&lt;br /&gt;
* Language Features: Ruby vs Python&lt;br /&gt;
* Web programming environments&lt;br /&gt;
* Features exclusive to each of Ruby and Python&lt;br /&gt;
* Advantages of Ruby/Python over statically typed languages&lt;br /&gt;
* Project environments suited to each&lt;br /&gt;
&lt;br /&gt;
==Language Features==&lt;br /&gt;
&lt;br /&gt;
===Access Protection ===&lt;br /&gt;
&lt;br /&gt;
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. One of the differences of Ruby compared to Python is that Ruby keeps all of its instance variables completely private to the class and only exposes them through accessor methods (attr_writer, attr_reader, etc).&lt;br /&gt;
&lt;br /&gt;
Python's property descriptors are similar, but come with a tradeoff in the development process. If one begins in Python by using a publicly exposed instance variable and later changes the implementation to use a private instance variable exposed through a property descriptor, code internal to the class may need to be adjusted to use the private variable rather than the public property. Ruby removes this design decision&lt;br /&gt;
&lt;br /&gt;
===Functions and methods ===&lt;br /&gt;
In Ruby, the part which is different from Python is the fact that all operations are messages to objects. There are no separate functions and methods; all of them are methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Python, there are separate methods and functions as shown in the example below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
print string.count('o'), len(string)  # prints 2, 11 – why not string.len()?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby has reference to class in class body ===&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass&lt;br /&gt;
    initialize_magick()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Rubys variant is cleaner, as the magic stuff is done in the class definition, so you see that it’s being done when you look at the class.&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass:&lt;br /&gt;
    pass&lt;br /&gt;
initialize_magick(MyClass)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But it’s really not a big deal, because calling the initialise method after the class or as a decorator is really not a major drawback.&lt;br /&gt;
&lt;br /&gt;
=== Self Reference ===&lt;br /&gt;
In Python, one needs to write ''self'' as the first parameter of a method definition (alike Perl). Furthermore, Python doesn’t  require the variable name to be self. In Ruby, ''self'' is automatically available in a similar fashion as in C++.&lt;br /&gt;
&lt;br /&gt;
Additionally, the method call ''self.method'' can be shortened to ''method'', as ''self'' is the default receiver.&lt;br /&gt;
&lt;br /&gt;
=== Ruby continuations vs Python Generators ===&lt;br /&gt;
&lt;br /&gt;
Continuation is a &amp;quot;pointer&amp;quot; to the current position in your program, including calling stack and all variables. You can reuse that pointer to &amp;quot;go back in time&amp;quot; when needed. Continuations are useful when it comes to ''usecases''.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def loop&lt;br /&gt;
  cont=nil&lt;br /&gt;
  for i in 1..4&lt;br /&gt;
    puts i&lt;br /&gt;
    callcc {|continuation| cont=continuation} if i==2&lt;br /&gt;
  end&lt;br /&gt;
  return cont&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python doesn't support full continuations or even coroutines; instead it supports &amp;quot;generator&amp;quot; functions which create a kind of limited coroutine.&lt;br /&gt;
A generator in python is implemented as a special syntax for creating an instance of an iterator object, which returns the values returned by the &amp;quot;function&amp;quot; definition you provide. Python generators are easy and clean.&lt;br /&gt;
The equivalent code for the above code segment, in python is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from generator_tools import copy_generator&lt;br /&gt;
&lt;br /&gt;
def _callg(generator, generator_copy=None):&lt;br /&gt;
    for _ in generator: # run to the end&lt;br /&gt;
        pass&lt;br /&gt;
    if generator_copy is not None:&lt;br /&gt;
        return lambda: _callg(copy_generator(generator_copy))&lt;br /&gt;
&lt;br /&gt;
def loop(c):&lt;br /&gt;
    c.next() # advance to yield's expression&lt;br /&gt;
    return _callg(c, copy_generator(c))&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    def loop_gen():&lt;br /&gt;
        i = 1&lt;br /&gt;
        while i &amp;lt;= 4:&lt;br /&gt;
            print i&lt;br /&gt;
            if i == 2:&lt;br /&gt;
                yield&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
    c = loop(loop_gen())&lt;br /&gt;
    print(&amp;quot;c:&amp;quot;, c)&lt;br /&gt;
    for _ in range(2):&lt;br /&gt;
        print(&amp;quot;c():&amp;quot;, c())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indentation===&lt;br /&gt;
&lt;br /&gt;
Python uses whitespace indentation, rather than curly braces or keywords, to delimit statement blocks (a feature also known as the off-side rule). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.&lt;br /&gt;
On the other hand, ruby doesn't need any indentation although it can be optionally used for clarity.&lt;br /&gt;
&lt;br /&gt;
=== Other Differences ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby&lt;br /&gt;
!  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Higher-Order Functions&lt;br /&gt;
|  Implemented with procedure objects&lt;br /&gt;
|  Implemented as lambda expressions&lt;br /&gt;
|-&lt;br /&gt;
|  Arrays and hashes&lt;br /&gt;
|  supports Arrays and associative arrays (Hash)&lt;br /&gt;
|  has Lists and Tuples which are the same as arrays.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Memory management&lt;br /&gt;
|  has a mark and sweep garbage collector&lt;br /&gt;
|  has a reference counting garbage collector.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Parallel assignment&lt;br /&gt;
|  claims to do Operating System independent threading.&lt;br /&gt;
|  Threading available on many common platforms with some threading support&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Package support &lt;br /&gt;
| Not available&lt;br /&gt;
| Available&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Web Programming Environments ==&lt;br /&gt;
&lt;br /&gt;
Both Ruby and Python have a large number of web programming environments/ application frameworks. They are exhaustively listed and compared [http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Python here]. For brevity, we compare ruby's [http://en.wikipedia.org/wiki/Ruby_on_rails Ruby on Rails] with python's [http://en.wikipedia.org/wiki/Django_(web_framework) Django].  The need was to compare two frameworks which were developed independent of each other and not based or influenced on the other. Hence the choice of django was made, as other web python frameworks like pylons and web2py are based  on rails. &lt;br /&gt;
&lt;br /&gt;
Django is a complete Python web application framework while rails is an agile web programming environment built in Ruby which greatly simplifies MVC framework development. Ruby OO programming topics in conjunction with various Rails recipes are considered a much lighter, simpler and faster development experience than other current enterprise frameworks provided today.&lt;br /&gt;
&lt;br /&gt;
The table below compares them.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby on Rails&lt;br /&gt;
!  Django&lt;br /&gt;
|-&lt;br /&gt;
|  Language&lt;br /&gt;
|  Ruby&lt;br /&gt;
|  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Ajax&lt;br /&gt;
|  Prototype, script.aculo.us&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  MVC framework&lt;br /&gt;
|  ActiveRecord, Action Pack&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  MVC Push/Pull&lt;br /&gt;
|  Push&lt;br /&gt;
|  Push 	 	 	 	 	&lt;br /&gt;
|-&lt;br /&gt;
| i18n &amp;amp; l10n?&lt;br /&gt;
| Localization, Plug-in &lt;br /&gt;
| Yes &lt;br /&gt;
|-&lt;br /&gt;
|  ORM&lt;br /&gt;
|  ActiveRecord&lt;br /&gt;
|  Django ORM&lt;br /&gt;
|-&lt;br /&gt;
|  Testing framework(s)&lt;br /&gt;
|  Unit Tests, Functional Tests and Integration Tests&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  DB migration framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  No (plugin exists, might be merged into trunk when more stable and feature complete)&lt;br /&gt;
|-&lt;br /&gt;
|  Security Framework(s)&lt;br /&gt;
|  Plug-in&lt;br /&gt;
|  ACL-based&lt;br /&gt;
|-&lt;br /&gt;
|  Template Framework(s)  &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  Caching Framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|-&lt;br /&gt;
|  Form Validation Framework(s) &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Advantages of Ruby/Python over statically typed languages==&lt;br /&gt;
&lt;br /&gt;
The term Dynamic language refers to high level programming language that allows the programmer to modify the code during run time. The modifications may include addition of new blocks of code or modifications to objects during execution or changing the type of objects. Statically typed languages such as Java or C# have type checking performed during compile-time as opposed to run-time and an objects type cannot be changed. Programmers should declare the types they intend a method or function to use and the compiler will not permit the programmer to ignore this type. Apart from being dynamically typed, there are many features provided by dynamic languages that aren’t to be found in Static languages. These include blocks and closures, metaprogramming, and unbounded polymorphism and support for multiple programming paradigms. These features lend certain advantages to a dynamic language which are listed below: &lt;br /&gt;
&lt;br /&gt;
===Purely Object Oriented===&lt;br /&gt;
Ruby does not have primitives. everything, including integers are full fledged objects.&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  0.zero?    This evaluates to a true&lt;br /&gt;
  1.zero?    This evaluates to a false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Typed features===&lt;br /&gt;
With Static typing in Java and C#, programmers should declare the types they want a method or function to use while with Ruby you don't declare types for variables or functions. In Ruby objects are strongly and dynamically typed.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int val1=5;&lt;br /&gt;
String value=String.valueOf(val1);&lt;br /&gt;
if(value.equals(&amp;quot;5&amp;quot;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val1=5&lt;br /&gt;
value=str(val1)&lt;br /&gt;
if value == &amp;quot;5&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verbosity===&lt;br /&gt;
Statically typed languages tend to be more verbose. &lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
BufferedReader file1=new BufferedReader(new FileReader(Filename));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file=open(Filename);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Relaxed syntax===&lt;br /&gt;
Ruby and Python are flexible with respect to syntax. For example,&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat = Cat.new  &lt;br /&gt;
cat = Cat.new()  &lt;br /&gt;
cat = Cat.new();  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===More compact code===&lt;br /&gt;
&lt;br /&gt;
'''Java''':  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (int i = 0; i &amp;lt; 100; i++) &lt;br /&gt;
{}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
100.times { |i| }  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Default Arguments===&lt;br /&gt;
Ruby and Python allows you to define default values to method arguments while Java does not. &lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def calc_cube(x=2,y=3)&lt;br /&gt;
  val=x**y&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Checked Exceptions ===&lt;br /&gt;
Checked exceptions force every method to deal with (catching or throwing) all exceptions that its child calls or may call.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
If in the program, a method calls run as follows, A1() -&amp;gt; A2() -&amp;gt; A3() -&amp;gt; A4() and if A4() throws an Exception, and it is caught by A1(), then A2(), A3() must also throw the same Exception. &lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
Exceptions propagate upwards and A2() and A3() do not need to throw the Exception. &lt;br /&gt;
&lt;br /&gt;
===Duck Typing===&lt;br /&gt;
&lt;br /&gt;
Ruby doesn't care about an object's class, just whether it has a method of the name used in the method call. For this reason, the dynamic approach has earned the name duck typing.&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Duck &lt;br /&gt;
	def sound&lt;br /&gt;
         puts &amp;quot;Quack&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Class Frog&lt;br /&gt;
	def sound&lt;br /&gt;
	 puts &amp;quot;Croak&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def noises(duck)&lt;br /&gt;
 duck.sound&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duckA=Duck.new&lt;br /&gt;
frogB=Frog.new&lt;br /&gt;
&lt;br /&gt;
noises(frogB)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Result''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;Croak&amp;quot; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Environments Suited to Each==&lt;br /&gt;
&lt;br /&gt;
Python is useful for rapid prototyping, web scripting, XML processing, database applications, GUI applications, scientific computations. Python can be used for large and complex software systems. YouTube, for instance, runs mainly on Python, and it is preferred language at organizations including Google, NASA and Industrial Light and Magic. Specialized Python libraries and frameworks exist for scientific programming, data manipulation, Web services, XML interchange and many other things.&lt;br /&gt;
&lt;br /&gt;
Ruby is useful for typical scripting language applications such as text processing and middleware programs. It is suitable for small, ad-hoc scripting tasks that previously may have been solved with Perl. Ruby has first-class regular expressions, which makes text processing scripts easy to write. Ruby is also suitable for larger software systems. It’s most successful application is in the Ruby on Rails web framework. Websites like Twitter and Hulu use the Ruby on Rails web development framework in production environments.&lt;br /&gt;
Ruby can also be used as a high-level API wrapper (or domain-specific language) around some C library. Other uses for Ruby is in test/behavior driven development and when you need to create an &amp;quot;internal&amp;quot; domain-specific language.&lt;/div&gt;</summary>
		<author><name>Nutmeg</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17646</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 f1,</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17646"/>
		<updated>2009-09-05T21:45:01Z</updated>

		<summary type="html">&lt;p&gt;Nutmeg: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ruby and Python are both scripting languages whose popularity has sky rocketed in recent years. Both languages are &lt;br /&gt;
[http://en.wikipedia.org/wiki/High_level_language High-Level], [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) Garbage-collected], and [http://en.wikipedia.org/wiki/Dynamically_typed#Dynamic_typing Dynamically-typed]. Both provide an interactive shell, standard libraries, and persistence support. So, what are the differences?&lt;br /&gt;
&lt;br /&gt;
[[Image:svg2raster.png|frame|alt=Puzzle globe logo|Ruby Logo]]&lt;br /&gt;
[[Image:python.png|frame|alt=Puzzle globe logo|Python Logo]]&lt;br /&gt;
&lt;br /&gt;
Points of comparison:&lt;br /&gt;
* Language Features: Ruby vs Python&lt;br /&gt;
* Web programming environments&lt;br /&gt;
* Features exclusive to each of Ruby and Python&lt;br /&gt;
* Advantages of Ruby/Python over statically typed languages&lt;br /&gt;
* Project environments suited to each&lt;br /&gt;
&lt;br /&gt;
==Language Features==&lt;br /&gt;
&lt;br /&gt;
===Access Protection ===&lt;br /&gt;
&lt;br /&gt;
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. One of the differences of Ruby compared to Python is that Ruby keeps all of its instance variables completely private to the class and only exposes them through accessor methods (attr_writer, attr_reader, etc).&lt;br /&gt;
&lt;br /&gt;
Python's property descriptors are similar, but come with a tradeoff in the development process. If one begins in Python by using a publicly exposed instance variable and later changes the implementation to use a private instance variable exposed through a property descriptor, code internal to the class may need to be adjusted to use the private variable rather than the public property. Ruby removes this design decision&lt;br /&gt;
&lt;br /&gt;
===Functions and methods ===&lt;br /&gt;
In Ruby, the part which is different from Python is the fact that all operations are messages to objects. There are no separate functions and methods; all of them are methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Python, there are separate methods and functions as shown in the example below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
print string.count('o'), len(string)  # prints 2, 11 – why not string.len()?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby has reference to class in class body ===&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass&lt;br /&gt;
    initialize_magick()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Rubys variant is cleaner, as the magic stuff is done in the class definition, so you see that it’s being done when you look at the class.&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass:&lt;br /&gt;
    pass&lt;br /&gt;
initialize_magick(MyClass)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But it’s really not a big deal, because calling the initialise method after the class or as a decorator is really not a major drawback.&lt;br /&gt;
&lt;br /&gt;
=== Self Reference ===&lt;br /&gt;
In Python, one needs to write ''self'' as the first parameter of a method definition (alike Perl). Furthermore, Python doesn’t  require the variable name to be self. In Ruby, ''self'' is automatically available in a similar fashion as in C++.&lt;br /&gt;
&lt;br /&gt;
Additionally, the method call ''self.method'' can be shortened to ''method'', as ''self'' is the default receiver.&lt;br /&gt;
&lt;br /&gt;
=== Ruby continuations vs Python Generators ===&lt;br /&gt;
&lt;br /&gt;
Continuation is a &amp;quot;pointer&amp;quot; to the current position in your program, including calling stack and all variables. You can reuse that pointer to &amp;quot;go back in time&amp;quot; when needed. Continuations are useful when it comes to ''usecases''.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def loop&lt;br /&gt;
  cont=nil&lt;br /&gt;
  for i in 1..4&lt;br /&gt;
    puts i&lt;br /&gt;
    callcc {|continuation| cont=continuation} if i==2&lt;br /&gt;
  end&lt;br /&gt;
  return cont&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python doesn't support full continuations or even coroutines; instead it supports &amp;quot;generator&amp;quot; functions which create a kind of limited coroutine.&lt;br /&gt;
A generator in python is implemented as a special syntax for creating an instance of an iterator object, which returns the values returned by the &amp;quot;function&amp;quot; definition you provide. Python generators are easy and clean.&lt;br /&gt;
The equivalent code for the above code segment, in python is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from generator_tools import copy_generator&lt;br /&gt;
&lt;br /&gt;
def _callg(generator, generator_copy=None):&lt;br /&gt;
    for _ in generator: # run to the end&lt;br /&gt;
        pass&lt;br /&gt;
    if generator_copy is not None:&lt;br /&gt;
        return lambda: _callg(copy_generator(generator_copy))&lt;br /&gt;
&lt;br /&gt;
def loop(c):&lt;br /&gt;
    c.next() # advance to yield's expression&lt;br /&gt;
    return _callg(c, copy_generator(c))&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    def loop_gen():&lt;br /&gt;
        i = 1&lt;br /&gt;
        while i &amp;lt;= 4:&lt;br /&gt;
            print i&lt;br /&gt;
            if i == 2:&lt;br /&gt;
                yield&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
    c = loop(loop_gen())&lt;br /&gt;
    print(&amp;quot;c:&amp;quot;, c)&lt;br /&gt;
    for _ in range(2):&lt;br /&gt;
        print(&amp;quot;c():&amp;quot;, c())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indentation===&lt;br /&gt;
&lt;br /&gt;
Python uses whitespace indentation, rather than curly braces or keywords, to delimit statement blocks (a feature also known as the off-side rule). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.&lt;br /&gt;
On the other hand, ruby doesn't need any indentation although it can be optionally used for clarity.&lt;br /&gt;
&lt;br /&gt;
=== Other Differences ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby&lt;br /&gt;
!  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Higher-Order Functions&lt;br /&gt;
|  Implemented with procedure objects&lt;br /&gt;
|  Implemented as lambda expressions&lt;br /&gt;
|-&lt;br /&gt;
|  Arrays and hashes&lt;br /&gt;
|  supports Arrays and associative arrays (Hash)&lt;br /&gt;
|  has Lists and Tuples which are the same as arrays.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Memory management&lt;br /&gt;
|  has a mark and sweep garbage collector&lt;br /&gt;
|  has a reference counting garbage collector.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Parallel assignment&lt;br /&gt;
|  claims to do Operating System independent threading.&lt;br /&gt;
|  Threading available on many common platforms with some threading support&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Package support &lt;br /&gt;
| Not available&lt;br /&gt;
| Available&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Web Programming Environments ==&lt;br /&gt;
&lt;br /&gt;
Both Ruby and Python have a large number of web programming environments/ application frameworks. They are exhaustively listed and compared [http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Python here]. For brevity, we compare ruby's [http://en.wikipedia.org/wiki/Ruby_on_rails Ruby on Rails] with python's [http://en.wikipedia.org/wiki/Django_(web_framework) Django].  The need was to compare two frameworks which were developed independent of each other and not based or influenced on the other. Hence the choice of django was made, as other web python frameworks like pylons and web2py are based  on rails. &lt;br /&gt;
&lt;br /&gt;
Django is a complete Python web application framework while rails is an agile web programming environment built in Ruby which greatly simplifies MVC framework development. Ruby OO programming topics in conjunction with various Rails recipes are considered a much lighter, simpler and faster development experience than other current enterprise frameworks provided today.&lt;br /&gt;
&lt;br /&gt;
The table below compares them.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby on Rails&lt;br /&gt;
!  Django&lt;br /&gt;
|-&lt;br /&gt;
|  Language&lt;br /&gt;
|  Ruby&lt;br /&gt;
|  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Ajax&lt;br /&gt;
|  Prototype, script.aculo.us&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  MVC framework&lt;br /&gt;
|  ActiveRecord, Action Pack&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  MVC Push/Pull&lt;br /&gt;
|  Push&lt;br /&gt;
|  Push&lt;br /&gt;
&lt;br /&gt;
 	 	 	 	 	&lt;br /&gt;
|-&lt;br /&gt;
| i18n &amp;amp; l10n?&lt;br /&gt;
| Localization, Plug-in &lt;br /&gt;
| Yes &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  ORM&lt;br /&gt;
|  ActiveRecord&lt;br /&gt;
|  Django ORM&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Testing framework(s)&lt;br /&gt;
|  Unit Tests, Functional Tests and Integration Tests&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  DB migration framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  No (plugin exists, might be merged into trunk when more stable and feature complete)&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Security Framework(s)&lt;br /&gt;
|  Plug-in&lt;br /&gt;
|  ACL-based&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Template Framework(s)  &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Caching Framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Form Validation Framework(s) &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Advantages of Ruby/Python over statically typed languages==&lt;br /&gt;
&lt;br /&gt;
The term Dynamic language refers to high level programming language that allows the programmer to modify the code during run time. The modifications may include addition of new blocks of code or modifications to objects during execution or changing the type of objects. Statically typed languages such as Java or C# have type checking performed during compile-time as opposed to run-time and an objects type cannot be changed. Programmers should declare the types they intend a method or function to use and the compiler will not permit the programmer to ignore this type. Apart from being dynamically typed, there are many features provided by dynamic languages that aren’t to be found in Static languages. These include blocks and closures, metaprogramming, and unbounded polymorphism and support for multiple programming paradigms. These features lend certain advantages to a dynamic language which are listed below: &lt;br /&gt;
&lt;br /&gt;
===Purely Object Oriented===&lt;br /&gt;
Ruby does not have primitives. everything, including integers are full fledged objects.&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  0.zero?    This evaluates to a true&lt;br /&gt;
  1.zero?    This evaluates to a false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Typed features===&lt;br /&gt;
With Static typing in Java and C#, programmers should declare the types they want a method or function to use while with Ruby you don't declare types for variables or functions. In Ruby objects are strongly and dynamically typed.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int val1=5;&lt;br /&gt;
String value=String.valueOf(val1);&lt;br /&gt;
if(value.equals(&amp;quot;5&amp;quot;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val1=5&lt;br /&gt;
value=str(val1)&lt;br /&gt;
if value == &amp;quot;5&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verbosity===&lt;br /&gt;
Statically typed languages tend to be more verbose. &lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
BufferedReader file1=new BufferedReader(new FileReader(Filename));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file=open(Filename);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Relaxed syntax===&lt;br /&gt;
Ruby and Python are flexible with respect to syntax. For example,&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat = Cat.new  &lt;br /&gt;
cat = Cat.new()  &lt;br /&gt;
cat = Cat.new();  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===More compact code===&lt;br /&gt;
&lt;br /&gt;
'''Java''':  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (int i = 0; i &amp;lt; 100; i++) &lt;br /&gt;
{}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
100.times { |i| }  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Default Arguments===&lt;br /&gt;
Ruby and Python allows you to define default values to method arguments while Java does not. &lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def calc_cube(x=2,y=3)&lt;br /&gt;
  val=x**y&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Checked Exceptions ===&lt;br /&gt;
Checked exceptions force every method to deal with (catching or throwing) all exceptions that its child calls or may call.&lt;br /&gt;
&lt;br /&gt;
'''Java''':&lt;br /&gt;
If in the program, a method calls run as follows, A1() -&amp;gt; A2() -&amp;gt; A3() -&amp;gt; A4() and if A4() throws an Exception, and it is caught by A1(), then A2(), A3() must also throw the same Exception. &lt;br /&gt;
&lt;br /&gt;
'''Python''':&lt;br /&gt;
Exceptions propagate upwards and A2() and A3() do not need to throw the Exception. &lt;br /&gt;
&lt;br /&gt;
===Duck Typing===&lt;br /&gt;
&lt;br /&gt;
Ruby doesn't care about an object's class, just whether it has a method of the name used in the method call. For this reason, the dynamic approach has earned the name duck typing.&lt;br /&gt;
&lt;br /&gt;
'''Ruby''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Duck &lt;br /&gt;
	def sound&lt;br /&gt;
         puts &amp;quot;Quack&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Class Frog&lt;br /&gt;
	def sound&lt;br /&gt;
	 puts &amp;quot;Croak&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def noises(duck)&lt;br /&gt;
 duck.sound&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duckA=Duck.new&lt;br /&gt;
frogB=Frog.new&lt;br /&gt;
&lt;br /&gt;
noises(frogB)&lt;br /&gt;
&lt;br /&gt;
'''Result''':&lt;br /&gt;
&amp;quot;Croak&amp;quot; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Environments Suited to Each==&lt;br /&gt;
&lt;br /&gt;
Python is useful for rapid prototyping, web scripting, XML processing, database applications, GUI applications, scientific computations. Python can be used for large and complex software systems. YouTube, for instance, runs mainly on Python, and it is preferred language at organizations including Google, NASA and Industrial Light and Magic. Specialized Python libraries and frameworks exist for scientific programming, data manipulation, Web services, XML interchange and many other things.&lt;br /&gt;
&lt;br /&gt;
Ruby is useful for typical scripting language applications such as text processing and middleware programs. It is suitable for small, ad-hoc scripting tasks that previously may have been solved with Perl. Ruby has first-class regular expressions, which makes text processing scripts easy to write. Ruby is also suitable for larger software systems. It’s most successful application is in the Ruby on Rails web framework. Websites like Twitter and Hulu use the Ruby on Rails web development framework in production environments.&lt;br /&gt;
Ruby can also be used as a high-level API wrapper (or domain-specific language) around some C library. Other uses for Ruby is in test/behavior driven development and when you need to create an &amp;quot;internal&amp;quot; domain-specific language.&lt;/div&gt;</summary>
		<author><name>Nutmeg</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17643</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 f1,</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17643"/>
		<updated>2009-09-05T21:40:25Z</updated>

		<summary type="html">&lt;p&gt;Nutmeg: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ruby and Python are both scripting languages whose popularity has sky rocketed in recent years. Both languages are &lt;br /&gt;
[http://en.wikipedia.org/wiki/High_level_language High-Level], [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) Garbage-collected], and [http://en.wikipedia.org/wiki/Dynamically_typed#Dynamic_typing Dynamically-typed]. Both provide an interactive shell, standard libraries, and persistence support. So, what are the differences?&lt;br /&gt;
&lt;br /&gt;
[[Image:svg2raster.png|frame|alt=Puzzle globe logo|Ruby Logo]]&lt;br /&gt;
[[Image:python.png|frame|alt=Puzzle globe logo|Python Logo]]&lt;br /&gt;
&lt;br /&gt;
Points of comparison:&lt;br /&gt;
* Language Features&lt;br /&gt;
* Web programming environments&lt;br /&gt;
* Features exclusive to each&lt;br /&gt;
* Advantages of each over statically typed languages&lt;br /&gt;
* Project environments suited to each&lt;br /&gt;
&lt;br /&gt;
==Language Features==&lt;br /&gt;
&lt;br /&gt;
===Access Protection ===&lt;br /&gt;
&lt;br /&gt;
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. One of the differences of Ruby compared to Python is that Ruby keeps all of its instance variables completely private to the class and only exposes them through accessor methods (attr_writer, attr_reader, etc).&lt;br /&gt;
&lt;br /&gt;
Python's property descriptors are similar, but come with a tradeoff in the development process. If one begins in Python by using a publicly exposed instance variable and later changes the implementation to use a private instance variable exposed through a property descriptor, code internal to the class may need to be adjusted to use the private variable rather than the public property. Ruby removes this design decision&lt;br /&gt;
&lt;br /&gt;
===Functions and methods ===&lt;br /&gt;
In Ruby, the part which is different from Python is the fact that all operations are messages to objects. There are no separate functions and methods; all of them are methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Python, there are separate methods and functions as shown in the example below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
print string.count('o'), len(string)  # prints 2, 11 – why not string.len()?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby has reference to class in class body ===&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass&lt;br /&gt;
    initialize_magick()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Rubys variant is cleaner, as the magic stuff is done in the class definition, so you see that it’s being done when you look at the class.&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass:&lt;br /&gt;
    pass&lt;br /&gt;
initialize_magick(MyClass)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But it’s really not a big deal, because calling the initialise method after the class or as a decorator is really not a major drawback.&lt;br /&gt;
&lt;br /&gt;
=== Self Reference ===&lt;br /&gt;
In Python, one needs to write ''self'' as the first parameter of a method definition (alike Perl). Furthermore, Python doesn’t  require the variable name to be self. In Ruby, ''self'' is automatically available in a similar fashion as in C++.&lt;br /&gt;
&lt;br /&gt;
Additionally, the method call ''self.method'' can be shortened to ''method'', as ''self'' is the default receiver.&lt;br /&gt;
&lt;br /&gt;
=== Ruby continuations vs Python Generators ===&lt;br /&gt;
&lt;br /&gt;
Continuation is a &amp;quot;pointer&amp;quot; to the current position in your program, including calling stack and all variables. You can reuse that pointer to &amp;quot;go back in time&amp;quot; when needed. Continuations are useful when it comes to ''usecases''.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def loop&lt;br /&gt;
  cont=nil&lt;br /&gt;
  for i in 1..4&lt;br /&gt;
    puts i&lt;br /&gt;
    callcc {|continuation| cont=continuation} if i==2&lt;br /&gt;
  end&lt;br /&gt;
  return cont&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python doesn't support full continuations or even coroutines; instead it supports &amp;quot;generator&amp;quot; functions which create a kind of limited coroutine.&lt;br /&gt;
A generator in python is implemented as a special syntax for creating an instance of an iterator object, which returns the values returned by the &amp;quot;function&amp;quot; definition you provide. Python generators are easy and clean.&lt;br /&gt;
The equivalent code for the above code segment, in python is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from generator_tools import copy_generator&lt;br /&gt;
&lt;br /&gt;
def _callg(generator, generator_copy=None):&lt;br /&gt;
    for _ in generator: # run to the end&lt;br /&gt;
        pass&lt;br /&gt;
    if generator_copy is not None:&lt;br /&gt;
        return lambda: _callg(copy_generator(generator_copy))&lt;br /&gt;
&lt;br /&gt;
def loop(c):&lt;br /&gt;
    c.next() # advance to yield's expression&lt;br /&gt;
    return _callg(c, copy_generator(c))&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    def loop_gen():&lt;br /&gt;
        i = 1&lt;br /&gt;
        while i &amp;lt;= 4:&lt;br /&gt;
            print i&lt;br /&gt;
            if i == 2:&lt;br /&gt;
                yield&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
    c = loop(loop_gen())&lt;br /&gt;
    print(&amp;quot;c:&amp;quot;, c)&lt;br /&gt;
    for _ in range(2):&lt;br /&gt;
        print(&amp;quot;c():&amp;quot;, c())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indentation===&lt;br /&gt;
&lt;br /&gt;
Python uses whitespace indentation, rather than curly braces or keywords, to delimit statement blocks (a feature also known as the off-side rule). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.&lt;br /&gt;
On the other hand, ruby doesn't need any indentation although it can be optionally used for clarity.&lt;br /&gt;
&lt;br /&gt;
=== Other Differences ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby&lt;br /&gt;
!  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Higher-Order Functions&lt;br /&gt;
|  Implemented with procedure objects&lt;br /&gt;
|  Implemented as lambda expressions&lt;br /&gt;
|-&lt;br /&gt;
|  Arrays and hashes&lt;br /&gt;
|  supports Arrays and associative arrays (Hash)&lt;br /&gt;
|  has Lists and Tuples which are the same as arrays.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Memory management&lt;br /&gt;
|  has a mark and sweep garbage collector&lt;br /&gt;
|  has a reference counting garbage collector.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Parallel assignment&lt;br /&gt;
|  claims to do Operating System independent threading.&lt;br /&gt;
|  Threading available on many common platforms with some threading support&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Package support &lt;br /&gt;
| Not available&lt;br /&gt;
| Available&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Web Programming Environments ==&lt;br /&gt;
&lt;br /&gt;
Both Ruby and Python have a large number of web programming environments/ application frameworks. They are exhaustively listed and compared [http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#Python here]. For brevity, we compare ruby's [http://en.wikipedia.org/wiki/Ruby_on_rails Ruby on Rails] with python's [http://en.wikipedia.org/wiki/Django_(web_framework) Django].  The need was to compare two frameworks which were developed independent of each other and not based or influenced on the other. Hence the choice of django was made, as other web python frameworks like pylons and web2py are based  on rails. &lt;br /&gt;
&lt;br /&gt;
Django is a complete Python web application framework while rails is an agile web programming environment built in Ruby which greatly simplifies MVC framework development. Ruby OO programming topics in conjunction with various Rails recipes are considered a much lighter, simpler and faster development experience than other current enterprise frameworks provided today.&lt;br /&gt;
&lt;br /&gt;
The table below compares them.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby on Rails&lt;br /&gt;
!  Django&lt;br /&gt;
|-&lt;br /&gt;
|  Language&lt;br /&gt;
|  Ruby&lt;br /&gt;
|  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Ajax&lt;br /&gt;
|  Prototype, script.aculo.us&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  MVC framework&lt;br /&gt;
|  ActiveRecord, Action Pack&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  MVC Push/Pull&lt;br /&gt;
|  Push&lt;br /&gt;
|  Push&lt;br /&gt;
&lt;br /&gt;
 	 	 	 	 	&lt;br /&gt;
|-&lt;br /&gt;
| i18n &amp;amp; l10n?&lt;br /&gt;
| Localization, Plug-in &lt;br /&gt;
| Yes &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  ORM&lt;br /&gt;
|  ActiveRecord&lt;br /&gt;
|  Django ORM&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Testing framework(s)&lt;br /&gt;
|  Unit Tests, Functional Tests and Integration Tests&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  DB migration framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  No (plugin exists, might be merged into trunk when more stable and feature complete)&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Security Framework(s)&lt;br /&gt;
|  Plug-in&lt;br /&gt;
|  ACL-based&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Template Framework(s)  &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Caching Framework(s)&lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Form Validation Framework(s) &lt;br /&gt;
|  Yes&lt;br /&gt;
|  Yes&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Advantages of each over statically typed languages==&lt;br /&gt;
&lt;br /&gt;
The term Dynamic language refers to high level programming language that allows the programmer to modify the code during run time. The modifications may include addition of new blocks of code or modifications to objects during execution or changing the type of objects. Statically typed languages such as Java or C# have type checking performed during compile-time as opposed to run-time and an objects type cannot be changed. Programmers should declare the types they intend a method or function to use and the compiler will not permit the programmer to ignore this type. Apart from being dynamically typed, there are many features provided by dynamic languages that aren’t to be found in Static languages. These include blocks and closures, metaprogramming, and unbounded polymorphism and support for multiple programming paradigms. These features lend certain advantages to a dynamic language which are listed below: &lt;br /&gt;
&lt;br /&gt;
===Purely Object Oriented===&lt;br /&gt;
Ruby does not have primitives. everything, including integers are full fledged objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  0.zero?    This evaluates to a true&lt;br /&gt;
  1.zero?    This evaluates to a false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Typed features===&lt;br /&gt;
With Static typing in Java and C#, programmers should declare the types they want a method or function to use while with Ruby you don't declare types for variables or functions. In Ruby objects are strongly and dynamically typed.&lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int val1=5;&lt;br /&gt;
String value=String.valueOf(val1);&lt;br /&gt;
if(value.equals(&amp;quot;5&amp;quot;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val1=5&lt;br /&gt;
value=str(val1)&lt;br /&gt;
if value == &amp;quot;5&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Verbosity===&lt;br /&gt;
Statically typed languages tend to be more verbose. &lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
BufferedReader file1=new BufferedReader(new FileReader(Filename));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file=open(Filename);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Relaxed syntax===&lt;br /&gt;
Ruby and Python are flexible with respect to syntax. For example,&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat = Cat.new  &lt;br /&gt;
cat = Cat.new()  &lt;br /&gt;
cat = Cat.new();  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===More compact code===&lt;br /&gt;
&lt;br /&gt;
Java:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (int i = 0; i &amp;lt; 100; i++) &lt;br /&gt;
{}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
100.times { |i| }  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Default Arguments===&lt;br /&gt;
Ruby and Python allows you to define default values to method arguments while Java does not. &lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def calc_cube(x=2,y=3)&lt;br /&gt;
  val=x**y&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Checked Exceptions ===&lt;br /&gt;
Checked exceptions force every method to deal with (catching or throwing) all exceptions that its child calls or may call.&lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
If in the program, a method calls run as follows, A1() -&amp;gt; A2() -&amp;gt; A3() -&amp;gt; A4() and if A4() throws an Exception, and it is caught by A1(), then A2(), A3() must also throw the same Exception. &lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
Exceptions propagate upwards and A2() and A3() do not need to throw the Exception. &lt;br /&gt;
&lt;br /&gt;
===Duck Typing===&lt;br /&gt;
&lt;br /&gt;
Ruby doesn't care about an object's class, just whether it has a method of the name used in the method call. For this reason, the dynamic approach has earned the name duck typing.&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Duck &lt;br /&gt;
	def sound&lt;br /&gt;
         puts &amp;quot;Quack&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Class Frog&lt;br /&gt;
	def sound&lt;br /&gt;
	 puts &amp;quot;Croak&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def noises(duck)&lt;br /&gt;
 duck.sound&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duckA=Duck.new&lt;br /&gt;
frogB=Frog.new&lt;br /&gt;
&lt;br /&gt;
noises(frogB)&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;quot;Croak&amp;quot; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Environments Suited to Each==&lt;br /&gt;
&lt;br /&gt;
Python is useful for rapid prototyping, web scripting, XML processing, database applications, GUI applications, scientific computations. Python can be used for large and complex software systems. YouTube, for instance, runs mainly on Python, and it is preferred language at organizations including Google, NASA and Industrial Light and Magic. Specialized Python libraries and frameworks exist for scientific programming, data manipulation, Web services, XML interchange and many other things.&lt;br /&gt;
&lt;br /&gt;
Ruby is useful for typical scripting language applications such as text processing and middleware programs. It is suitable for small, ad-hoc scripting tasks that previously may have been solved with Perl. Ruby has first-class regular expressions, which makes text processing scripts easy to write. Ruby is also suitable for larger software systems. It’s most successful application is in the Ruby on Rails web framework. Websites like Twitter and Hulu use the Ruby on Rails web development framework in production environments.&lt;br /&gt;
Ruby can also be used as a high-level API wrapper (or domain-specific language) around some C library. Other uses for Ruby is in test/behavior driven development and when you need to create an &amp;quot;internal&amp;quot; domain-specific language.&lt;/div&gt;</summary>
		<author><name>Nutmeg</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17637</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 f1,</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_f1,&amp;diff=17637"/>
		<updated>2009-09-05T19:56:05Z</updated>

		<summary type="html">&lt;p&gt;Nutmeg: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ruby and Python are both scripting languages whose popularity has sky rocketed in recent years. Both languages are &lt;br /&gt;
[http://en.wikipedia.org/wiki/High_level_language High-Level], [http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) Garbage-collected], and [http://en.wikipedia.org/wiki/Dynamically_typed#Dynamic_typing Dynamically-typed]. Both provide an interactive shell, standard libraries, and persistence support. So, what are the differences?&lt;br /&gt;
&lt;br /&gt;
[[Image:svg2raster.png|frame|alt=Puzzle globe logo|Ruby Logo]]&lt;br /&gt;
[[Image:python.png|frame|alt=Puzzle globe logo|Python Logo]]&lt;br /&gt;
&lt;br /&gt;
Points of comparison:&lt;br /&gt;
* Language Features&lt;br /&gt;
* Web programming environments&lt;br /&gt;
* Features exclusive to each&lt;br /&gt;
* Advantages of each over statically typed languages&lt;br /&gt;
* Project environments suited to each&lt;br /&gt;
&lt;br /&gt;
==Language Features==&lt;br /&gt;
&lt;br /&gt;
===Access Protection ===&lt;br /&gt;
&lt;br /&gt;
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. One of the differences of Ruby compared to Python is that Ruby keeps all of its instance variables completely private to the class and only exposes them through accessor methods (attr_writer, attr_reader, etc).&lt;br /&gt;
&lt;br /&gt;
Python's property descriptors are similar, but come with a tradeoff in the development process. If one begins in Python by using a publicly exposed instance variable and later changes the implementation to use a private instance variable exposed through a property descriptor, code internal to the class may need to be adjusted to use the private variable rather than the public property. Ruby removes this design decision&lt;br /&gt;
&lt;br /&gt;
===Functions and methods ===&lt;br /&gt;
In Ruby, the part which is different from Python is the fact that all operations are messages to objects. There are no separate functions and methods; all of them are methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Python, there are separate methods and functions as shown in the example below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string = 'Hello world'&lt;br /&gt;
print string.count('o'), len(string)  # prints 2, 11 – why not string.len()?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby has reference to class in class body ===&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass&lt;br /&gt;
    initialize_magick()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Rubys variant is cleaner, as the magic stuff is done in the class definition, so you see that it’s being done when you look at the class.&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MyClass:&lt;br /&gt;
    pass&lt;br /&gt;
initialize_magick(MyClass)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But it’s really not a big deal, because calling the initialise method after the class or as a decorator is really not a major drawback.&lt;br /&gt;
&lt;br /&gt;
=== Self Reference ===&lt;br /&gt;
In Python, one needs to write ''self'' as the first parameter of a method definition (alike Perl). Furthermore, Python doesn’t  require the variable name to be self. In Ruby, ''self'' is automatically available in a similar fashion as in C++.&lt;br /&gt;
&lt;br /&gt;
Additionally, the method call ''self.method'' can be shortened to ''method'', as ''self'' is the default receiver.&lt;br /&gt;
&lt;br /&gt;
=== Ruby continuations vs Python Generators ===&lt;br /&gt;
&lt;br /&gt;
Continuation is a &amp;quot;pointer&amp;quot; to the current position in your program, including calling stack and all variables. You can reuse that pointer to &amp;quot;go back in time&amp;quot; when needed. Continuations are useful when it comes to ''usecases''.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def loop&lt;br /&gt;
  cont=nil&lt;br /&gt;
  for i in 1..4&lt;br /&gt;
    puts i&lt;br /&gt;
    callcc {|continuation| cont=continuation} if i==2&lt;br /&gt;
  end&lt;br /&gt;
  return cont&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python doesn't support full continuations or even coroutines; instead it supports &amp;quot;generator&amp;quot; functions which create a kind of limited coroutine.&lt;br /&gt;
A generator in python is implemented as a special syntax for creating an instance of an iterator object, which returns the values returned by the &amp;quot;function&amp;quot; definition you provide. Python generators are easy and clean.&lt;br /&gt;
The equivalent code for the above code segment, in python is &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from generator_tools import copy_generator&lt;br /&gt;
&lt;br /&gt;
def _callg(generator, generator_copy=None):&lt;br /&gt;
    for _ in generator: # run to the end&lt;br /&gt;
        pass&lt;br /&gt;
    if generator_copy is not None:&lt;br /&gt;
        return lambda: _callg(copy_generator(generator_copy))&lt;br /&gt;
&lt;br /&gt;
def loop(c):&lt;br /&gt;
    c.next() # advance to yield's expression&lt;br /&gt;
    return _callg(c, copy_generator(c))&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    def loop_gen():&lt;br /&gt;
        i = 1&lt;br /&gt;
        while i &amp;lt;= 4:&lt;br /&gt;
            print i&lt;br /&gt;
            if i == 2:&lt;br /&gt;
                yield&lt;br /&gt;
            i += 1&lt;br /&gt;
&lt;br /&gt;
    c = loop(loop_gen())&lt;br /&gt;
    print(&amp;quot;c:&amp;quot;, c)&lt;br /&gt;
    for _ in range(2):&lt;br /&gt;
        print(&amp;quot;c():&amp;quot;, c())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indentation===&lt;br /&gt;
&lt;br /&gt;
Python uses whitespace indentation, rather than curly braces or keywords, to delimit statement blocks (a feature also known as the off-side rule). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.&lt;br /&gt;
On the other hand, ruby doesn't need any indentation although it can be optionally used for clarity.&lt;br /&gt;
&lt;br /&gt;
=== Other Differences ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Feature&lt;br /&gt;
!  Ruby&lt;br /&gt;
!  Python&lt;br /&gt;
|-&lt;br /&gt;
|  Higher-Order Functions&lt;br /&gt;
|  Implemented with procedure objects&lt;br /&gt;
|  Implemented as lambda expressions&lt;br /&gt;
|-&lt;br /&gt;
|  Arrays and hashes&lt;br /&gt;
|  supports Arrays and associative arrays (Hash)&lt;br /&gt;
|  has Lists and Tuples which are the same as arrays.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Memory management&lt;br /&gt;
|  has a mark and sweep garbage collector&lt;br /&gt;
|  has a reference counting garbage collector.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  Parallel assignment&lt;br /&gt;
|  claims to do Operating System independent threading.&lt;br /&gt;
|  Threading available on many common platforms with some threading support&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Package support &lt;br /&gt;
| Not available&lt;br /&gt;
| Available&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Web Programming Environments ==&lt;br /&gt;
&lt;br /&gt;
    * Ruby on Rails - A Ruby Application Server for web development&lt;br /&gt;
    * Zope - Like Ruby on Rails, but in Python &lt;br /&gt;
&lt;br /&gt;
Both of these are&lt;br /&gt;
&lt;br /&gt;
==Advantages of each over statically typed languages==&lt;br /&gt;
&lt;br /&gt;
The term Dynamic language refers to high level programming language that allows the programmer to modify the code during run time. The modifications may include addition of new blocks of code or modifications to objects. Statically typed languages such as Java or C# need to have all expressions assigned to a particular type before being run (or during compile-time).&lt;br /&gt;
&lt;br /&gt;
Apart from being dynamically typed, there are many features provided by dynamic languages that aren’t to be found in Static languages. These include blocks and closures, metaprogramming, and unbounded polymorphism and support for multiple programming paradigms. &lt;br /&gt;
&lt;br /&gt;
===Purely Object Oriented===&lt;br /&gt;
Ruby does not have primitives; everything, including integers are full fledged objects.&lt;br /&gt;
&lt;br /&gt;
  0.zero?    # =&amp;gt; true&lt;br /&gt;
  1.zero?    # =&amp;gt; false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Typed features===&lt;br /&gt;
With Static typing in Java and C#, we need to declare the type of each variable (int, char, float etc.) while with Ruby you don't declare types for variables or functions. In Ruby objects are strongly and dynamically typed. Where ‘type’ refers to a set of values or a set of operations. &lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int val1=5;&lt;br /&gt;
String value=String.valueOf(val1);&lt;br /&gt;
if(value.equals(&amp;quot;5&amp;quot;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val1=5&lt;br /&gt;
value=str(val1)&lt;br /&gt;
if value == &amp;quot;5&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Checked Exceptions ===&lt;br /&gt;
Checked exceptions force every method to deal with (catching or throwing) all exceptions that its child calls or may call.&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
If in the program, a method calls run as follows, A1() -&amp;gt; A2() -&amp;gt; A3() -&amp;gt; A4() and if A4() throws an Exception, and it is caught by A1(), then A2(), A3() must also throw the same Exception. &lt;br /&gt;
&lt;br /&gt;
Python&lt;br /&gt;
Exceptions propagate upwards and A2() and A3() do not need to throw the Exception. &lt;br /&gt;
&lt;br /&gt;
===Verbosity===&lt;br /&gt;
Statically typed languages are verbose. &lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
BufferedReader file1=new BufferedReader(new FileReader(Filename));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file=open(Filename);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Relaxed syntax===&lt;br /&gt;
All the statements below achieve the same functionality. &lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat = Cat.new  &lt;br /&gt;
cat = Cat.new()  &lt;br /&gt;
cat = Cat.new();  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===More compact code===&lt;br /&gt;
&lt;br /&gt;
Java:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (int i = 0; i &amp;lt; 100; i++) &lt;br /&gt;
{}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
100.times { |i| }  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Default Arguments===&lt;br /&gt;
Ruby and Python allows you to define default values to method arguments while Java does not. &lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def calc_cube(x=2,y=3)&lt;br /&gt;
  val=x**y&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Duck Typing===&lt;br /&gt;
&lt;br /&gt;
Ruby doesn't care about an object's class, just whether it has a method of the name used in the method call. For this reason, the dynamic approach has earned the name duck typing.&lt;br /&gt;
&lt;br /&gt;
Ruby:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Duck &lt;br /&gt;
	def sound&lt;br /&gt;
         puts &amp;quot;Quack&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Class Frog&lt;br /&gt;
	def sound&lt;br /&gt;
	 puts &amp;quot;Croak&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
def noises(duck)&lt;br /&gt;
 duck.sound&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duckA=Duck.new&lt;br /&gt;
frogB=Frog.new&lt;br /&gt;
&lt;br /&gt;
noises(frogB)&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;quot;Croak&amp;quot; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nutmeg</name></author>
	</entry>
</feed>