<?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=Snirgud</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=Snirgud"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Snirgud"/>
	<updated>2026-05-09T04:46:40Z</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/wiki2_14_san&amp;diff=23748</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23748"/>
		<updated>2009-10-09T07:59:53Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Balking Pattern====&lt;br /&gt;
The balking pattern only executes an action on an object when the object is in a particular state so if we are trying to access an object in a particular state which differs from the expected state, the object will &amp;quot;balk&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
For example, in Java, an IllegalStateException might be thrown in this case [10]. To avoid such an error from occurring, the object can attempt to acquire write locks which will time out if the object is not in the right state. Also, if an object’s method is called when the object is not in an appropriate state to execute that method, have the method return without doing anything [11].  &lt;br /&gt;
&lt;br /&gt;
An example of the Balking pattern in Java [10]:&lt;br /&gt;
 public class Example{&lt;br /&gt;
    private boolean jobInProgress = false; &lt;br /&gt;
    public void job(){&lt;br /&gt;
        synchronized(this){&lt;br /&gt;
           if(jobInProgress){&lt;br /&gt;
               return;&lt;br /&gt;
           }&lt;br /&gt;
           jobInProgress = true;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Read/Write Lock Pattern====&lt;br /&gt;
This pattern allows concurrent read access to an object but requires exclusive access for write operations [11]. This means that when an object is being written to, the object access will be blocked for all other read operations. &lt;br /&gt;
&lt;br /&gt;
The Java module ReadWriteLock is a good example of this pattern. It maintains a pair of associated locks, one for read-only operations and one for writing so that the read lock may be held simultaneously by multiple reader threads, so long as there are no writer but the write lock is exclusive [12]. &lt;br /&gt;
&lt;br /&gt;
An example of the read/write locking in Java [13]:&lt;br /&gt;
 public void setWriteLock(boolean lock) {&lt;br /&gt;
        if (lock) {&lt;br /&gt;
                rwLock.writeLock().lock();&lt;br /&gt;
                WaitTimerTask job = new WaitTimerTask(Thread.currentThread(),false);&lt;br /&gt;
                waitTimer.schedule(job, maxWait);&lt;br /&gt;
        } else {&lt;br /&gt;
                rwLock.writeLock().unlock();&lt;br /&gt;
                WaitTimerTask job = lockTaskStack.get().pop();&lt;br /&gt;
                job.cancel();&lt;br /&gt;
        }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Guarded Suspension Pattern====&lt;br /&gt;
In this pattern, an operation on an object required not only a lock but also a condition to be met before the operation is executed [14]. So as the name suggests, the execution is &amp;quot;suspended&amp;quot; until the &amp;quot;guard&amp;quot; or condition is satisfied. Because it is blocking, the guarded suspension pattern is generally only used when the developer knows that a method call will be suspended for a finite and reasonable period of time. If a method call is suspended for too long, then the overall program will slow down or stop, waiting for the precondition to be satisfied. If the developer knows that the method call suspension will be indefinite or for an unacceptably long period, then the balking pattern may be preferred [14].&lt;br /&gt;
&lt;br /&gt;
An example of an actual implementation would be a queue object with a get method that has a guard to detect when there are no items in the queue. Once the &amp;quot;put&amp;quot; method notifies the other methods (for example, a get() method), then the get() method can exit its guarded state and proceed with a call. Once the queue is empty, then the get() method will enter a guarded state once again [14].&lt;br /&gt;
&lt;br /&gt;
An example of Guarded Suspension [15]:&lt;br /&gt;
 synchronized void guardedMethod () {&lt;br /&gt;
    while (! precondition) { wait (); }&lt;br /&gt;
        ... // code requiring precondition&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Monitor Pattern====&lt;br /&gt;
In this pattern, an object may be used by multiple threads using mutual exclusion such that at any time only a single thread will be executing on that object [16]. This simplifies the code complexity by removing the need to parallelize the code between the multiple threads. Monitors also provide a mechanism for threads to temporarily give up exclusive access, in order to wait for some condition to be met, before regaining exclusive access and resuming their task or have a mechanism for signaling other threads that such conditions have been met [16].&lt;br /&gt;
&lt;br /&gt;
As a simple example, consider a monitor for performing transactions on a bank account [16]:&lt;br /&gt;
&lt;br /&gt;
 monitor class Account {&lt;br /&gt;
  private int balance := 0&lt;br /&gt;
  invariant balance &amp;gt;= 0  &lt;br /&gt;
  public method boolean withdraw(int amount)&lt;br /&gt;
  {&lt;br /&gt;
    if amount &amp;lt; 0 then error &amp;quot;Amount may not be negative&amp;quot;&lt;br /&gt;
    else if balance &amp;lt; amount then return false&lt;br /&gt;
    else { balance := balance - amount ; return true }&lt;br /&gt;
  }&lt;br /&gt;
  public method deposit(int amount) {&lt;br /&gt;
    if amount &amp;lt; 0 then error &amp;quot;Amount may not be negative&amp;quot;&lt;br /&gt;
    else balance := balance + amount&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[10] http://en.wikipedia.org/wiki/Balking_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[11] http://www.mindspring.com/~mgrand/pattern_synopses.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[12] http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[13] http://today.java.net/pub/a/today/2007/06/28/extending-reentrantreadwritelock.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[14] http://en.wikipedia.org/wiki/Guarded_suspension &amp;lt;br /&amp;gt;&lt;br /&gt;
[15] http://web.cecs.pdx.edu/~antoy/Courses/Patterns/slides/GuardedSuspension.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[16] http://en.wikipedia.org/wiki/Monitor_%28synchronization%29&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23746</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23746"/>
		<updated>2009-10-09T07:49:16Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Balking Pattern====&lt;br /&gt;
The balking pattern only executes an action on an object when the object is in a particular state so if we are trying to access an object in a particular state which differs from the expected state, the object will &amp;quot;balk&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
For example, in Java, an IllegalStateException might be thrown in this case [10]. To avoid such an error from occurring, the object can attempt to acquire write locks which will time out if the object is not in the right state. Also, if an object’s method is called when the object is not in an appropriate state to execute that method, have the method return without doing anything [11].  &lt;br /&gt;
&lt;br /&gt;
An example of the Balking pattern in Java [10]:&lt;br /&gt;
 public class Example{&lt;br /&gt;
    private boolean jobInProgress = false; &lt;br /&gt;
    public void job(){&lt;br /&gt;
        synchronized(this){&lt;br /&gt;
           if(jobInProgress){&lt;br /&gt;
               return;&lt;br /&gt;
           }&lt;br /&gt;
           jobInProgress = true;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Read/Write Lock Pattern====&lt;br /&gt;
This pattern allows concurrent read access to an object but requires exclusive access for write operations [11]. This means that when an object is being written to, the object access will be blocked for all other read operations. &lt;br /&gt;
&lt;br /&gt;
The Java module ReadWriteLock is a good example of this pattern. It maintains a pair of associated locks, one for read-only operations and one for writing so that the read lock may be held simultaneously by multiple reader threads, so long as there are no writer but the write lock is exclusive [12]. &lt;br /&gt;
&lt;br /&gt;
An example of the read/write locking in Java [13]:&lt;br /&gt;
 public void setWriteLock(boolean lock) {&lt;br /&gt;
        if (lock) {&lt;br /&gt;
                rwLock.writeLock().lock();&lt;br /&gt;
                WaitTimerTask job = new WaitTimerTask(Thread.currentThread(),false);&lt;br /&gt;
                waitTimer.schedule(job, maxWait);&lt;br /&gt;
        } else {&lt;br /&gt;
                rwLock.writeLock().unlock();&lt;br /&gt;
                WaitTimerTask job = lockTaskStack.get().pop();&lt;br /&gt;
                job.cancel();&lt;br /&gt;
        }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Guarded Suspension Pattern====&lt;br /&gt;
In this pattern, an operation on an object required not only a lock but also a condition to be met before the operation is executed [14]. So as the name suggests, the execution is &amp;quot;suspended&amp;quot; until the &amp;quot;guard&amp;quot; or condition is satisfied. Because it is blocking, the guarded suspension pattern is generally only used when the developer knows that a method call will be suspended for a finite and reasonable period of time. If a method call is suspended for too long, then the overall program will slow down or stop, waiting for the precondition to be satisfied. If the developer knows that the method call suspension will be indefinite or for an unacceptably long period, then the balking pattern may be preferred [14].&lt;br /&gt;
&lt;br /&gt;
An example of an actual implementation would be a queue object with a get method that has a guard to detect when there are no items in the queue. Once the &amp;quot;put&amp;quot; method notifies the other methods (for example, a get() method), then the get() method can exit its guarded state and proceed with a call. Once the queue is empty, then the get() method will enter a guarded state once again [14].&lt;br /&gt;
&lt;br /&gt;
An example of Guarded Suspension [15]:&lt;br /&gt;
 synchronized void guardedMethod () {&lt;br /&gt;
    while (! precondition) { wait (); }&lt;br /&gt;
        ... // code requiring precondition&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[10] http://en.wikipedia.org/wiki/Balking_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[11] http://www.mindspring.com/~mgrand/pattern_synopses.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[12] http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[13] http://today.java.net/pub/a/today/2007/06/28/extending-reentrantreadwritelock.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[14] http://en.wikipedia.org/wiki/Guarded_suspension &amp;lt;br /&amp;gt;&lt;br /&gt;
[15] http://web.cecs.pdx.edu/~antoy/Courses/Patterns/slides/GuardedSuspension.html &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23742</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23742"/>
		<updated>2009-10-09T07:44:49Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Balking Pattern====&lt;br /&gt;
The balking pattern only executes an action on an object when the object is in a particular state so if we are trying to access an object in a particular state which differs from the expected state, the object will &amp;quot;balk&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
For example, in Java, an IllegalStateException might be thrown in this case [10]. To avoid such an error from occurring, the object can attempt to acquire write locks which will time out if the object is not in the right state. Also, if an object’s method is called when the object is not in an appropriate state to execute that method, have the method return without doing anything [11].  &lt;br /&gt;
&lt;br /&gt;
An example of the Balking pattern in Java [10]:&lt;br /&gt;
 public class Example{&lt;br /&gt;
    private boolean jobInProgress = false; &lt;br /&gt;
    public void job(){&lt;br /&gt;
        synchronized(this){&lt;br /&gt;
           if(jobInProgress){&lt;br /&gt;
               return;&lt;br /&gt;
           }&lt;br /&gt;
           jobInProgress = true;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Read/Write Lock Pattern====&lt;br /&gt;
This pattern allows concurrent read access to an object but requires exclusive access for write operations [11]. This means that when an object is being written to, the object access will be blocked for all other read operations. &lt;br /&gt;
&lt;br /&gt;
The Java module ReadWriteLock is a good example of this pattern. It maintains a pair of associated locks, one for read-only operations and one for writing so that the read lock may be held simultaneously by multiple reader threads, so long as there are no writer but the write lock is exclusive [12]. &lt;br /&gt;
&lt;br /&gt;
An example of the read/write locking in Java [13]:&lt;br /&gt;
 public void setWriteLock(boolean lock) {&lt;br /&gt;
        if (lock) {&lt;br /&gt;
                rwLock.writeLock().lock();&lt;br /&gt;
                WaitTimerTask job = new WaitTimerTask(Thread.currentThread(),false);&lt;br /&gt;
                waitTimer.schedule(job, maxWait);&lt;br /&gt;
        } else {&lt;br /&gt;
                rwLock.writeLock().unlock();&lt;br /&gt;
                WaitTimerTask job = lockTaskStack.get().pop();&lt;br /&gt;
                job.cancel();&lt;br /&gt;
        }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Guarded Suspension Pattern====&lt;br /&gt;
In this pattern, an operation on an object required not only a lock but also a condition to be met before the operation is executed [14]. So as the name suggests, the execution is &amp;quot;suspended&amp;quot; until the &amp;quot;guard&amp;quot; or condition is satisfied. Because it is blocking, the guarded suspension pattern is generally only used when the developer knows that a method call will be suspended for a finite and reasonable period of time. If a method call is suspended for too long, then the overall program will slow down or stop, waiting for the precondition to be satisfied. If the developer knows that the method call suspension will be indefinite or for an unacceptably long period, then the balking pattern may be preferred [14].&lt;br /&gt;
&lt;br /&gt;
An example of Guarded Suspension [15]:&lt;br /&gt;
 synchronized void guardedMethod () {&lt;br /&gt;
    while (! precondition) { wait (); }&lt;br /&gt;
        ... // code requiring precondition&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[10] http://en.wikipedia.org/wiki/Balking_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[11] http://www.mindspring.com/~mgrand/pattern_synopses.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[12] http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[13] http://today.java.net/pub/a/today/2007/06/28/extending-reentrantreadwritelock.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[14] http://en.wikipedia.org/wiki/Guarded_suspension &amp;lt;br /&amp;gt;&lt;br /&gt;
[15] http://web.cecs.pdx.edu/~antoy/Courses/Patterns/slides/GuardedSuspension.html &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23708</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23708"/>
		<updated>2009-10-09T07:18:58Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Balking Pattern====&lt;br /&gt;
The balking pattern only executes an action on an object when the object is in a particular state so if we are trying to access an object in a particular state which differs from the expected state, the object will &amp;quot;balk&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
For example, in Java, an IllegalStateException might be thrown in this case [10]. To avoid such an error from occurring, the object can attempt to acquire write locks which will time out if the object is not in the right state. Also, if an object’s method is called when the object is not in an appropriate state to execute that method, have the method return without doing anything [11].  &lt;br /&gt;
&lt;br /&gt;
An example of the Balking pattern in Java [10]:&lt;br /&gt;
 public class Example{&lt;br /&gt;
    private boolean jobInProgress = false; &lt;br /&gt;
    public void job(){&lt;br /&gt;
        synchronized(this){&lt;br /&gt;
           if(jobInProgress){&lt;br /&gt;
               return;&lt;br /&gt;
           }&lt;br /&gt;
           jobInProgress = true;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Read/Write Lock Pattern====&lt;br /&gt;
This pattern allows concurrent read access to an object but requires exclusive access for write operations [11]. This means that when an object is being written to, the object access will be blocked for all other read operations. &lt;br /&gt;
&lt;br /&gt;
The Java module ReadWriteLock is a good example of this pattern. It maintains a pair of associated locks, one for read-only operations and one for writing so that the read lock may be held simultaneously by multiple reader threads, so long as there are no writer but the write lock is exclusive [12]. &lt;br /&gt;
&lt;br /&gt;
An example of the read/write locking in Java [13]:&lt;br /&gt;
 public void setWriteLock(boolean lock) {&lt;br /&gt;
        if (lock) {&lt;br /&gt;
                rwLock.writeLock().lock();&lt;br /&gt;
                WaitTimerTask job = new WaitTimerTask(Thread.currentThread(),false);&lt;br /&gt;
                waitTimer.schedule(job, maxWait);&lt;br /&gt;
        } else {&lt;br /&gt;
                rwLock.writeLock().unlock();&lt;br /&gt;
                WaitTimerTask job = lockTaskStack.get().pop();&lt;br /&gt;
                job.cancel();&lt;br /&gt;
        }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[10] http://en.wikipedia.org/wiki/Balking_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[11] http://www.mindspring.com/~mgrand/pattern_synopses.htm&lt;br /&gt;
[12] http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html&lt;br /&gt;
[13] http://today.java.net/pub/a/today/2007/06/28/extending-reentrantreadwritelock.html&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23694</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23694"/>
		<updated>2009-10-09T07:07:52Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Balking Pattern====&lt;br /&gt;
The balking pattern only executes an action on an object when the object is in a particular state so if we are trying to access an object in a particular state which differs from the expected state, the object will &amp;quot;balk&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
For example, in Java, an IllegalStateException might be thrown in this case [10]. To avoid such an error from occurring, the object can attempt to acquire write locks which will time out if the object is not in the right state. Also, if an object’s method is called when the object is not in an appropriate state to execute that method, have the method return without doing anything [11].  &lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [10]:&lt;br /&gt;
 public class Example{&lt;br /&gt;
    private boolean jobInProgress = false; &lt;br /&gt;
    public void job(){&lt;br /&gt;
        synchronized(this){&lt;br /&gt;
           if(jobInProgress){&lt;br /&gt;
               return;&lt;br /&gt;
           }&lt;br /&gt;
           jobInProgress = true;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Read/Write Lock Pattern====&lt;br /&gt;
This pattern allows concurrent read access to an object but requires exclusive access for write operations [11]. This means that when an object is being written to, the object access will be blocked for all other read operations. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[10] http://en.wikipedia.org/wiki/Balking_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[11] http://www.mindspring.com/~mgrand/pattern_synopses.htm&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23686</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23686"/>
		<updated>2009-10-09T06:57:46Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Balking Pattern====&lt;br /&gt;
The balking pattern only executes an action on an object when the object is in a particular state so if we are trying to access an object in a particular state which differs from the expected state, the object will &amp;quot;balk&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
For example, in Java, an IllegalStateException might be thrown in this case [10]. To avoid such an error from occurring, the object can attempt to acquire write locks which will time out if the object is not in the right state. Also, if an object’s method is called when the object is not in an appropriate state to execute that method, have the method return without doing anything [11].  &lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [10]:&lt;br /&gt;
 public class Example{&lt;br /&gt;
    private boolean jobInProgress = false; &lt;br /&gt;
    public void job(){&lt;br /&gt;
        synchronized(this){&lt;br /&gt;
           if(jobInProgress){&lt;br /&gt;
               return;&lt;br /&gt;
           }&lt;br /&gt;
           jobInProgress = true;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Read/Write Lock Pattern====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[10] http://en.wikipedia.org/wiki/Balking_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[11] http://www.mindspring.com/~mgrand/pattern_synopses.htm#Balking&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23683</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23683"/>
		<updated>2009-10-09T06:53:35Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Balking Pattern====&lt;br /&gt;
The balking pattern only executes an action on an object when the object is in a particular state so if we are trying to access an object in a particular state which differs from the expected state, the object will &amp;quot;balk&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
For example, in Java, an IllegalStateException might be thrown in this case [10]. To avoid such an error from occurring, the object can attempt to acquire write locks which will time out if the object is not in the right state. Also, if an object’s method is called when the object is not in an appropriate state to execute that method, have the method return without doing anything [11].  &lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [10]:&lt;br /&gt;
 public class Example{&lt;br /&gt;
    private boolean jobInProgress = false; &lt;br /&gt;
    public void job(){&lt;br /&gt;
        synchronized(this){&lt;br /&gt;
           if(jobInProgress){&lt;br /&gt;
               return;&lt;br /&gt;
           }&lt;br /&gt;
           jobInProgress = true;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf &amp;lt;br /&amp;gt;&lt;br /&gt;
[10] http://en.wikipedia.org/wiki/Balking_pattern &amp;lt;br /&amp;gt;&lt;br /&gt;
[11] http://www.mindspring.com/~mgrand/pattern_synopses.htm#Balking&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23651</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23651"/>
		<updated>2009-10-09T06:35:28Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Balking Pattern====&lt;br /&gt;
The balking pattern only executes an action on an object when the object is in a particular state so if we are trying to access an object in a particular state which differs from the expected state, the object will &amp;quot;balk&amp;quot;. For example, in Java, an IllegalStateException might be thrown in this case [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf&lt;br /&gt;
[10] http://en.wikipedia.org/wiki/Balking_pattern&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23640</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23640"/>
		<updated>2009-10-09T06:26:11Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Balking Pattern====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23637</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23637"/>
		<updated>2009-10-09T06:19:01Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Balking Pattern====&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23635</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23635"/>
		<updated>2009-10-09T06:16:33Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23634</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23634"/>
		<updated>2009-10-09T06:15:48Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
An example of the Scheduler component in Java [9]:&lt;br /&gt;
 public class Scheduler&lt;br /&gt;
 {&lt;br /&gt;
   private List act_list = new ArrayList();&lt;br /&gt;
   private synchronized IMethodRequest get()&lt;br /&gt;
   public synchronized void insert(IMethodRequest mr)&lt;br /&gt;
   private class Dispatcher extends Thread&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Active.jpg&amp;diff=23633</id>
		<title>File:Active.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Active.jpg&amp;diff=23633"/>
		<updated>2009-10-09T06:12:51Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23632</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23632"/>
		<updated>2009-10-09T06:12:31Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|frame|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23631</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23631"/>
		<updated>2009-10-09T06:11:43Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:active.jpg|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23630</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23630"/>
		<updated>2009-10-09T06:11:15Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components [8]: &lt;br /&gt;
The Proxy component provides interface for clients with publicly accessible methods. The Scheduler component schedules requests to decide which request will be executed next. There is another interface which defines the method request on an active object. There also exists a list of pending requests from clients along with the implementation of the active object method. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Class Diagram for Active Object [9]]]&lt;br /&gt;
&lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23615</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23615"/>
		<updated>2009-10-09T05:42:26Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
====Active Object====&lt;br /&gt;
The Active Object pattern decouples method execution from method invocation in order to simplify synchronized access to an object that resides in its own thread of control so that one or more independent threads can access data modeled as a single object [8]. &lt;br /&gt;
&lt;br /&gt;
This pattern consists of certain important components and describes the interactions between these components. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This pattern is commonly used in distributed systems requiring multi-threaded servers and in client applications, such as windowing systems and network browsers which employ active objects to simplify concurrent, asynchronous network operations [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;br /&gt;
[8] http://www.cs.wustl.edu/~schmidt/PDF/Act-Obj.pdf&lt;br /&gt;
[9] http://www.cs.uu.nl/docs/vakken/no/active_object_pattern.pdf&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23552</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23552"/>
		<updated>2009-10-09T04:34:23Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definitions===&lt;br /&gt;
&lt;br /&gt;
* Design Patterns&lt;br /&gt;
*:In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
* Concurrency Pattern&lt;br /&gt;
*:To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23546</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23546"/>
		<updated>2009-10-09T04:30:42Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Two important questions arise:'''&lt;br /&gt;
&lt;br /&gt;
* What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
* How do we ensure that a particular multi-threaded code is thread safe? Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definition &amp;amp; Motivation===&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
====Concurrency Pattern====&lt;br /&gt;
To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23538</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23538"/>
		<updated>2009-10-09T04:27:00Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
# What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
# How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definition &amp;amp; Motivation===&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
====Concurrency Pattern====&lt;br /&gt;
To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23537</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23537"/>
		<updated>2009-10-09T04:24:03Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definition &amp;amp; Motivation===&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
====Concurrency Pattern====&lt;br /&gt;
To ensure the above discussed thread safe programming in a multi-threaded programming paradigm where the focus is on the interactions between tasks that execute in parallel, we need to design applications using design patterns called concurrency patterns [7].  &lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Concurrency_pattern&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23479</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23479"/>
		<updated>2009-10-09T03:47:39Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definition &amp;amp; Motivation===&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design and not a finished design that can be transformed directly into code [6]. It is a description or template for how to solve a problem that can be used in many different situations and typically shows relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved [6].&lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;br /&gt;
[6] http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23470</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23470"/>
		<updated>2009-10-09T03:33:45Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definition &amp;amp; Motivation===&lt;br /&gt;
&lt;br /&gt;
====Design Patterns====&lt;br /&gt;
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved.&lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23456</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23456"/>
		<updated>2009-10-09T03:20:14Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Concurrency Patterns==&lt;br /&gt;
&lt;br /&gt;
===Definition &amp;amp; Motivation===&lt;br /&gt;
&lt;br /&gt;
===Types of Concurrency Patterns===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23450</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23450"/>
		<updated>2009-10-09T03:17:45Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23448</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23448"/>
		<updated>2009-10-09T03:17:12Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
Here's an example of some thread safe code. In C language, local variables are dynamically allocated on the stack. Therefore, any function that does not use static data or other shared resources is trivially thread-safe, as in the following example [5]:&lt;br /&gt;
 /* thread-safe function */&lt;br /&gt;
 int diff(int x, int y)&lt;br /&gt;
 {&lt;br /&gt;
        int delta;&lt;br /&gt;
&lt;br /&gt;
        delta = y - x;&lt;br /&gt;
        if (delta &amp;lt; 0)&lt;br /&gt;
                delta = -delta;&lt;br /&gt;
&lt;br /&gt;
        return delta;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[5] http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.genprogc/doc/genprogc/writing_reentrant_thread_safe_code.htm &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23440</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23440"/>
		<updated>2009-10-09T03:11:02Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.jpg|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Thread-unsafe.jpg&amp;diff=23438</id>
		<title>File:Thread-unsafe.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Thread-unsafe.jpg&amp;diff=23438"/>
		<updated>2009-10-09T03:09:20Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23431</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23431"/>
		<updated>2009-10-09T03:05:32Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.gif|frame|Typical thread-unsafe scenario [4]]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23430</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23430"/>
		<updated>2009-10-09T03:04:00Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.gif| Typical thread-unsafe scenario]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23425</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23425"/>
		<updated>2009-10-09T03:01:51Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Here's an illustration of a thread unsafe scenario. Suppose that your application creates several threads, each of which makes a call to the same library routine such that this library routine accesses/modifies a global structure or location in memory then as each thread calls this routine it is possible that they may try to modify this global structure/memory location at the same time [4]. &lt;br /&gt;
&lt;br /&gt;
[[Image:thread-unsafe.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;br /&gt;
[4] http://www.cdac.in/html/events/beta-test/PEEP-2008-web-page/peep-2008-handson-webpage-mode-1/pthreads-peep-2008/pthreads-peep-2008-overview.html &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Thread-unsafe.gif&amp;diff=23413</id>
		<title>File:Thread-unsafe.gif</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Thread-unsafe.gif&amp;diff=23413"/>
		<updated>2009-10-09T02:55:59Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23397</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23397"/>
		<updated>2009-10-09T02:48:24Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Two important questions arise:&lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23396</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23396"/>
		<updated>2009-10-09T02:48:12Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
Two important questions arise. &lt;br /&gt;
&lt;br /&gt;
1. What are the consequences of running a thread-unsafe program? &amp;lt;br /&amp;gt;&lt;br /&gt;
Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
2. How do we ensure that a particular multi-threaded code is thread safe? &amp;lt;br /&amp;gt;&lt;br /&gt;
Some ways to unsure thread safety are that concurrent threads use synchronized algorithms that cooperate with each other and to confine the address of a shared object to one thread whenever an unasynchronized algorithm is active [1].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23376</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23376"/>
		<updated>2009-10-09T02:31:30Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
&lt;br /&gt;
What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety &amp;lt;br /&amp;gt;&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/ &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23369</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23369"/>
		<updated>2009-10-09T02:29:48Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads and in particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2]. &lt;br /&gt;
What are the consequences of running a thread-unsafe program? Thread programming errors may lead to unpredictable results like data errors possibly followed by fatal application exceptions or endless blocked threads (race-conditions and deadlocks) and these errors are especially difficult to find but easy to introduce by inexperienced programmers [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety&lt;br /&gt;
[3] http://www.multicoreinfo.com/2009/03/thread-safe/&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23354</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23354"/>
		<updated>2009-10-09T02:19:48Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads. In particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html &amp;lt;br /&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23353</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23353"/>
		<updated>2009-10-09T02:19:32Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Thread-Safe Programming and Concurrency Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads [1]. A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads. In particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time [2].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Thread_safety&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23349</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23349"/>
		<updated>2009-10-09T02:17:29Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;br /&gt;
&lt;br /&gt;
==Introduction to Thread-Safe Programming==&lt;br /&gt;
In computer programming, thread-safe describes a program portion or routine that can be called from multiple programming threads without unwanted interaction between the threads.[http://searchcio-midmarket.techtarget.com/sDefinition/0,,sid183_gci331590,00.html] &lt;br /&gt;
A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads. In particular, it must satisfy the need for multiple threads to access the same shared data, and the need for a shared piece of data to be accessed by only one thread at any given time.[http://en.wikipedia.org/wiki/Thread_safety]&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23323</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 14 san</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_14_san&amp;diff=23323"/>
		<updated>2009-10-09T01:39:11Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Thread-Safe Programming and Concurrency Patterns=&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19465</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 rubyvspython</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19465"/>
		<updated>2009-09-16T22:31:39Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby vs. Python=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Python and Ruby are amongst some of the most popular programming languages in use today. Although this page compares and contrasts the two languages, when compared to the other existing languages in the market today, Ruby and Python are almost similar and developed with the same overall goals. However, the differences that do exist have made these two languages the subject of debate between their users. &lt;br /&gt;
  &lt;br /&gt;
===Brief Descriptions===&lt;br /&gt;
&lt;br /&gt;
====Python====&lt;br /&gt;
Python is a [http://en.wikipedia.org/wiki/High-level_programming_language high-level] programming language with a design philosophy that emphasizes code readability, clear syntax and its standard library is large and comprehensive. Its use of indentation as block delimiters is unusual among popular programming languages. Python supports multiple programming paradigms (primarily object-oriented, [http://en.wikipedia.org/wiki/Imperative_programming imperative], and functional), features a fully [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing dynamic] type system and [http://en.wikipedia.org/wiki/Memory_management automatic memory management] and is often used as a scripting language [1].&lt;br /&gt;
&lt;br /&gt;
Here's some sample python code: [2]&lt;br /&gt;
 name = input('What is your name?\n')&lt;br /&gt;
 print('Hi, ' + name + '.')&lt;br /&gt;
&lt;br /&gt;
====Ruby====&lt;br /&gt;
Ruby is a dynamic, general purpose object-oriented programming language developed and designed by Yukihiro &amp;quot;Matz&amp;quot; Matsumoto who wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflective]. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Python [3].&lt;br /&gt;
&lt;br /&gt;
Here's some sample ruby code: [4]&lt;br /&gt;
 puts &amp;quot;What is your name?&amp;quot;&lt;br /&gt;
 $name = STDIN.gets&lt;br /&gt;
 puts &amp;quot;Hi &amp;quot; + $name&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
There are a lot of features that Ruby and Python have in common. So before we compare their differences, its a good idea to list their common features:&lt;br /&gt;
* High-level programming languages (language with strong abstraction from the details of the computer [5]).&lt;br /&gt;
* Everything is an object, and variables are just references to objects [6].&lt;br /&gt;
* Fully dynamic type system&lt;br /&gt;
:A language is dynamically typed when majority of its type checking is performed at run-time as opposed to at compile-time [7].&lt;br /&gt;
* Both provide an interactive prompt [6].&lt;br /&gt;
* Automatic memory management&lt;br /&gt;
:In computer science, garbage collection is a form of automatic memory management. The garbage collector attempts to reclaim garbage, or memory used by objects that are no longer in use by the application [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, let us see how these two languages differ in their features:&lt;br /&gt;
&lt;br /&gt;
''For a brief summary of differences, see [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython#Summary_of_Differences table] below.''&lt;br /&gt;
&lt;br /&gt;
====Strings in Python vs. Strings in Ruby====&lt;br /&gt;
String objects in Python are [http://en.wikipedia.org/wiki/Mutable immutable] whereas in Ruby strings are mutable objects [9]. &lt;br /&gt;
&lt;br /&gt;
An immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. If an object is known to be immutable, it can be copied simply by making a copy of a reference to it instead of copying the entire object. Because a reference is usually much smaller than the object itself, this results in memory savings and a boost in execution speed [10].&lt;br /&gt;
&lt;br /&gt;
So in Python, adding a string to another can create several unwanted intermediate strings and consume memory. In Ruby however, strings can expand as required without consuming much memory or time [9].  &lt;br /&gt;
&lt;br /&gt;
====Defining Private Variables and Methods==== &lt;br /&gt;
In Python &amp;quot;_&amp;quot; is appended in front of a variable or method name to make it private. &lt;br /&gt;
&lt;br /&gt;
In Ruby, all variables defined in a class are by default private and no specific keyword is required to make them so. For making a method private, a method ''private'' is called just before the actual method.&lt;br /&gt;
 private&lt;br /&gt;
   def sample_method_name&lt;br /&gt;
[11]&lt;br /&gt;
&lt;br /&gt;
====Code Blocks vs. Lambdas====&lt;br /&gt;
In Ruby, a code block is an object which contains certain code along with a context required to execute it. A code block can be thought of as a function not bound to a name. This is one of the most distinctive and unique features in Ruby. A code block in Ruby is defined as follows [12]:&lt;br /&gt;
 [1,2,3].each { |i| puts i}&lt;br /&gt;
&lt;br /&gt;
In Python, the concept of code blocks does not exist but the ability of creating unnamed functions can be achieved using [http://www.secnetix.de/olli/Python/lambda_functions.hawk lambdas]. The lambda function acts like any standard function in Python. A lambda may be used as follows [13]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; (lambda x: x*2)(3)&lt;br /&gt;
 8&lt;br /&gt;
&lt;br /&gt;
====Functions and Methods==== &lt;br /&gt;
There are no functions and methods separately in Ruby; all of them are methods. &lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, for example, len() is a function, but items() is a method.&lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 print string.count('o'), len(string)  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, one needs to write self as the first parameter of a method definition. In Ruby, self is automatically available in a similar fashion as ''this'' in C++ [11].&lt;br /&gt;
&lt;br /&gt;
====Multiple Inheritance====&lt;br /&gt;
Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one [http://en.wikipedia.org/wiki/Superclass_(computer_science) superclass]. This contrasts with single inheritance, where a class may inherit from at most one superclass [14].&lt;br /&gt;
&lt;br /&gt;
Python offers support for multiple inheritance and a class definition with multiple base classes looks like this [15]:&lt;br /&gt;
 class DerivedClassName(Base1, Base2, Base3):&lt;br /&gt;
    &amp;lt;statement-1&amp;gt;&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    &amp;lt;statement-N&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby does not support multiple inheritance but provides support so that classes can import modules as mixins [3]. &lt;br /&gt;
A mixin is a class that provides a certain functionality to be inherited by a subclass, while not meant for instantiation (the generating of objects of that class). Inheriting from a mixin is not a form of [http://docs.oasis-open.org/dita/v1.0/archspec/specialize.html specialization] but is rather a means of collecting functionality. A class may inherit most or all of its functionality from one or more mixins through multiple inheritance [16]. &lt;br /&gt;
 require &amp;quot;tcalc&amp;quot;&lt;br /&gt;
 class Invoice&lt;br /&gt;
   include Tcalc    # The line that mixes&lt;br /&gt;
[17]&lt;br /&gt;
&lt;br /&gt;
====Support for Threads==== &lt;br /&gt;
Ruby does not support OS (preemptive) threads and most code is not [http://en.wikipedia.org/wiki/Thread_safety threadsafe]. &lt;br /&gt;
&lt;br /&gt;
Python does support preemptive OS threads which can be used to handle concurrency well when some threads are blocking on external sources (disk access, network IO, waiting on a socket, etc) [18].&lt;br /&gt;
&lt;br /&gt;
====Boolean Values==== &lt;br /&gt;
In Python you have a boolean data type called bool which is a subclass of int and which can either be True or False. Every Python object can either be True or False which is defined by overriding the __nonzero__ method of an object. By default all empty objects (empty lists, dictionaries, tuples, strings etc) are False. This also applies to 0 and 0.0 [19].&lt;br /&gt;
&lt;br /&gt;
In Ruby the situation is completely different. There is no boolean data type but there are two [http://msdn.microsoft.com/en-us/library/ms998426.aspx singletons] (true, instance of TrueClass and false, instance of FalseClass). Everything but nil and false is true. It's also not override-able [19].&lt;br /&gt;
&lt;br /&gt;
====Syntax Differences==== &lt;br /&gt;
* Unlike Python, in Ruby indentation is not significant.&lt;br /&gt;
* In Python, one has to write private instance variables using the long form self.__foobar. In Ruby, the form is @foobar.&lt;br /&gt;
* Ruby provides public, private, and protected to enforce access while Python uses underscore __convention__.&lt;br /&gt;
* Unlike Python, in Ruby parentheses for method calls are usually optional.&lt;br /&gt;
* Ruby uses ''elsif'' instead of ''elif'' as in Python.&lt;br /&gt;
* Ruby uses ''require'' instead of ''import'' as in Python. The usage however remains the same.&lt;br /&gt;
[6]&lt;br /&gt;
&lt;br /&gt;
====Summary of Differences====&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!  !! Python !! Ruby           &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Strings&lt;br /&gt;
| Immutable || Mutable&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Variables&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || private by default&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Methods&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || method private called before actual method&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Code Blocks&lt;br /&gt;
| Do not exist - Lambdas used instead. || Exist.&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Functions and Methods&lt;br /&gt;
| Have a different significance || No difference&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Multiple Inheritance&lt;br /&gt;
| Supported || Not Supported - uses mixins&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Threads&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Boolean Data Type&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Differences in (Web) Programming Environments==&lt;br /&gt;
Web development in Ruby is done using the framework, Ruby on Rails. Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework used with an [http://en.wikipedia.org/wiki/Agile_software_development Agile] development methodology for rapid development. It uses the [http://en.wikipedia.org/wiki/Model-view-controller Model-View-Controller (MVC)] architecture pattern to organize application programming [20]. Considered to be one of the best web development frameworks in the market, Ruby on Rails has helped to substantially increase the popularity of Ruby.&lt;br /&gt;
&lt;br /&gt;
In the case of Python, there are several web development frameworks such as [http://www.djangoproject.com/ Django], [http://grok.zope.org/ Grok], [http://pylonshq.com/ Pylons], [http://turbogears.org/ TurboGears], [http://www.web2py.com/ web2py], [http://www.zope.org/ Zope] [21]. Django is designed with a similar architecture and feature set as Rails to be just as efficient without being just a clone. &lt;br /&gt;
&lt;br /&gt;
So while either frameworks may be used to develop a good web application, there are certain differences in both these frameworks [22]:&lt;br /&gt;
* Django has built in support for developer-friendly templates while Rails needs third party library support.&lt;br /&gt;
* Rails has in-built javascript support while Django has no direct support.&lt;br /&gt;
* In terms of Performance and Scalability, Django is considered better.&lt;br /&gt;
* Lesser number of plugins and support available for Django compared to Rails.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rails has for some time retained the top position in the popularity charts with developers. However, the situation seems to be changing with Django beating Rails since 2008 [23].&lt;br /&gt;
&lt;br /&gt;
[[Image:django-vs-rails.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Interesting Feature(s) Comparison: When is Python or Ruby preferred over the other==&lt;br /&gt;
&lt;br /&gt;
Python may be considered better than Ruby in the following cases [24]:&lt;br /&gt;
* Performance&lt;br /&gt;
:Ruby's interpreter performance trails compared to Python mainly due to the design of the interpreter. To execute Ruby code, the interpreter builds a [http://en.wikipedia.org/wiki/Abstract_syntax_tree syntax tree] from the source code and then evaluates the syntax tree directly, instead of first compiling it into a more efficiently executable form.&lt;br /&gt;
* Threading&lt;br /&gt;
:Ruby's threading model has some inherent limitations which render it difficult to use or unsafe in some scenarios.&lt;br /&gt;
* Unicode&lt;br /&gt;
:Ruby does not yet have native support for Unicode or multibyte strings.&lt;br /&gt;
* Backward compatibility&lt;br /&gt;
:Ruby suffers from backward compatibility problems. &lt;br /&gt;
However, Ruby 2.0 aims to address all of the aforementioned problems.&lt;br /&gt;
&lt;br /&gt;
Ruby may be considered better than Python in the following cases [25]:&lt;br /&gt;
* Ruby on Rails is considered on of the most efficient web development frameworks (see section 1.3 for details).&lt;br /&gt;
* Ruby provides mutable string support (see section 1.2.1 for more details).&lt;br /&gt;
* Ruby supports usage of constants [19].&lt;br /&gt;
&lt;br /&gt;
==Advantages Over Statically Typed Languages==&lt;br /&gt;
A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. Statically typed languages include [http://en.wikipedia.org/wiki/Ada_(programming_language) Ada], C, C++, C#, [http://en.wikipedia.org/wiki/JADE_(programming_language) JADE], Java, Fortran, [http://en.wikipedia.org/wiki/Haskell_(programming_language) Haskell], [http://en.wikipedia.org/wiki/ML_(programming_language) ML], Pascal, Perl and [http://en.wikipedia.org/wiki/Scala_(programming_language) Scala] [26].&lt;br /&gt;
&lt;br /&gt;
====Code Size====&lt;br /&gt;
Python/Ruby are concise and compact as compared to Java which is verbose. This is shown in the example below:&lt;br /&gt;
 &lt;br /&gt;
Python&lt;br /&gt;
 print &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
 public class HelloWorld&lt;br /&gt;
 {&lt;br /&gt;
    public static void main (String[] args)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Static vs. Dynamic====&lt;br /&gt;
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That's what it means to say that Python is a dynamically typed language. Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required [27].&lt;br /&gt;
&lt;br /&gt;
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception. That's what it means to say that Java is a statically typed language. Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn't remember its type, and must be explicitly cast to the desired type [27].&lt;br /&gt;
&lt;br /&gt;
====Flexibility====&lt;br /&gt;
Flexibility of dynamically typed langauges such as Python and Ruby makes writing code significantly easier. Modules are easier to write, and easier to change. There are no build time issues at all [28].&lt;br /&gt;
* Java does not support operator overloading [29].&lt;br /&gt;
* Generators (functions that save state between different results) not present in Java [29].&lt;br /&gt;
* Ruby/Python support [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] as well as the procedural and functional paradigms [30].&lt;br /&gt;
&lt;br /&gt;
==Comparison by Application Domains==&lt;br /&gt;
Since Ruby and Python are almost similar languages built with the same broad goals, we cannot pin point on certain applications that may be built only in Python or Ruby. Yet, due to the certain differences that exist developers may prefer one over the other depending on the application's requirements.&lt;br /&gt;
&lt;br /&gt;
As Rails is one of the most popular web development frameworks, it can be said that Ruby is more popular for web development that Python. Ruby on Rails makes a great framework to develop both small as well as high traffic sites. Ruby is, at present, exceptionally good at one specific kind of small project: database-backed web applications. Ruby on Rails counteracts all of Ruby's small-project disadvantages [31].&lt;br /&gt;
&lt;br /&gt;
Some of the top organizations using Ruby on Rails include NASA, Motorola, Google, Amazon, Cisco, IBM, Oracle, Yahoo [32][33].&lt;br /&gt;
&lt;br /&gt;
Python is better suited to desktop apps on Linux because you can perhaps integrate better to the host platform [34]. Python is believed to give better performance than Ruby and has a large standard library which is why more developers prefer it for areas such as text and numerical processing, operating system interfaces, internet protocols, internet security, software engineering, graphic design. Some of the big companies using Python include Google, Yahoo, CERN and NASA [35][36][1].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Python_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[2] http://wiki.python.org/moin/SimplePrograms&lt;br /&gt;
&amp;lt;br&amp;gt;[3] http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[4] http://www.fincher.org/tips/Languages/Ruby/&lt;br /&gt;
&amp;lt;br&amp;gt;[5] http://en.wikipedia.org/wiki/High-level_programming_language&lt;br /&gt;
&amp;lt;br&amp;gt;[6] http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/&lt;br /&gt;
&amp;lt;br&amp;gt;[7] http://en.wikipedia.org/wiki/Type_system#Dynamic_typing&lt;br /&gt;
&amp;lt;br&amp;gt;[8] http://en.wikipedia.org/wiki/Automatic_memory_management&lt;br /&gt;
&amp;lt;br&amp;gt;[9] http://oreilly.com/catalog/9780596523695/&lt;br /&gt;
&amp;lt;br&amp;gt;[10] http://en.wikipedia.org/wiki/Immutable_object&lt;br /&gt;
&amp;lt;br&amp;gt;[11] http://johan.kiviniemi.name/blag/ruby-vs-python&lt;br /&gt;
&amp;lt;br&amp;gt;[12] http://www.devarticles.com/c/a/Ruby-on-Rails/Code-Blocks-and-Iteration/&lt;br /&gt;
&amp;lt;br&amp;gt;[13] http://www.secnetix.de/olli/Python/lambda_functions.hawk&lt;br /&gt;
&amp;lt;br&amp;gt;[14] http://en.wikipedia.org/wiki/Multiple_inheritance&lt;br /&gt;
&amp;lt;br&amp;gt;[15] http://docs.python.org/tutorial/classes.html&lt;br /&gt;
&amp;lt;br&amp;gt;[16] http://en.wikipedia.org/wiki/Mixin&lt;br /&gt;
&amp;lt;br&amp;gt;[17] http://www.wellho.net/resources/ex.php4?item=r119/mixdem.rb&lt;br /&gt;
&amp;lt;br&amp;gt;[18] http://blog.ianbicking.org/ruby-python-power.html&lt;br /&gt;
&amp;lt;br&amp;gt;[19] http://dev.pocoo.org/~mitsuhiko/pythonruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[20] http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
&amp;lt;br&amp;gt;[21] http://wiki.python.org/moin/WebFrameworks&lt;br /&gt;
&amp;lt;br&amp;gt;[22] http://3columns.net/habitual/docs/RailsVsDjango.pdf&lt;br /&gt;
&amp;lt;br&amp;gt;[23] www.venturedig.com/wordpress/wp-content/uploads/2009/04/django-vs-rails11.jpg&lt;br /&gt;
&amp;lt;br&amp;gt;[24] http://en.wikipedia.org/wiki/Ruby_MRI#Criticism&lt;br /&gt;
&amp;lt;br&amp;gt;[25] Ruby Cookbook: Recipes for Object Oriented Scripting : ISBN 10: 0-596-52369-6 | ISBN 13: 9780596523695&lt;br /&gt;
&amp;lt;br&amp;gt;[26] http://en.wikipedia.org/wiki/Type_system&lt;br /&gt;
&amp;lt;br&amp;gt;[27] http://www.ferg.org/projects/python_java_side-by-side.html&lt;br /&gt;
&amp;lt;br&amp;gt;[28] http://www.artima.com/weblogs/viewpost.jsp?thread=4639&lt;br /&gt;
&amp;lt;br&amp;gt;[29] http://www.razorvine.net/python/PythonComparedToJava&lt;br /&gt;
&amp;lt;br&amp;gt;[30] http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[31] http://www.infoq.com/news/2007/06/rubyvsjava&lt;br /&gt;
&amp;lt;br&amp;gt;[32] http://www.ruby-lang.org/en/documentation/success-stories/&lt;br /&gt;
&amp;lt;br&amp;gt;[33] http://blog.obiefernandez.com/content/2008/03/big-name-compan.html&lt;br /&gt;
&amp;lt;br&amp;gt;[34] http://ubuntuforums.org/showthread.php?t=845563&lt;br /&gt;
&amp;lt;br&amp;gt;[35] http://ubuntuforums.org/archive/index.php/t-416082.html&lt;br /&gt;
&amp;lt;br&amp;gt;[36] http://www.python.org/doc/faq/general&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19451</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 rubyvspython</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19451"/>
		<updated>2009-09-16T22:25:45Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby vs. Python=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Python and Ruby are amongst some of the most popular programming languages in use today. Although this page compares and contrasts the two languages, when compared to the other existing languages in the market today, Ruby and Python are almost similar and developed with the same overall goals. However, the differences that do exist have made these two languages the subject of debate between their users. &lt;br /&gt;
  &lt;br /&gt;
===Brief Descriptions===&lt;br /&gt;
&lt;br /&gt;
====Python====&lt;br /&gt;
Python is a [http://en.wikipedia.org/wiki/High-level_programming_language high-level] programming language with a design philosophy that emphasizes code readability, clear syntax and its standard library is large and comprehensive. Its use of indentation as block delimiters is unusual among popular programming languages. Python supports multiple programming paradigms (primarily object-oriented, [http://en.wikipedia.org/wiki/Imperative_programming imperative], and functional), features a fully [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing dynamic] type system and [http://en.wikipedia.org/wiki/Memory_management automatic memory management] and is often used as a scripting language [1].&lt;br /&gt;
&lt;br /&gt;
Here's some sample python code: [2]&lt;br /&gt;
 name = input('What is your name?\n')&lt;br /&gt;
 print('Hi, ' + name + '.')&lt;br /&gt;
&lt;br /&gt;
====Ruby====&lt;br /&gt;
Ruby is a dynamic, general purpose object-oriented programming language developed and designed by Yukihiro &amp;quot;Matz&amp;quot; Matsumoto who wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflective]. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Python [3].&lt;br /&gt;
&lt;br /&gt;
Here's some sample ruby code: [4]&lt;br /&gt;
 puts &amp;quot;What is your name?&amp;quot;&lt;br /&gt;
 $name = STDIN.gets&lt;br /&gt;
 puts &amp;quot;Hi &amp;quot; + $name&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
There are a lot of features that Ruby and Python have in common. So before we compare their differences, its a good idea to list their common features:&lt;br /&gt;
* High-level programming languages (language with strong abstraction from the details of the computer [5]).&lt;br /&gt;
* Everything is an object, and variables are just references to objects [6].&lt;br /&gt;
* Fully dynamic type system&lt;br /&gt;
:A language is dynamically typed when majority of its type checking is performed at run-time as opposed to at compile-time [7].&lt;br /&gt;
* Both provide an interactive prompt [6].&lt;br /&gt;
* Automatic memory management&lt;br /&gt;
:In computer science, garbage collection is a form of automatic memory management. The garbage collector attempts to reclaim garbage, or memory used by objects that are no longer in use by the application [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, let us see how these two languages differ in their features:&lt;br /&gt;
&lt;br /&gt;
''For a brief summary of differences, see [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython#Summary_of_Differences table] below.''&lt;br /&gt;
&lt;br /&gt;
====Strings in Python vs. Strings in Ruby====&lt;br /&gt;
String objects in Python are [http://en.wikipedia.org/wiki/Mutable immutable] whereas in Ruby strings are mutable objects [9]. &lt;br /&gt;
&lt;br /&gt;
An immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. If an object is known to be immutable, it can be copied simply by making a copy of a reference to it instead of copying the entire object. Because a reference is usually much smaller than the object itself, this results in memory savings and a boost in execution speed [10].&lt;br /&gt;
&lt;br /&gt;
So in Python, adding a string to another can create several unwanted intermediate strings and consume memory. In Ruby however, strings can expand as required without consuming much memory or time [9].  &lt;br /&gt;
&lt;br /&gt;
====Defining Private Variables and Methods==== &lt;br /&gt;
In Python &amp;quot;_&amp;quot; is appended in front of a variable or method name to make it private. &lt;br /&gt;
&lt;br /&gt;
In Ruby, all variables defined in a class are by default private and no specific keyword is required to make them so. For making a method private, a method ''private'' is called just before the actual method.&lt;br /&gt;
 private&lt;br /&gt;
   def sample_method_name&lt;br /&gt;
[11]&lt;br /&gt;
&lt;br /&gt;
====Code Blocks vs. Lambdas====&lt;br /&gt;
In Ruby, a code block is an object which contains certain code along with a context required to execute it. A code block can be thought of as a function not bound to a name. This is one of the most distinctive and unique features in Ruby. A code block in Ruby is defined as follows [12]:&lt;br /&gt;
 [1,2,3].each { |i| puts i}&lt;br /&gt;
&lt;br /&gt;
In Python, the concept of code blocks does not exist but the ability of creating unnamed functions can be achieved using [http://www.secnetix.de/olli/Python/lambda_functions.hawk lambdas]. The lambda function acts like any standard function in Python. A lambda may be used as follows [13]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; (lambda x: x*2)(3)&lt;br /&gt;
 8&lt;br /&gt;
&lt;br /&gt;
====Functions and Methods==== &lt;br /&gt;
There are no functions and methods separately in Ruby; all of them are methods. &lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, for example, len() is a function, but items() is a method.&lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 print string.count('o'), len(string)  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, one needs to write self as the first parameter of a method definition. In Ruby, self is automatically available in a similar fashion as ''this'' in C++ [11].&lt;br /&gt;
&lt;br /&gt;
====Multiple Inheritance====&lt;br /&gt;
Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one [http://en.wikipedia.org/wiki/Superclass_(computer_science) superclass]. This contrasts with single inheritance, where a class may inherit from at most one superclass [14].&lt;br /&gt;
&lt;br /&gt;
Python offers support for multiple inheritance and a class definition with multiple base classes looks like this [15]:&lt;br /&gt;
 class DerivedClassName(Base1, Base2, Base3):&lt;br /&gt;
    &amp;lt;statement-1&amp;gt;&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    &amp;lt;statement-N&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby does not support multiple inheritance but provides support so that classes can import modules as mixins [3]. &lt;br /&gt;
A mixin is a class that provides a certain functionality to be inherited by a subclass, while not meant for instantiation (the generating of objects of that class). Inheriting from a mixin is not a form of [http://docs.oasis-open.org/dita/v1.0/archspec/specialize.html specialization] but is rather a means of collecting functionality. A class may inherit most or all of its functionality from one or more mixins through multiple inheritance [16]. &lt;br /&gt;
 require &amp;quot;tcalc&amp;quot;&lt;br /&gt;
 class Invoice&lt;br /&gt;
   include Tcalc    # The line that mixes&lt;br /&gt;
[17]&lt;br /&gt;
&lt;br /&gt;
====Support for Threads==== &lt;br /&gt;
Ruby does not support OS (preemptive) threads and most code is not [http://en.wikipedia.org/wiki/Thread_safety threadsafe]. &lt;br /&gt;
&lt;br /&gt;
Python does support preemptive OS threads which can be used to handle concurrency well when some threads are blocking on external sources (disk access, network IO, waiting on a socket, etc) [18].&lt;br /&gt;
&lt;br /&gt;
====Boolean Values==== &lt;br /&gt;
In Python you have a boolean data type called bool which is a subclass of int and which can either be True or False. Every Python object can either be True or False which is defined by overriding the __nonzero__ method of an object. By default all empty objects (empty lists, dictionaries, tuples, strings etc) are False. This also applies to 0 and 0.0 [19].&lt;br /&gt;
&lt;br /&gt;
In Ruby the situation is completely different. There is no boolean data type but there are two [http://msdn.microsoft.com/en-us/library/ms998426.aspx singletons] (true, instance of TrueClass and false, instance of FalseClass). Everything but nil and false is true. It's also not override-able [19].&lt;br /&gt;
&lt;br /&gt;
====Syntax Differences==== &lt;br /&gt;
* Unlike Python, in Ruby indentation is not significant.&lt;br /&gt;
* In Python, one has to write private instance variables using the long form self.__foobar. In Ruby, the form is @foobar.&lt;br /&gt;
* Ruby provides public, private, and protected to enforce access while Python uses underscore __convention__.&lt;br /&gt;
* Unlike Python, in Ruby parentheses for method calls are usually optional.&lt;br /&gt;
* Ruby uses ''elsif'' instead of ''elif'' as in Python.&lt;br /&gt;
* Ruby uses ''require'' instead of ''import'' as in Python. The usage however remains the same.&lt;br /&gt;
[6]&lt;br /&gt;
&lt;br /&gt;
====Summary of Differences====&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!  !! Python !! Ruby           &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Strings&lt;br /&gt;
| Immutable || Mutable&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Variables&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || private by default&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Methods&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || method private called before actual method&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Code Blocks&lt;br /&gt;
| Do not exist - Lambdas used instead. || Exist.&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Functions and Methods&lt;br /&gt;
| Have a different significance || No difference&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Multiple Inheritance&lt;br /&gt;
| Supported || Not Supported - uses mixins&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Threads&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Boolean Data Type&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Differences in (Web) Programming Environments==&lt;br /&gt;
Web development in Ruby is done using the framework, Ruby on Rails. Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework used with an [http://en.wikipedia.org/wiki/Agile_software_development Agile] development methodology for rapid development. It uses the [http://en.wikipedia.org/wiki/Model-view-controller Model-View-Controller (MVC)] architecture pattern to organize application programming [20]. Considered to be one of the best web development frameworks in the market, Ruby on Rails has helped to substantially increase the popularity of Ruby.&lt;br /&gt;
&lt;br /&gt;
In the case of Python, there are several web development frameworks such as [http://www.djangoproject.com/ Django], [http://grok.zope.org/ Grok], [http://pylonshq.com/ Pylons], [http://turbogears.org/ TurboGears], [http://www.web2py.com/ web2py], [http://www.zope.org/ Zope] [21]. Django is designed with a similar architecture and feature set as Rails to be just as efficient without being just a clone. &lt;br /&gt;
&lt;br /&gt;
So while either frameworks may be used to develop a good web application, there are certain differences in both these frameworks [22]:&lt;br /&gt;
* Django has built in support for developer-friendly templates while Rails needs third party library support.&lt;br /&gt;
* Rails has in-built javascript support while Django has no direct support.&lt;br /&gt;
* In terms of Performance and Scalability, Django is considered better.&lt;br /&gt;
* Lesser number of plugins and support available for Django compared to Rails.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rails has for some time retained the top position in the popularity charts with developers. However, the situation seems to be changing with Django beating Rails since 2008 [23].&lt;br /&gt;
&lt;br /&gt;
[[Image:django-vs-rails.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Interesting Feature(s) Comparison: When is Python or Ruby preferred over the other==&lt;br /&gt;
&lt;br /&gt;
Python may be considered better than Ruby in the following cases [24]:&lt;br /&gt;
* Performance&lt;br /&gt;
:Ruby's interpreter performance trails compared to Python mainly due to the design of the interpreter. To execute Ruby code, the interpreter builds a [http://en.wikipedia.org/wiki/Abstract_syntax_tree syntax tree] from the source code and then evaluates the syntax tree directly, instead of first compiling it into a more efficiently executable form.&lt;br /&gt;
* Threading&lt;br /&gt;
:Ruby's threading model has some inherent limitations which render it difficult to use or unsafe in some scenarios.&lt;br /&gt;
* Unicode&lt;br /&gt;
:Ruby does not yet have native support for Unicode or multibyte strings.&lt;br /&gt;
* Backward compatibility&lt;br /&gt;
:Ruby suffers from backward compatibility problems. &lt;br /&gt;
However, Ruby 2.0 aims to address all of the aforementioned problems.&lt;br /&gt;
&lt;br /&gt;
Ruby may be considered better than Python in the following cases [25]:&lt;br /&gt;
* Ruby on Rails is considered on of the most efficient web development frameworks (see section 1.3 for details).&lt;br /&gt;
* Ruby provides mutable string support (see section 1.2.1 for more details).&lt;br /&gt;
* Ruby supports usage of constants [19].&lt;br /&gt;
&lt;br /&gt;
==Advantages Over Statically Typed Languages==&lt;br /&gt;
A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. Statically typed languages include Ada, C, C++, C#, JADE, Java, Fortran, Haskell, ML, Pascal, Perl and Scala [26].&lt;br /&gt;
&lt;br /&gt;
====Code Size====&lt;br /&gt;
Python/Ruby are concise and compact as compared to Java which is verbose. This is shown in the example below:&lt;br /&gt;
 &lt;br /&gt;
Python&lt;br /&gt;
 print &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
 public class HelloWorld&lt;br /&gt;
 {&lt;br /&gt;
    public static void main (String[] args)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Static vs. Dynamic====&lt;br /&gt;
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That's what it means to say that Python is a dynamically typed language. Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required [27].&lt;br /&gt;
&lt;br /&gt;
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception. That's what it means to say that Java is a statically typed language. Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn't remember its type, and must be explicitly cast to the desired type [27].&lt;br /&gt;
&lt;br /&gt;
====Flexibility====&lt;br /&gt;
Flexibility of dynamically typed langauges such as Python and Ruby makes writing code significantly easier. Modules are easier to write, and easier to change. There are no build time issues at all [28].&lt;br /&gt;
* Java does not support operator overloading [29].&lt;br /&gt;
* Generators (functions that save state between different results) not present in Java [29].&lt;br /&gt;
* Ruby/Python support [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] as well as the procedural and functional paradigms [30].&lt;br /&gt;
&lt;br /&gt;
==Comparison by Application Domains==&lt;br /&gt;
Since Ruby and Python are almost similar languages built with the same broad goals, we cannot pin point on certain applications that may be built only in Python or Ruby. Yet, due to the certain differences that exist developers may prefer one over the other depending on the application's requirements.&lt;br /&gt;
&lt;br /&gt;
As Rails is one of the most popular web development frameworks, it can be said that Ruby is more popular for web development that Python. Ruby on Rails makes a great framework to develop both small as well as high traffic sites. Ruby is, at present, exceptionally good at one specific kind of small project: database-backed web applications. Ruby on Rails counteracts all of Ruby's small-project disadvantages [31].&lt;br /&gt;
&lt;br /&gt;
Some of the top organizations using Ruby on Rails include NASA, Motorola, Google, Amazon, Cisco, IBM, Oracle, Yahoo [32][33].&lt;br /&gt;
&lt;br /&gt;
Python is better suited to desktop apps on Linux because you can perhaps integrate better to the host platform [34]. Python is believed to give better performance than Ruby and has a large standard library which is why more developers prefer it for areas such as text and numerical processing, operating system interfaces, internet protocols, internet security, software engineering, graphic design. Some of the big companies using Python include Google, Yahoo, CERN and NASA [35][36][1].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Python_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[2] http://wiki.python.org/moin/SimplePrograms&lt;br /&gt;
&amp;lt;br&amp;gt;[3] http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[4] http://www.fincher.org/tips/Languages/Ruby/&lt;br /&gt;
&amp;lt;br&amp;gt;[5] http://en.wikipedia.org/wiki/High-level_programming_language&lt;br /&gt;
&amp;lt;br&amp;gt;[6] http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/&lt;br /&gt;
&amp;lt;br&amp;gt;[7] http://en.wikipedia.org/wiki/Type_system#Dynamic_typing&lt;br /&gt;
&amp;lt;br&amp;gt;[8] http://en.wikipedia.org/wiki/Automatic_memory_management&lt;br /&gt;
&amp;lt;br&amp;gt;[9] http://oreilly.com/catalog/9780596523695/&lt;br /&gt;
&amp;lt;br&amp;gt;[10] http://en.wikipedia.org/wiki/Immutable_object&lt;br /&gt;
&amp;lt;br&amp;gt;[11] http://johan.kiviniemi.name/blag/ruby-vs-python&lt;br /&gt;
&amp;lt;br&amp;gt;[12] http://www.devarticles.com/c/a/Ruby-on-Rails/Code-Blocks-and-Iteration/&lt;br /&gt;
&amp;lt;br&amp;gt;[13] http://www.secnetix.de/olli/Python/lambda_functions.hawk&lt;br /&gt;
&amp;lt;br&amp;gt;[14] http://en.wikipedia.org/wiki/Multiple_inheritance&lt;br /&gt;
&amp;lt;br&amp;gt;[15] http://docs.python.org/tutorial/classes.html&lt;br /&gt;
&amp;lt;br&amp;gt;[16] http://en.wikipedia.org/wiki/Mixin&lt;br /&gt;
&amp;lt;br&amp;gt;[17] http://www.wellho.net/resources/ex.php4?item=r119/mixdem.rb&lt;br /&gt;
&amp;lt;br&amp;gt;[18] http://blog.ianbicking.org/ruby-python-power.html&lt;br /&gt;
&amp;lt;br&amp;gt;[19] http://dev.pocoo.org/~mitsuhiko/pythonruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[20] http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
&amp;lt;br&amp;gt;[21] http://wiki.python.org/moin/WebFrameworks&lt;br /&gt;
&amp;lt;br&amp;gt;[22] http://3columns.net/habitual/docs/RailsVsDjango.pdf&lt;br /&gt;
&amp;lt;br&amp;gt;[23] www.venturedig.com/wordpress/wp-content/uploads/2009/04/django-vs-rails11.jpg&lt;br /&gt;
&amp;lt;br&amp;gt;[24] http://en.wikipedia.org/wiki/Ruby_MRI#Criticism&lt;br /&gt;
&amp;lt;br&amp;gt;[25] Ruby Cookbook: Recipes for Object Oriented Scripting : ISBN 10: 0-596-52369-6 | ISBN 13: 9780596523695&lt;br /&gt;
&amp;lt;br&amp;gt;[26] http://en.wikipedia.org/wiki/Type_system&lt;br /&gt;
&amp;lt;br&amp;gt;[27] http://www.ferg.org/projects/python_java_side-by-side.html&lt;br /&gt;
&amp;lt;br&amp;gt;[28] http://www.artima.com/weblogs/viewpost.jsp?thread=4639&lt;br /&gt;
&amp;lt;br&amp;gt;[29] http://www.razorvine.net/python/PythonComparedToJava&lt;br /&gt;
&amp;lt;br&amp;gt;[30] http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[31] http://www.infoq.com/news/2007/06/rubyvsjava&lt;br /&gt;
&amp;lt;br&amp;gt;[32] http://www.ruby-lang.org/en/documentation/success-stories/&lt;br /&gt;
&amp;lt;br&amp;gt;[33] http://blog.obiefernandez.com/content/2008/03/big-name-compan.html&lt;br /&gt;
&amp;lt;br&amp;gt;[34] http://ubuntuforums.org/showthread.php?t=845563&lt;br /&gt;
&amp;lt;br&amp;gt;[35] http://ubuntuforums.org/archive/index.php/t-416082.html&lt;br /&gt;
&amp;lt;br&amp;gt;[36] http://www.python.org/doc/faq/general&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19436</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 rubyvspython</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19436"/>
		<updated>2009-09-16T22:17:24Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby vs. Python=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Python and Ruby are amongst some of the most popular programming languages in use today. Although this page compares and contrasts the two languages, when compared to the other existing languages in the market today, Ruby and Python are almost similar and developed with the same overall goals. However, the differences that do exist have made these two languages the subject of debate between their users. &lt;br /&gt;
  &lt;br /&gt;
===Brief Descriptions===&lt;br /&gt;
&lt;br /&gt;
====Python====&lt;br /&gt;
Python is a [http://en.wikipedia.org/wiki/High-level_programming_language high-level] programming language with a design philosophy that emphasizes code readability, clear syntax and its standard library is large and comprehensive. Its use of indentation as block delimiters is unusual among popular programming languages. Python supports multiple programming paradigms (primarily object-oriented, [http://en.wikipedia.org/wiki/Imperative_programming imperative], and functional), features a fully [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing dynamic] type system and [http://en.wikipedia.org/wiki/Memory_management automatic memory management] and is often used as a scripting language [1].&lt;br /&gt;
&lt;br /&gt;
Here's some sample python code: [2]&lt;br /&gt;
 name = input('What is your name?\n')&lt;br /&gt;
 print('Hi, ' + name + '.')&lt;br /&gt;
&lt;br /&gt;
====Ruby====&lt;br /&gt;
Ruby is a dynamic, general purpose object-oriented programming language developed and designed by Yukihiro &amp;quot;Matz&amp;quot; Matsumoto who wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflective]. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Python [3].&lt;br /&gt;
&lt;br /&gt;
Here's some sample ruby code: [4]&lt;br /&gt;
 puts &amp;quot;What is your name?&amp;quot;&lt;br /&gt;
 $name = STDIN.gets&lt;br /&gt;
 puts &amp;quot;Hi &amp;quot; + $name&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
There are a lot of features that Ruby and Python have in common. So before we compare their differences, its a good idea to list their common features:&lt;br /&gt;
* High-level programming languages (language with strong abstraction from the details of the computer [5]).&lt;br /&gt;
* Everything is an object, and variables are just references to objects [6].&lt;br /&gt;
* Fully dynamic type system&lt;br /&gt;
:A language is dynamically typed when majority of its type checking is performed at run-time as opposed to at compile-time [7].&lt;br /&gt;
* Both provide an interactive prompt [6].&lt;br /&gt;
* Automatic memory management&lt;br /&gt;
:In computer science, garbage collection is a form of automatic memory management. The garbage collector attempts to reclaim garbage, or memory used by objects that are no longer in use by the application [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, let us see how these two languages differ in their features:&lt;br /&gt;
&lt;br /&gt;
''For a brief summary of differences, see [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython#Summary_of_Differences table] below.''&lt;br /&gt;
&lt;br /&gt;
====Strings in Python vs. Strings in Ruby====&lt;br /&gt;
String objects in Python are [http://en.wikipedia.org/wiki/Mutable immutable] whereas in Ruby strings are mutable objects [9]. &lt;br /&gt;
&lt;br /&gt;
An immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. If an object is known to be immutable, it can be copied simply by making a copy of a reference to it instead of copying the entire object. Because a reference is usually much smaller than the object itself, this results in memory savings and a boost in execution speed [10].&lt;br /&gt;
&lt;br /&gt;
So in Python, adding a string to another can create several unwanted intermediate strings and consume memory. In Ruby however, strings can expand as required without consuming much memory or time [9].  &lt;br /&gt;
&lt;br /&gt;
====Defining Private Variables and Methods==== &lt;br /&gt;
In Python &amp;quot;_&amp;quot; is appended in front of a variable or method name to make it private. &lt;br /&gt;
&lt;br /&gt;
In Ruby, all variables defined in a class are by default private and no specific keyword is required to make them so. For making a method private, a method ''private'' is called just before the actual method.&lt;br /&gt;
 private&lt;br /&gt;
   def sample_method_name&lt;br /&gt;
[11]&lt;br /&gt;
&lt;br /&gt;
====Code Blocks vs. Lambdas====&lt;br /&gt;
In Ruby, a code block is an object which contains certain code along with a context required to execute it. A code block can be thought of as a function not bound to a name. This is one of the most distinctive and unique features in Ruby. A code block in Ruby is defined as follows [12]:&lt;br /&gt;
 [1,2,3].each { |i| puts i}&lt;br /&gt;
&lt;br /&gt;
In Python, the concept of code blocks does not exist but the ability of creating unnamed functions can be achieved using [http://www.secnetix.de/olli/Python/lambda_functions.hawk lambdas]. The lambda function acts like any standard function in Python. A lambda may be used as follows [13]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; (lambda x: x*2)(3)&lt;br /&gt;
 8&lt;br /&gt;
&lt;br /&gt;
====Functions and Methods==== &lt;br /&gt;
There are no functions and methods separately in Ruby; all of them are methods. &lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, for example, len() is a function, but items() is a method.&lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 print string.count('o'), len(string)  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, one needs to write self as the first parameter of a method definition. In Ruby, self is automatically available in a similar fashion as ''this'' in C++ [11].&lt;br /&gt;
&lt;br /&gt;
====Multiple Inheritance====&lt;br /&gt;
Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one [http://en.wikipedia.org/wiki/Superclass_(computer_science) superclass]. This contrasts with single inheritance, where a class may inherit from at most one superclass [14].&lt;br /&gt;
&lt;br /&gt;
Python offers support for multiple inheritance and a class definition with multiple base classes looks like this [15]:&lt;br /&gt;
 class DerivedClassName(Base1, Base2, Base3):&lt;br /&gt;
    &amp;lt;statement-1&amp;gt;&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    &amp;lt;statement-N&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby does not support multiple inheritance but provides support so that classes can import modules as mixins [3]. &lt;br /&gt;
A mixin is a class that provides a certain functionality to be inherited by a subclass, while not meant for instantiation (the generating of objects of that class). Inheriting from a mixin is not a form of [http://docs.oasis-open.org/dita/v1.0/archspec/specialize.html specialization] but is rather a means of collecting functionality. A class may inherit most or all of its functionality from one or more mixins through multiple inheritance [16]. &lt;br /&gt;
 require &amp;quot;tcalc&amp;quot;&lt;br /&gt;
 class Invoice&lt;br /&gt;
   include Tcalc    # The line that mixes&lt;br /&gt;
[17]&lt;br /&gt;
&lt;br /&gt;
====Support for Threads==== &lt;br /&gt;
Ruby does not support OS (preemptive) threads and most code is not [http://en.wikipedia.org/wiki/Thread_safety threadsafe]. &lt;br /&gt;
&lt;br /&gt;
Python does support preemptive OS threads which can be used to handle concurrency well when some threads are blocking on external sources (disk access, network IO, waiting on a socket, etc) [18].&lt;br /&gt;
&lt;br /&gt;
====Boolean Values==== &lt;br /&gt;
In Python you have a boolean data type called bool which is a subclass of int and which can either be True or False. Every Python object can either be True or False which is defined by overriding the __nonzero__ method of an object. By default all empty objects (empty lists, dictionaries, tuples, strings etc) are False. This also applies to 0 and 0.0 [19].&lt;br /&gt;
&lt;br /&gt;
In Ruby the situation is completely different. There is no boolean data type but there are two [http://msdn.microsoft.com/en-us/library/ms998426.aspx singletons] (true, instance of TrueClass and false, instance of FalseClass). Everything but nil and false is true. It's also not override-able [19].&lt;br /&gt;
&lt;br /&gt;
====Syntax Differences==== &lt;br /&gt;
* Unlike Python, in Ruby indentation is not significant.&lt;br /&gt;
* In Python, one has to write private instance variables using the long form self.__foobar. In Ruby, the form is @foobar.&lt;br /&gt;
* Ruby provides public, private, and protected to enforce access while Python uses underscore __convention__.&lt;br /&gt;
* Unlike Python, in Ruby parentheses for method calls are usually optional.&lt;br /&gt;
* Ruby uses ''elsif'' instead of ''elif'' as in Python.&lt;br /&gt;
* Ruby uses ''require'' instead of ''import'' as in Python. The usage however remains the same.&lt;br /&gt;
[6]&lt;br /&gt;
&lt;br /&gt;
====Summary of Differences====&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!  !! Python !! Ruby           &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Strings&lt;br /&gt;
| Immutable || Mutable&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Variables&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || private by default&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Methods&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || method private called before actual method&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Code Blocks&lt;br /&gt;
| Do not exist - Lambdas used instead. || Exist.&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Functions and Methods&lt;br /&gt;
| Have a different significance || No difference&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Multiple Inheritance&lt;br /&gt;
| Supported || Not Supported - uses mixins&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Threads&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Boolean Data Type&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Differences in (Web) Programming Environments==&lt;br /&gt;
Web development in Ruby is done using the framework, Ruby on Rails. Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework used with an [http://en.wikipedia.org/wiki/Agile_software_development Agile] development methodology for rapid development. It uses the [http://en.wikipedia.org/wiki/Model-view-controller Model-View-Controller (MVC)] architecture pattern to organize application programming [20]. Considered to be one of the best web development frameworks in the market, Ruby on Rails has helped to substantially increase the popularity of Ruby.&lt;br /&gt;
&lt;br /&gt;
In the case of Python, there are several web development frameworks such as [http://www.djangoproject.com/ Django], [http://grok.zope.org/ Grok], [http://pylonshq.com/ Pylons], [http://turbogears.org/ TurboGears], [http://www.web2py.com/ web2py], [http://www.zope.org/ Zope] [21]. Django is designed with a similar architecture and feature set as Rails to be just as efficient without being just a clone. &lt;br /&gt;
&lt;br /&gt;
So while either frameworks may be used to develop a good web application, there are certain differences in both these frameworks [22]:&lt;br /&gt;
* Django has built in support for developer-friendly templates while Rails needs third party library support.&lt;br /&gt;
* Rails has in-built javascript support while Django has no direct support.&lt;br /&gt;
* In terms of Performance and Scalability, Django is considered better.&lt;br /&gt;
* Lesser number of plugins and support available for Django compared to Rails.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rails has for some time retained the top position in the popularity charts with developers. However, the situation seems to be changing with Django beating Rails since 2008 [23].&lt;br /&gt;
&lt;br /&gt;
[[Image:django-vs-rails.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Interesting Feature(s) Comparison: When is Python or Ruby preferred over the other==&lt;br /&gt;
&lt;br /&gt;
Python may be considered better than Ruby in the following cases [24]:&lt;br /&gt;
* Performance&lt;br /&gt;
:Ruby's interpreter performance trails compared to Python mainly due to the design of the interpreter. To execute Ruby code, the interpreter builds a [http://en.wikipedia.org/wiki/Abstract_syntax_tree syntax tree] from the source code and then evaluates the syntax tree directly, instead of first compiling it into a more efficiently executable form.&lt;br /&gt;
* Threading&lt;br /&gt;
:Ruby's threading model has some inherent limitations which render it difficult to use or unsafe in some scenarios.&lt;br /&gt;
* Unicode&lt;br /&gt;
:Ruby does not yet have native support for Unicode or multibyte strings.&lt;br /&gt;
* Backward compatibility&lt;br /&gt;
:Ruby suffers from backward compatibility problems. &lt;br /&gt;
However, Ruby 2.0 aims to address all of the aforementioned problems.&lt;br /&gt;
&lt;br /&gt;
Ruby may be considered better than Python in the following cases [25]:&lt;br /&gt;
* Ruby on Rails is considered on of the most efficient web development frameworks (see section 1.3 for details).&lt;br /&gt;
* Ruby provides mutable string support (see section 1.2.1 for more details).&lt;br /&gt;
* Ruby supports usage of constants [19].&lt;br /&gt;
&lt;br /&gt;
==Advantages Over Statically Typed Languages==&lt;br /&gt;
A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. Statically typed languages include Ada, C, C++, C#, JADE, Java, Fortran, Haskell, ML, Pascal, Perl and Scala [26].&lt;br /&gt;
&lt;br /&gt;
====Code Size====&lt;br /&gt;
Python/Ruby are concise and compact as compared to Java which is verbose. This is shown in the example below:&lt;br /&gt;
 &lt;br /&gt;
Python&lt;br /&gt;
 print &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
 public class HelloWorld&lt;br /&gt;
 {&lt;br /&gt;
    public static void main (String[] args)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Static vs. Dynamic====&lt;br /&gt;
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That's what it means to say that Python is a dynamically typed language. Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required [27].&lt;br /&gt;
&lt;br /&gt;
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception. That's what it means to say that Java is a statically typed language. Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn't remember its type, and must be explicitly cast to the desired type [27].&lt;br /&gt;
&lt;br /&gt;
====Flexibility====&lt;br /&gt;
Flexibility of dynamically typed langauges such as Python and Ruby makes writing code significantly easier. Modules are easier to write, and easier to change. There are no build time issues at all [28].&lt;br /&gt;
* Java does not support operator overloading [29].&lt;br /&gt;
* Generators (functions that save state between different results) not present in Java [29].&lt;br /&gt;
* Ruby/Python support metaprogramming as well as the procedural and functional paradigms [30].&lt;br /&gt;
&lt;br /&gt;
==Comparison by Application Domains==&lt;br /&gt;
Since Ruby and Python are almost similar languages built with the same broad goals, we cannot pin point on certain applications that may be built only in Python or Ruby. Yet, due to the certain differences that exist developers may prefer one over the other depending on the application's requirements.&lt;br /&gt;
&lt;br /&gt;
As Rails is one of the most popular web development frameworks, it can be said that Ruby is more popular for web development that Python. Ruby on Rails makes a great framework to develop both small as well as high traffic sites. Ruby is, at present, exceptionally good at one specific kind of small project: database-backed web applications. Ruby on Rails counteracts all of Ruby's small-project disadvantages [31].&lt;br /&gt;
&lt;br /&gt;
Some of the top organizations using Ruby on Rails include NASA, Motorola, Google, Amazon, Cisco, IBM, Oracle, Yahoo [32][33].&lt;br /&gt;
&lt;br /&gt;
Python is better suited to desktop apps on Linux because you can perhaps integrate better to the host platform [34]. Python is believed to give better performance than Ruby and has a large standard library which is why more developers prefer it for areas such as text and numerical processing, operating system interfaces, internet protocols, internet security, software engineering, graphic design. Some of the big companies using Python include Google, Yahoo, CERN and NASA [35][36][1].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Python_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[2] http://wiki.python.org/moin/SimplePrograms&lt;br /&gt;
&amp;lt;br&amp;gt;[3] http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[4] http://www.fincher.org/tips/Languages/Ruby/&lt;br /&gt;
&amp;lt;br&amp;gt;[5] http://en.wikipedia.org/wiki/High-level_programming_language&lt;br /&gt;
&amp;lt;br&amp;gt;[6] http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/&lt;br /&gt;
&amp;lt;br&amp;gt;[7] http://en.wikipedia.org/wiki/Type_system#Dynamic_typing&lt;br /&gt;
&amp;lt;br&amp;gt;[8] http://en.wikipedia.org/wiki/Automatic_memory_management&lt;br /&gt;
&amp;lt;br&amp;gt;[9] http://oreilly.com/catalog/9780596523695/&lt;br /&gt;
&amp;lt;br&amp;gt;[10] http://en.wikipedia.org/wiki/Immutable_object&lt;br /&gt;
&amp;lt;br&amp;gt;[11] http://johan.kiviniemi.name/blag/ruby-vs-python&lt;br /&gt;
&amp;lt;br&amp;gt;[12] http://www.devarticles.com/c/a/Ruby-on-Rails/Code-Blocks-and-Iteration/&lt;br /&gt;
&amp;lt;br&amp;gt;[13] http://www.secnetix.de/olli/Python/lambda_functions.hawk&lt;br /&gt;
&amp;lt;br&amp;gt;[14] http://en.wikipedia.org/wiki/Multiple_inheritance&lt;br /&gt;
&amp;lt;br&amp;gt;[15] http://docs.python.org/tutorial/classes.html&lt;br /&gt;
&amp;lt;br&amp;gt;[16] http://en.wikipedia.org/wiki/Mixin&lt;br /&gt;
&amp;lt;br&amp;gt;[17] http://www.wellho.net/resources/ex.php4?item=r119/mixdem.rb&lt;br /&gt;
&amp;lt;br&amp;gt;[18] http://blog.ianbicking.org/ruby-python-power.html&lt;br /&gt;
&amp;lt;br&amp;gt;[19] http://dev.pocoo.org/~mitsuhiko/pythonruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[20] http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
&amp;lt;br&amp;gt;[21] http://wiki.python.org/moin/WebFrameworks&lt;br /&gt;
&amp;lt;br&amp;gt;[22] http://3columns.net/habitual/docs/RailsVsDjango.pdf&lt;br /&gt;
&amp;lt;br&amp;gt;[23] www.venturedig.com/wordpress/wp-content/uploads/2009/04/django-vs-rails11.jpg&lt;br /&gt;
&amp;lt;br&amp;gt;[24] http://en.wikipedia.org/wiki/Ruby_MRI#Criticism&lt;br /&gt;
&amp;lt;br&amp;gt;[25] Ruby Cookbook: Recipes for Object Oriented Scripting : ISBN 10: 0-596-52369-6 | ISBN 13: 9780596523695&lt;br /&gt;
&amp;lt;br&amp;gt;[26] http://en.wikipedia.org/wiki/Type_system&lt;br /&gt;
&amp;lt;br&amp;gt;[27] http://www.ferg.org/projects/python_java_side-by-side.html&lt;br /&gt;
&amp;lt;br&amp;gt;[28] http://www.artima.com/weblogs/viewpost.jsp?thread=4639&lt;br /&gt;
&amp;lt;br&amp;gt;[29] http://www.razorvine.net/python/PythonComparedToJava&lt;br /&gt;
&amp;lt;br&amp;gt;[30] http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[31] http://www.infoq.com/news/2007/06/rubyvsjava&lt;br /&gt;
&amp;lt;br&amp;gt;[32] http://www.ruby-lang.org/en/documentation/success-stories/&lt;br /&gt;
&amp;lt;br&amp;gt;[33] http://blog.obiefernandez.com/content/2008/03/big-name-compan.html&lt;br /&gt;
&amp;lt;br&amp;gt;[34] http://ubuntuforums.org/showthread.php?t=845563&lt;br /&gt;
&amp;lt;br&amp;gt;[35] http://ubuntuforums.org/archive/index.php/t-416082.html&lt;br /&gt;
&amp;lt;br&amp;gt;[36] http://www.python.org/doc/faq/general&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19416</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 rubyvspython</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19416"/>
		<updated>2009-09-16T21:55:35Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby vs. Python=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Python and Ruby are amongst some of the most popular programming languages in use today. Although this page compares and contrasts the two languages, when compared to the other existing languages in the market today, Ruby and Python are almost similar and developed with the same overall goals. However, the differences that do exist have made these two languages the subject of debate between their users. &lt;br /&gt;
  &lt;br /&gt;
===Brief Descriptions===&lt;br /&gt;
&lt;br /&gt;
====Python====&lt;br /&gt;
Python is a [http://en.wikipedia.org/wiki/High-level_programming_language high-level] programming language with a design philosophy that emphasizes code readability, clear syntax and its standard library is large and comprehensive. Its use of indentation as block delimiters is unusual among popular programming languages. Python supports multiple programming paradigms (primarily object-oriented, [http://en.wikipedia.org/wiki/Imperative_programming imperative], and functional), features a fully [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing dynamic] type system and [http://en.wikipedia.org/wiki/Memory_management automatic memory management] and is often used as a scripting language [1].&lt;br /&gt;
&lt;br /&gt;
Here's some sample python code: [2]&lt;br /&gt;
 name = input('What is your name?\n')&lt;br /&gt;
 print('Hi, ' + name + '.')&lt;br /&gt;
&lt;br /&gt;
====Ruby====&lt;br /&gt;
Ruby is a dynamic, general purpose object-oriented programming language developed and designed by Yukihiro &amp;quot;Matz&amp;quot; Matsumoto who wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflective]. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Python [3].&lt;br /&gt;
&lt;br /&gt;
Here's some sample ruby code: [4]&lt;br /&gt;
 puts &amp;quot;What is your name?&amp;quot;&lt;br /&gt;
 $name = STDIN.gets&lt;br /&gt;
 puts &amp;quot;Hi &amp;quot; + $name&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
There are a lot of features that Ruby and Python have in common. So before we compare their differences, its a good idea to list their common features:&lt;br /&gt;
* High-level programming languages (language with strong abstraction from the details of the computer [5]).&lt;br /&gt;
* Everything is an object, and variables are just references to objects [6].&lt;br /&gt;
* Fully dynamic type system&lt;br /&gt;
:A language is dynamically typed when majority of its type checking is performed at run-time as opposed to at compile-time [7].&lt;br /&gt;
* Both provide an interactive prompt [6].&lt;br /&gt;
* Automatic memory management&lt;br /&gt;
:In computer science, garbage collection is a form of automatic memory management. The garbage collector attempts to reclaim garbage, or memory used by objects that are no longer in use by the application [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, let us see how these two languages differ in their features:&lt;br /&gt;
&lt;br /&gt;
''For a brief summary of differences, see [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython#Summary_of_Differences table] below.''&lt;br /&gt;
&lt;br /&gt;
====Strings in Python vs. Strings in Ruby====&lt;br /&gt;
String objects in Python are [http://en.wikipedia.org/wiki/Mutable immutable] whereas in Ruby strings are mutable objects [9]. &lt;br /&gt;
&lt;br /&gt;
An immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. If an object is known to be immutable, it can be copied simply by making a copy of a reference to it instead of copying the entire object. Because a reference is usually much smaller than the object itself, this results in memory savings and a boost in execution speed [10].&lt;br /&gt;
&lt;br /&gt;
So in Python, adding a string to another can create several unwanted intermediate strings and consume memory. In Ruby however, strings can expand as required without consuming much memory or time [9].  &lt;br /&gt;
&lt;br /&gt;
====Defining Private Variables and Methods==== &lt;br /&gt;
In Python &amp;quot;_&amp;quot; is appended in front of a variable or method name to make it private. &lt;br /&gt;
&lt;br /&gt;
In Ruby, all variables defined in a class are by default private and no specific keyword is required to make them so. For making a method private, a method ''private'' is called just before the actual method.&lt;br /&gt;
 private&lt;br /&gt;
   def sample_method_name&lt;br /&gt;
[11]&lt;br /&gt;
&lt;br /&gt;
====Code Blocks vs. Lambdas====&lt;br /&gt;
In Ruby, a code block is an object which contains certain code along with a context required to execute it. A code block can be thought of as a function not bound to a name. This is one of the most distinctive and unique features in Ruby. A code block in Ruby is defined as follows [12]:&lt;br /&gt;
 [1,2,3].each { |i| puts i}&lt;br /&gt;
&lt;br /&gt;
In Python, the concept of code blocks does not exist but the ability of creating unnamed functions can be achieved using [http://www.secnetix.de/olli/Python/lambda_functions.hawk lambdas]. The lambda function acts like any standard function in Python. A lambda may be used as follows [13]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; (lambda x: x*2)(3)&lt;br /&gt;
 8&lt;br /&gt;
&lt;br /&gt;
====Functions and Methods==== &lt;br /&gt;
There are no functions and methods separately in Ruby; all of them are methods. &lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, for example, len() is a function, but items() is a method.&lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 print string.count('o'), len(string)  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, one needs to write self as the first parameter of a method definition. In Ruby, self is automatically available in a similar fashion as ''this'' in C++ [11].&lt;br /&gt;
&lt;br /&gt;
====Multiple Inheritance====&lt;br /&gt;
Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one [http://en.wikipedia.org/wiki/Superclass_(computer_science) superclass]. This contrasts with single inheritance, where a class may inherit from at most one superclass [14].&lt;br /&gt;
&lt;br /&gt;
Python offers support for multiple inheritance and a class definition with multiple base classes looks like this [15]:&lt;br /&gt;
 class DerivedClassName(Base1, Base2, Base3):&lt;br /&gt;
    &amp;lt;statement-1&amp;gt;&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    &amp;lt;statement-N&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby does not support multiple inheritance but provides support so that classes can import modules as mixins [3]. &lt;br /&gt;
A mixin is a class that provides a certain functionality to be inherited by a subclass, while not meant for instantiation (the generating of objects of that class). Inheriting from a mixin is not a form of specialization but is rather a means of collecting functionality. A class may inherit most or all of its functionality from one or more mixins through multiple inheritance [16]. &lt;br /&gt;
 require &amp;quot;tcalc&amp;quot;&lt;br /&gt;
 class Invoice&lt;br /&gt;
   include Tcalc    # The line that mixes&lt;br /&gt;
[17]&lt;br /&gt;
&lt;br /&gt;
====Support for Threads==== &lt;br /&gt;
Ruby does not support OS (preemptive) threads and most code is not threadsafe. &lt;br /&gt;
&lt;br /&gt;
Python does support preemptive OS threads which can be used to handle concurrency well when some threads are blocking on external sources (disk access, network IO, waiting on a socket, etc) [18].&lt;br /&gt;
&lt;br /&gt;
====Boolean Values==== &lt;br /&gt;
In Python you have a boolean data type called bool which is a subclass of int and which can either be True or False. Every Python object can either be True or False which is defined by overriding the __nonzero__ method of an object. By default all empty objects (empty lists, dicts, tuples, strings etc) are False. This also applies to 0 and 0.0 [19].&lt;br /&gt;
&lt;br /&gt;
In Ruby the situation is completely different. There is no boolean data type but there are two singletons (true, instance of TrueClass and false, instance of FalseClass). Everything but nil and false is true. It's also not override-able [19].&lt;br /&gt;
&lt;br /&gt;
====Syntax Differences==== &lt;br /&gt;
* Unlike Python, in Ruby indentation is not significant.&lt;br /&gt;
* In Python, one has to write private instance variables using the long form self.__foobar. In Ruby, the form is @foobar.&lt;br /&gt;
* Ruby provides public, private, and protected to enforce access while Python uses underscore __convention__.&lt;br /&gt;
* Unlike Python, in Ruby parentheses for method calls are usually optional.&lt;br /&gt;
* Ruby uses ''elsif'' instead of ''elif'' as in Python.&lt;br /&gt;
* Ruby uses ''require'' instead of ''import'' as in Python. The usage however remains the same.&lt;br /&gt;
[6]&lt;br /&gt;
&lt;br /&gt;
====Summary of Differences====&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!  !! Python !! Ruby           &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Strings&lt;br /&gt;
| Immutable || Mutable&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Variables&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || private by default&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Methods&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || method private called before actual method&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Code Blocks&lt;br /&gt;
| Do not exist - Lambdas used instead. || Exist.&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Functions and Methods&lt;br /&gt;
| Have a different significance || No difference&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Multiple Inheritance&lt;br /&gt;
| Supported || Not Supported - uses mixins&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Threads&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Boolean Data Type&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Differences in (Web) Programming Environments==&lt;br /&gt;
Web development in Ruby is done using the framework, Ruby on Rails. Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework used with an Agile development methodology for rapid development. It uses the Model-View-Controller (MVC) architecture pattern to organize application programming [20]. Considered to be one of the best web development frameworks in the market, Ruby on Rails has helped to substantially increase the popularity of Ruby.&lt;br /&gt;
&lt;br /&gt;
In the case of Python, there are several web development frameworks such as Django, Grok, Pylons, TurboGears, web2py, Zope [21]. Django is designed with a similar architecture and feature set as Rails to be just as efficient without being just a clone. &lt;br /&gt;
&lt;br /&gt;
So while either frameworks may be used to develop a good web application, there are certain differences in both these frameworks [22]:&lt;br /&gt;
* Django has built in support for developer-friendly templates while Rails needs third party library support.&lt;br /&gt;
* Rails has in-built javascript support while Django has no direct support.&lt;br /&gt;
* In terms of Performance and Scalability, Django is considered better.&lt;br /&gt;
* Lesser number of plugins and support available for Django compared to Rails.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rails has for some time retained the top position in the popularity charts with developers. However, the situation seems to be changing with Django beating Rails since 2008 [23].&lt;br /&gt;
&lt;br /&gt;
[[Image:django-vs-rails.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Interesting Feature(s) Comparison: When is Python or Ruby preferred over the other==&lt;br /&gt;
&lt;br /&gt;
Python may be considered better than Ruby in the following cases [24]:&lt;br /&gt;
* Performance&lt;br /&gt;
:Ruby's interpreter performance trails compared to Python mainly due to the design of the interpreter. To execute Ruby code, the interpreter builds a syntax tree from the source code and then evaluates the syntax tree directly, instead of first compiling it into a more efficiently executable form.&lt;br /&gt;
* Threading&lt;br /&gt;
:Ruby's threading model has some inherent limitations which render it difficult to use or unsafe in some scenarios.&lt;br /&gt;
* Unicode&lt;br /&gt;
:Ruby does not yet have native support for Unicode or multibyte strings.&lt;br /&gt;
* Backward compatibility&lt;br /&gt;
:Ruby suffers from backward compatibility problems. &lt;br /&gt;
However, Ruby 2.0 aims to address all of the aforementioned problems.&lt;br /&gt;
&lt;br /&gt;
Ruby may be considered better than Python in the following cases [25]:&lt;br /&gt;
* Ruby on Rails is considered on of the most efficient web development frameworks (see section 1.3 for details).&lt;br /&gt;
* Ruby provides mutable string support (see section 1.2.1 for more details).&lt;br /&gt;
* Ruby supports usage of constants [19].&lt;br /&gt;
&lt;br /&gt;
==Advantages Over Statically Typed Languages==&lt;br /&gt;
A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. Statically typed languages include Ada, C, C++, C#, JADE, Java, Fortran, Haskell, ML, Pascal, Perl and Scala [26].&lt;br /&gt;
&lt;br /&gt;
====Code Size====&lt;br /&gt;
Python/Ruby are concise and compact as compared to Java which is verbose. This is shown in the example below:&lt;br /&gt;
 &lt;br /&gt;
Python&lt;br /&gt;
 print &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
 public class HelloWorld&lt;br /&gt;
 {&lt;br /&gt;
    public static void main (String[] args)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Static vs. Dynamic====&lt;br /&gt;
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That's what it means to say that Python is a dynamically typed language. Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required [27].&lt;br /&gt;
&lt;br /&gt;
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception. That's what it means to say that Java is a statically typed language. Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn't remember its type, and must be explicitly cast to the desired type [27].&lt;br /&gt;
&lt;br /&gt;
====Flexibility====&lt;br /&gt;
Flexibility of dynamically typed langauges such as Python and Ruby makes writing code significantly easier. Modules are easier to write, and easier to change. There are no build time issues at all [28].&lt;br /&gt;
* Java does not support operator overloading [29].&lt;br /&gt;
* Generators (functions that save state between different results) not present in Java [29].&lt;br /&gt;
* Ruby/Python support metaprogramming as well as the procedural and functional paradigms [30].&lt;br /&gt;
&lt;br /&gt;
==Comparison by Application Domains==&lt;br /&gt;
Since Ruby and Python are almost similar languages built with the same broad goals, we cannot pin point on certain applications that may be built only in Python or Ruby. Yet, due to the certain differences that exist developers may prefer one over the other depending on the application's requirements.&lt;br /&gt;
&lt;br /&gt;
As Rails is one of the most popular web development frameworks, it can be said that Ruby is more popular for web development that Python. Ruby on Rails makes a great framework to develop both small as well as high traffic sites. Ruby is, at present, exceptionally good at one specific kind of small project: database-backed web applications. Ruby on Rails counteracts all of Ruby's small-project disadvantages [31].&lt;br /&gt;
&lt;br /&gt;
Some of the top organizations using Ruby on Rails include NASA, Motorola, Google, Amazon, Cisco, IBM, Oracle, Yahoo [32][33].&lt;br /&gt;
&lt;br /&gt;
Python is better suited to desktop apps on Linux because you can perhaps integrate better to the host platform [34]. Python is believed to give better performance than Ruby and has a large standard library which is why more developers prefer it for areas such as text and numerical processing, operating system interfaces, internet protocols, internet security, software engineering, graphic design. Some of the big companies using Python include Google, Yahoo, CERN and NASA [35][36][1].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Python_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[2] http://wiki.python.org/moin/SimplePrograms&lt;br /&gt;
&amp;lt;br&amp;gt;[3] http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[4] http://www.fincher.org/tips/Languages/Ruby/&lt;br /&gt;
&amp;lt;br&amp;gt;[5] http://en.wikipedia.org/wiki/High-level_programming_language&lt;br /&gt;
&amp;lt;br&amp;gt;[6] http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/&lt;br /&gt;
&amp;lt;br&amp;gt;[7] http://en.wikipedia.org/wiki/Type_system#Dynamic_typing&lt;br /&gt;
&amp;lt;br&amp;gt;[8] http://en.wikipedia.org/wiki/Automatic_memory_management&lt;br /&gt;
&amp;lt;br&amp;gt;[9] http://oreilly.com/catalog/9780596523695/&lt;br /&gt;
&amp;lt;br&amp;gt;[10] http://en.wikipedia.org/wiki/Immutable_object&lt;br /&gt;
&amp;lt;br&amp;gt;[11] http://johan.kiviniemi.name/blag/ruby-vs-python&lt;br /&gt;
&amp;lt;br&amp;gt;[12] http://www.devarticles.com/c/a/Ruby-on-Rails/Code-Blocks-and-Iteration/&lt;br /&gt;
&amp;lt;br&amp;gt;[13] http://www.secnetix.de/olli/Python/lambda_functions.hawk&lt;br /&gt;
&amp;lt;br&amp;gt;[14] http://en.wikipedia.org/wiki/Multiple_inheritance&lt;br /&gt;
&amp;lt;br&amp;gt;[15] http://docs.python.org/tutorial/classes.html&lt;br /&gt;
&amp;lt;br&amp;gt;[16] http://en.wikipedia.org/wiki/Mixin&lt;br /&gt;
&amp;lt;br&amp;gt;[17] http://www.wellho.net/resources/ex.php4?item=r119/mixdem.rb&lt;br /&gt;
&amp;lt;br&amp;gt;[18] http://blog.ianbicking.org/ruby-python-power.html&lt;br /&gt;
&amp;lt;br&amp;gt;[19] http://dev.pocoo.org/~mitsuhiko/pythonruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[20] http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
&amp;lt;br&amp;gt;[21] http://wiki.python.org/moin/WebFrameworks&lt;br /&gt;
&amp;lt;br&amp;gt;[22] http://3columns.net/habitual/docs/RailsVsDjango.pdf&lt;br /&gt;
&amp;lt;br&amp;gt;[23] www.venturedig.com/wordpress/wp-content/uploads/2009/04/django-vs-rails11.jpg&lt;br /&gt;
&amp;lt;br&amp;gt;[24] http://en.wikipedia.org/wiki/Ruby_MRI#Criticism&lt;br /&gt;
&amp;lt;br&amp;gt;[25] Ruby Cookbook: Recipes for Object Oriented Scripting : ISBN 10: 0-596-52369-6 | ISBN 13: 9780596523695&lt;br /&gt;
&amp;lt;br&amp;gt;[26] http://en.wikipedia.org/wiki/Type_system&lt;br /&gt;
&amp;lt;br&amp;gt;[27] http://www.ferg.org/projects/python_java_side-by-side.html&lt;br /&gt;
&amp;lt;br&amp;gt;[28] http://www.artima.com/weblogs/viewpost.jsp?thread=4639&lt;br /&gt;
&amp;lt;br&amp;gt;[29] http://www.razorvine.net/python/PythonComparedToJava&lt;br /&gt;
&amp;lt;br&amp;gt;[30] http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[31] http://www.infoq.com/news/2007/06/rubyvsjava&lt;br /&gt;
&amp;lt;br&amp;gt;[32] http://www.ruby-lang.org/en/documentation/success-stories/&lt;br /&gt;
&amp;lt;br&amp;gt;[33] http://blog.obiefernandez.com/content/2008/03/big-name-compan.html&lt;br /&gt;
&amp;lt;br&amp;gt;[34] http://ubuntuforums.org/showthread.php?t=845563&lt;br /&gt;
&amp;lt;br&amp;gt;[35] http://ubuntuforums.org/archive/index.php/t-416082.html&lt;br /&gt;
&amp;lt;br&amp;gt;[36] http://www.python.org/doc/faq/general&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19408</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 rubyvspython</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19408"/>
		<updated>2009-09-16T21:43:39Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby vs. Python=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Python and Ruby are amongst some of the most popular programming languages in use today. Although this page compares and contrasts the two languages, when compared to the other existing languages in the market today, Ruby and Python are almost similar and developed with the same overall goals. However, the differences that do exist have made these two languages the subject of debate between their users. &lt;br /&gt;
  &lt;br /&gt;
===Brief Descriptions===&lt;br /&gt;
&lt;br /&gt;
====Python====&lt;br /&gt;
Python is a [http://en.wikipedia.org/wiki/High-level_programming_language high-level] programming language with a design philosophy that emphasizes code readability, clear syntax and its standard library is large and comprehensive. Its use of indentation as block delimiters is unusual among popular programming languages. Python supports multiple programming paradigms (primarily object-oriented, [http://en.wikipedia.org/wiki/Imperative_programming imperative], and functional), features a fully [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing dynamic] type system and [http://en.wikipedia.org/wiki/Memory_management automatic memory management] and is often used as a scripting language [1].&lt;br /&gt;
&lt;br /&gt;
Here's some sample python code: [2]&lt;br /&gt;
 name = input('What is your name?\n')&lt;br /&gt;
 print('Hi, ' + name + '.')&lt;br /&gt;
&lt;br /&gt;
====Ruby====&lt;br /&gt;
Ruby is a dynamic, general purpose object-oriented programming language developed and designed by Yukihiro &amp;quot;Matz&amp;quot; Matsumoto who wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflective]. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Python [3].&lt;br /&gt;
&lt;br /&gt;
Here's some sample ruby code: [4]&lt;br /&gt;
 puts &amp;quot;What is your name?&amp;quot;&lt;br /&gt;
 $name = STDIN.gets&lt;br /&gt;
 puts &amp;quot;Hi &amp;quot; + $name&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
There are a lot of features that Ruby and Python have in common. So before we compare their differences, its a good idea to list their common features:&lt;br /&gt;
* High-level programming languages (language with strong abstraction from the details of the computer [5]).&lt;br /&gt;
* Everything is an object, and variables are just references to objects [6].&lt;br /&gt;
* Fully dynamic type system&lt;br /&gt;
:A language is dynamically typed when majority of its type checking is performed at run-time as opposed to at compile-time [7].&lt;br /&gt;
* Both provide an interactive prompt [6].&lt;br /&gt;
* Automatic memory management&lt;br /&gt;
:In computer science, garbage collection is a form of automatic memory management. The garbage collector attempts to reclaim garbage, or memory used by objects that are no longer in use by the application [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, let us see how these two languages differ in their features:&lt;br /&gt;
&lt;br /&gt;
''For a brief summary of differences, see [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython#Summary_of_Differences table] below.''&lt;br /&gt;
&lt;br /&gt;
====Strings in Python vs. Strings in Ruby====&lt;br /&gt;
String objects in Python are immutable whereas in Ruby strings are mutable objects [9]. &lt;br /&gt;
&lt;br /&gt;
An immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. If an object is known to be immutable, it can be copied simply by making a copy of a reference to it instead of copying the entire object. Because a reference is usually much smaller than the object itself, this results in memory savings and a boost in execution speed [10].&lt;br /&gt;
&lt;br /&gt;
So in Python, adding a string to another can create several unwanted intermediate strings and consume memory. In Ruby however, strings can expand as required without consuming much memory or time [9].  &lt;br /&gt;
&lt;br /&gt;
====Defining Private Variables and Methods==== &lt;br /&gt;
In Python &amp;quot;_&amp;quot; is appended in front of a variable or method name to make it private. &lt;br /&gt;
&lt;br /&gt;
In Ruby, all variables defined in a class are by default private and no specific keyword is required to make them so. For making a method private, a method ''private'' is called just before the actual method.&lt;br /&gt;
 private&lt;br /&gt;
   def sample_method_name&lt;br /&gt;
[11]&lt;br /&gt;
&lt;br /&gt;
====Code Blocks vs. Lambdas====&lt;br /&gt;
In Ruby, a code block is an object which contains certain code along with a context required to execute it. A code block can be thought of as a function not bound to a name. This is one of the most distinctive and unique features in Ruby. A code block in Ruby is defined as follows [12]:&lt;br /&gt;
 [1,2,3].each { |i| puts i}&lt;br /&gt;
&lt;br /&gt;
In Python, the concept of code blocks does not exist but the ability of creating unnamed functions can be achieved using lambdas. The lambda function acts like any standard function in Python. A lambda may be used as follows [13]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; (lambda x: x*2)(3)&lt;br /&gt;
 8&lt;br /&gt;
&lt;br /&gt;
====Functions and Methods==== &lt;br /&gt;
There are no functions and methods separately in Ruby; all of them are methods. &lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, for example, len() is a function, but items() is a method.&lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 print string.count('o'), len(string)  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, one needs to write self as the first parameter of a method definition. In Ruby, self is automatically available in a similar fashion as ''this'' in C++ [11].&lt;br /&gt;
&lt;br /&gt;
====Multiple Inheritance====&lt;br /&gt;
Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. This contrasts with single inheritance, where a class may inherit from at most one superclass [14].&lt;br /&gt;
&lt;br /&gt;
Python offers support for multiple inheritance and a class definition with multiple base classes looks like this [15]:&lt;br /&gt;
 class DerivedClassName(Base1, Base2, Base3):&lt;br /&gt;
    &amp;lt;statement-1&amp;gt;&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    &amp;lt;statement-N&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby does not support multiple inheritance but provides support so that classes can import modules as mixins [3]. &lt;br /&gt;
A mixin is a class that provides a certain functionality to be inherited by a subclass, while not meant for instantiation (the generating of objects of that class). Inheriting from a mixin is not a form of specialization but is rather a means of collecting functionality. A class may inherit most or all of its functionality from one or more mixins through multiple inheritance [16]. &lt;br /&gt;
 require &amp;quot;tcalc&amp;quot;&lt;br /&gt;
 class Invoice&lt;br /&gt;
   include Tcalc    # The line that mixes&lt;br /&gt;
[17]&lt;br /&gt;
&lt;br /&gt;
====Support for Threads==== &lt;br /&gt;
Ruby does not support OS (preemptive) threads and most code is not threadsafe. &lt;br /&gt;
&lt;br /&gt;
Python does support preemptive OS threads which can be used to handle concurrency well when some threads are blocking on external sources (disk access, network IO, waiting on a socket, etc) [18].&lt;br /&gt;
&lt;br /&gt;
====Boolean Values==== &lt;br /&gt;
In Python you have a boolean data type called bool which is a subclass of int and which can either be True or False. Every Python object can either be True or False which is defined by overriding the __nonzero__ method of an object. By default all empty objects (empty lists, dicts, tuples, strings etc) are False. This also applies to 0 and 0.0 [19].&lt;br /&gt;
&lt;br /&gt;
In Ruby the situation is completely different. There is no boolean data type but there are two singletons (true, instance of TrueClass and false, instance of FalseClass). Everything but nil and false is true. It's also not override-able [19].&lt;br /&gt;
&lt;br /&gt;
====Syntax Differences==== &lt;br /&gt;
* Unlike Python, in Ruby indentation is not significant.&lt;br /&gt;
* In Python, one has to write private instance variables using the long form self.__foobar. In Ruby, the form is @foobar.&lt;br /&gt;
* Ruby provides public, private, and protected to enforce access while Python uses underscore __convention__.&lt;br /&gt;
* Unlike Python, in Ruby parentheses for method calls are usually optional.&lt;br /&gt;
* Ruby uses ''elsif'' instead of ''elif'' as in Python.&lt;br /&gt;
* Ruby uses ''require'' instead of ''import'' as in Python. The usage however remains the same.&lt;br /&gt;
[6]&lt;br /&gt;
&lt;br /&gt;
====Summary of Differences====&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!  !! Python !! Ruby           &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Strings&lt;br /&gt;
| Immutable || Mutable&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Variables&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || private by default&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Methods&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || method private called before actual method&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Code Blocks&lt;br /&gt;
| Do not exist - Lambdas used instead. || Exist.&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Functions and Methods&lt;br /&gt;
| Have a different significance || No difference&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Multiple Inheritance&lt;br /&gt;
| Supported || Not Supported - uses mixins&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Threads&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Boolean Data Type&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Differences in (Web) Programming Environments==&lt;br /&gt;
Web development in Ruby is done using the framework, Ruby on Rails. Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework used with an Agile development methodology for rapid development. It uses the Model-View-Controller (MVC) architecture pattern to organize application programming [20]. Considered to be one of the best web development frameworks in the market, Ruby on Rails has helped to substantially increase the popularity of Ruby.&lt;br /&gt;
&lt;br /&gt;
In the case of Python, there are several web development frameworks such as Django, Grok, Pylons, TurboGears, web2py, Zope [21]. Django is designed with a similar architecture and feature set as Rails to be just as efficient without being just a clone. &lt;br /&gt;
&lt;br /&gt;
So while either frameworks may be used to develop a good web application, there are certain differences in both these frameworks [22]:&lt;br /&gt;
* Django has built in support for developer-friendly templates while Rails needs third party library support.&lt;br /&gt;
* Rails has in-built javascript support while Django has no direct support.&lt;br /&gt;
* In terms of Performance and Scalability, Django is considered better.&lt;br /&gt;
* Lesser number of plugins and support available for Django compared to Rails.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rails has for some time retained the top position in the popularity charts with developers. However, the situation seems to be changing with Django beating Rails since 2008 [23].&lt;br /&gt;
&lt;br /&gt;
[[Image:django-vs-rails.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Interesting Feature(s) Comparison: When is Python or Ruby preferred over the other==&lt;br /&gt;
&lt;br /&gt;
Python may be considered better than Ruby in the following cases [24]:&lt;br /&gt;
* Performance&lt;br /&gt;
:Ruby's interpreter performance trails compared to Python mainly due to the design of the interpreter. To execute Ruby code, the interpreter builds a syntax tree from the source code and then evaluates the syntax tree directly, instead of first compiling it into a more efficiently executable form.&lt;br /&gt;
* Threading&lt;br /&gt;
:Ruby's threading model has some inherent limitations which render it difficult to use or unsafe in some scenarios.&lt;br /&gt;
* Unicode&lt;br /&gt;
:Ruby does not yet have native support for Unicode or multibyte strings.&lt;br /&gt;
* Backward compatibility&lt;br /&gt;
:Ruby suffers from backward compatibility problems. &lt;br /&gt;
However, Ruby 2.0 aims to address all of the aforementioned problems.&lt;br /&gt;
&lt;br /&gt;
Ruby may be considered better than Python in the following cases [25]:&lt;br /&gt;
* Ruby on Rails is considered on of the most efficient web development frameworks (see section 1.3 for details).&lt;br /&gt;
* Ruby provides mutable string support (see section 1.2.1 for more details).&lt;br /&gt;
* Ruby supports usage of constants [19].&lt;br /&gt;
&lt;br /&gt;
==Advantages Over Statically Typed Languages==&lt;br /&gt;
A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. Statically typed languages include Ada, C, C++, C#, JADE, Java, Fortran, Haskell, ML, Pascal, Perl and Scala [26].&lt;br /&gt;
&lt;br /&gt;
====Code Size====&lt;br /&gt;
Python/Ruby are concise and compact as compared to Java which is verbose. This is shown in the example below:&lt;br /&gt;
 &lt;br /&gt;
Python&lt;br /&gt;
 print &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
 public class HelloWorld&lt;br /&gt;
 {&lt;br /&gt;
    public static void main (String[] args)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Static vs. Dynamic====&lt;br /&gt;
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That's what it means to say that Python is a dynamically typed language. Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required [27].&lt;br /&gt;
&lt;br /&gt;
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception. That's what it means to say that Java is a statically typed language. Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn't remember its type, and must be explicitly cast to the desired type [27].&lt;br /&gt;
&lt;br /&gt;
====Flexibility====&lt;br /&gt;
Flexibility of dynamically typed langauges such as Python and Ruby makes writing code significantly easier. Modules are easier to write, and easier to change. There are no build time issues at all [28].&lt;br /&gt;
* Java does not support operator overloading [29].&lt;br /&gt;
* Generators (functions that save state between different results) not present in Java [29].&lt;br /&gt;
* Ruby/Python support metaprogramming as well as the procedural and functional paradigms [30].&lt;br /&gt;
&lt;br /&gt;
==Comparison by Application Domains==&lt;br /&gt;
Since Ruby and Python are almost similar languages built with the same broad goals, we cannot pin point on certain applications that may be built only in Python or Ruby. Yet, due to the certain differences that exist developers may prefer one over the other depending on the application's requirements.&lt;br /&gt;
&lt;br /&gt;
As Rails is one of the most popular web development frameworks, it can be said that Ruby is more popular for web development that Python. Ruby on Rails makes a great framework to develop both small as well as high traffic sites. Ruby is, at present, exceptionally good at one specific kind of small project: database-backed web applications. Ruby on Rails counteracts all of Ruby's small-project disadvantages [31].&lt;br /&gt;
&lt;br /&gt;
Some of the top organizations using Ruby on Rails include NASA, Motorola, Google, Amazon, Cisco, IBM, Oracle, Yahoo [32][33].&lt;br /&gt;
&lt;br /&gt;
Python is better suited to desktop apps on Linux because you can perhaps integrate better to the host platform [34]. Python is believed to give better performance than Ruby and has a large standard library which is why more developers prefer it for areas such as text and numerical processing, operating system interfaces, internet protocols, internet security, software engineering, graphic design. Some of the big companies using Python include Google, Yahoo, CERN and NASA [35][36][1].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Python_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[2] http://wiki.python.org/moin/SimplePrograms&lt;br /&gt;
&amp;lt;br&amp;gt;[3] http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[4] http://www.fincher.org/tips/Languages/Ruby/&lt;br /&gt;
&amp;lt;br&amp;gt;[5] http://en.wikipedia.org/wiki/High-level_programming_language&lt;br /&gt;
&amp;lt;br&amp;gt;[6] http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/&lt;br /&gt;
&amp;lt;br&amp;gt;[7] http://en.wikipedia.org/wiki/Type_system#Dynamic_typing&lt;br /&gt;
&amp;lt;br&amp;gt;[8] http://en.wikipedia.org/wiki/Automatic_memory_management&lt;br /&gt;
&amp;lt;br&amp;gt;[9] http://oreilly.com/catalog/9780596523695/&lt;br /&gt;
&amp;lt;br&amp;gt;[10] http://en.wikipedia.org/wiki/Immutable_object&lt;br /&gt;
&amp;lt;br&amp;gt;[11] http://johan.kiviniemi.name/blag/ruby-vs-python&lt;br /&gt;
&amp;lt;br&amp;gt;[12] http://www.devarticles.com/c/a/Ruby-on-Rails/Code-Blocks-and-Iteration/&lt;br /&gt;
&amp;lt;br&amp;gt;[13] http://www.secnetix.de/olli/Python/lambda_functions.hawk&lt;br /&gt;
&amp;lt;br&amp;gt;[14] http://en.wikipedia.org/wiki/Multiple_inheritance&lt;br /&gt;
&amp;lt;br&amp;gt;[15] http://docs.python.org/tutorial/classes.html&lt;br /&gt;
&amp;lt;br&amp;gt;[16] http://en.wikipedia.org/wiki/Mixin&lt;br /&gt;
&amp;lt;br&amp;gt;[17] http://www.wellho.net/resources/ex.php4?item=r119/mixdem.rb&lt;br /&gt;
&amp;lt;br&amp;gt;[18] http://blog.ianbicking.org/ruby-python-power.html&lt;br /&gt;
&amp;lt;br&amp;gt;[19] http://dev.pocoo.org/~mitsuhiko/pythonruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[20] http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
&amp;lt;br&amp;gt;[21] http://wiki.python.org/moin/WebFrameworks&lt;br /&gt;
&amp;lt;br&amp;gt;[22] http://3columns.net/habitual/docs/RailsVsDjango.pdf&lt;br /&gt;
&amp;lt;br&amp;gt;[23] www.venturedig.com/wordpress/wp-content/uploads/2009/04/django-vs-rails11.jpg&lt;br /&gt;
&amp;lt;br&amp;gt;[24] http://en.wikipedia.org/wiki/Ruby_MRI#Criticism&lt;br /&gt;
&amp;lt;br&amp;gt;[25] Ruby Cookbook: Recipes for Object Oriented Scripting : ISBN 10: 0-596-52369-6 | ISBN 13: 9780596523695&lt;br /&gt;
&amp;lt;br&amp;gt;[26] http://en.wikipedia.org/wiki/Type_system&lt;br /&gt;
&amp;lt;br&amp;gt;[27] http://www.ferg.org/projects/python_java_side-by-side.html&lt;br /&gt;
&amp;lt;br&amp;gt;[28] http://www.artima.com/weblogs/viewpost.jsp?thread=4639&lt;br /&gt;
&amp;lt;br&amp;gt;[29] http://www.razorvine.net/python/PythonComparedToJava&lt;br /&gt;
&amp;lt;br&amp;gt;[30] http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[31] http://www.infoq.com/news/2007/06/rubyvsjava&lt;br /&gt;
&amp;lt;br&amp;gt;[32] http://www.ruby-lang.org/en/documentation/success-stories/&lt;br /&gt;
&amp;lt;br&amp;gt;[33] http://blog.obiefernandez.com/content/2008/03/big-name-compan.html&lt;br /&gt;
&amp;lt;br&amp;gt;[34] http://ubuntuforums.org/showthread.php?t=845563&lt;br /&gt;
&amp;lt;br&amp;gt;[35] http://ubuntuforums.org/archive/index.php/t-416082.html&lt;br /&gt;
&amp;lt;br&amp;gt;[36] http://www.python.org/doc/faq/general&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19400</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 rubyvspython</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19400"/>
		<updated>2009-09-16T21:22:20Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby vs. Python=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Python and Ruby are amongst some of the most popular programming languages in use today. Although this page compares and contrasts the two languages, when compared to the other existing languages in the market today, Ruby and Python are almost similar and developed with the same overall goals. However, the differences that do exist have made these two languages the subject of debate between their users. &lt;br /&gt;
  &lt;br /&gt;
===Brief Descriptions===&lt;br /&gt;
&lt;br /&gt;
====Python====&lt;br /&gt;
Python is a [http://en.wikipedia.org/wiki/High-level_programming_language high-level] programming language with a design philosophy that emphasizes code readability, clear syntax and its standard library is large and comprehensive. Its use of indentation as block delimiters is unusual among popular programming languages. Python supports multiple programming paradigms (primarily object-oriented, [http://en.wikipedia.org/wiki/Imperative_programming imperative], and functional), features a fully [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing dynamic] type system and [http://en.wikipedia.org/wiki/Memory_management automatic memory management] and is often used as a scripting language [1].&lt;br /&gt;
&lt;br /&gt;
Here's some sample python code: [2]&lt;br /&gt;
 name = input('What is your name?\n')&lt;br /&gt;
 print('Hi, ' + name + '.')&lt;br /&gt;
&lt;br /&gt;
====Ruby====&lt;br /&gt;
Ruby is a dynamic, general purpose object-oriented programming language developed and designed by Yukihiro &amp;quot;Matz&amp;quot; Matsumoto who wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and reflective. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Python [3].&lt;br /&gt;
&lt;br /&gt;
Here's some sample ruby code: [4]&lt;br /&gt;
 puts &amp;quot;What is your name?&amp;quot;&lt;br /&gt;
 $name = STDIN.gets&lt;br /&gt;
 puts &amp;quot;Hi &amp;quot; + $name&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
There are a lot of features that Ruby and Python have in common. So before we compare their differences, its a good idea to list their common features:&lt;br /&gt;
* High-level programming languages (language with strong abstraction from the details of the computer [5]).&lt;br /&gt;
* Everything is an object, and variables are just references to objects [6].&lt;br /&gt;
* Fully dynamic type system&lt;br /&gt;
:A language is dynamically typed when majority of its type checking is performed at run-time as opposed to at compile-time [7].&lt;br /&gt;
* Both provide an interactive prompt [6].&lt;br /&gt;
* Automatic memory management&lt;br /&gt;
:In computer science, garbage collection is a form of automatic memory management. The garbage collector attempts to reclaim garbage, or memory used by objects that are no longer in use by the application [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, let us see how these two languages differ in their features:&lt;br /&gt;
&lt;br /&gt;
''For a brief summary of differences, see [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython#Summary_of_Differences table] below.''&lt;br /&gt;
&lt;br /&gt;
====Strings in Python vs. Strings in Ruby====&lt;br /&gt;
String objects in Python are immutable whereas in Ruby strings are mutable objects [9]. &lt;br /&gt;
&lt;br /&gt;
An immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. If an object is known to be immutable, it can be copied simply by making a copy of a reference to it instead of copying the entire object. Because a reference is usually much smaller than the object itself, this results in memory savings and a boost in execution speed [10].&lt;br /&gt;
&lt;br /&gt;
So in Python, adding a string to another can create several unwanted intermediate strings and consume memory. In Ruby however, strings can expand as required without consuming much memory or time [9].  &lt;br /&gt;
&lt;br /&gt;
====Defining Private Variables and Methods==== &lt;br /&gt;
In Python &amp;quot;_&amp;quot; is appended in front of a variable or method name to make it private. &lt;br /&gt;
&lt;br /&gt;
In Ruby, all variables defined in a class are by default private and no specific keyword is required to make them so. For making a method private, a method ''private'' is called just before the actual method.&lt;br /&gt;
 private&lt;br /&gt;
   def sample_method_name&lt;br /&gt;
[11]&lt;br /&gt;
&lt;br /&gt;
====Code Blocks vs. Lambdas====&lt;br /&gt;
In Ruby, a code block is an object which contains certain code along with a context required to execute it. A code block can be thought of as a function not bound to a name. This is one of the most distinctive and unique features in Ruby. A code block in Ruby is defined as follows [12]:&lt;br /&gt;
 [1,2,3].each { |i| puts i}&lt;br /&gt;
&lt;br /&gt;
In Python, the concept of code blocks does not exist but the ability of creating unnamed functions can be achieved using lambdas. The lambda function acts like any standard function in Python. A lambda may be used as follows [13]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; (lambda x: x*2)(3)&lt;br /&gt;
 8&lt;br /&gt;
&lt;br /&gt;
====Functions and Methods==== &lt;br /&gt;
There are no functions and methods separately in Ruby; all of them are methods. &lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, for example, len() is a function, but items() is a method.&lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 print string.count('o'), len(string)  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, one needs to write self as the first parameter of a method definition. In Ruby, self is automatically available in a similar fashion as ''this'' in C++ [11].&lt;br /&gt;
&lt;br /&gt;
====Multiple Inheritance====&lt;br /&gt;
Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. This contrasts with single inheritance, where a class may inherit from at most one superclass [14].&lt;br /&gt;
&lt;br /&gt;
Python offers support for multiple inheritance and a class definition with multiple base classes looks like this [15]:&lt;br /&gt;
 class DerivedClassName(Base1, Base2, Base3):&lt;br /&gt;
    &amp;lt;statement-1&amp;gt;&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    &amp;lt;statement-N&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby does not support multiple inheritance but provides support so that classes can import modules as mixins [3]. &lt;br /&gt;
A mixin is a class that provides a certain functionality to be inherited by a subclass, while not meant for instantiation (the generating of objects of that class). Inheriting from a mixin is not a form of specialization but is rather a means of collecting functionality. A class may inherit most or all of its functionality from one or more mixins through multiple inheritance [16]. &lt;br /&gt;
 require &amp;quot;tcalc&amp;quot;&lt;br /&gt;
 class Invoice&lt;br /&gt;
   include Tcalc    # The line that mixes&lt;br /&gt;
[17]&lt;br /&gt;
&lt;br /&gt;
====Support for Threads==== &lt;br /&gt;
Ruby does not support OS (preemptive) threads and most code is not threadsafe. &lt;br /&gt;
&lt;br /&gt;
Python does support preemptive OS threads which can be used to handle concurrency well when some threads are blocking on external sources (disk access, network IO, waiting on a socket, etc) [18].&lt;br /&gt;
&lt;br /&gt;
====Boolean Values==== &lt;br /&gt;
In Python you have a boolean data type called bool which is a subclass of int and which can either be True or False. Every Python object can either be True or False which is defined by overriding the __nonzero__ method of an object. By default all empty objects (empty lists, dicts, tuples, strings etc) are False. This also applies to 0 and 0.0 [19].&lt;br /&gt;
&lt;br /&gt;
In Ruby the situation is completely different. There is no boolean data type but there are two singletons (true, instance of TrueClass and false, instance of FalseClass). Everything but nil and false is true. It's also not override-able [19].&lt;br /&gt;
&lt;br /&gt;
====Syntax Differences==== &lt;br /&gt;
* Unlike Python, in Ruby indentation is not significant.&lt;br /&gt;
* In Python, one has to write private instance variables using the long form self.__foobar. In Ruby, the form is @foobar.&lt;br /&gt;
* Ruby provides public, private, and protected to enforce access while Python uses underscore __convention__.&lt;br /&gt;
* Unlike Python, in Ruby parentheses for method calls are usually optional.&lt;br /&gt;
* Ruby uses ''elsif'' instead of ''elif'' as in Python.&lt;br /&gt;
* Ruby uses ''require'' instead of ''import'' as in Python. The usage however remains the same.&lt;br /&gt;
[6]&lt;br /&gt;
&lt;br /&gt;
====Summary of Differences====&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!  !! Python !! Ruby           &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Strings&lt;br /&gt;
| Immutable || Mutable&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Variables&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || private by default&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Methods&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || method private called before actual method&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Code Blocks&lt;br /&gt;
| Do not exist - Lambdas used instead. || Exist.&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Functions and Methods&lt;br /&gt;
| Have a different significance || No difference&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Multiple Inheritance&lt;br /&gt;
| Supported || Not Supported - uses mixins&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Threads&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Boolean Data Type&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Differences in (Web) Programming Environments==&lt;br /&gt;
Web development in Ruby is done using the framework, Ruby on Rails. Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework used with an Agile development methodology for rapid development. It uses the Model-View-Controller (MVC) architecture pattern to organize application programming [20]. Considered to be one of the best web development frameworks in the market, Ruby on Rails has helped to substantially increase the popularity of Ruby.&lt;br /&gt;
&lt;br /&gt;
In the case of Python, there are several web development frameworks such as Django, Grok, Pylons, TurboGears, web2py, Zope [21]. Django is designed with a similar architecture and feature set as Rails to be just as efficient without being just a clone. &lt;br /&gt;
&lt;br /&gt;
So while either frameworks may be used to develop a good web application, there are certain differences in both these frameworks [22]:&lt;br /&gt;
* Django has built in support for developer-friendly templates while Rails needs third party library support.&lt;br /&gt;
* Rails has in-built javascript support while Django has no direct support.&lt;br /&gt;
* In terms of Performance and Scalability, Django is considered better.&lt;br /&gt;
* Lesser number of plugins and support available for Django compared to Rails.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rails has for some time retained the top position in the popularity charts with developers. However, the situation seems to be changing with Django beating Rails since 2008 [23].&lt;br /&gt;
&lt;br /&gt;
[[Image:django-vs-rails.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Interesting Feature(s) Comparison: When is Python or Ruby preferred over the other==&lt;br /&gt;
&lt;br /&gt;
Python may be considered better than Ruby in the following cases [24]:&lt;br /&gt;
* Performance&lt;br /&gt;
:Ruby's interpreter performance trails compared to Python mainly due to the design of the interpreter. To execute Ruby code, the interpreter builds a syntax tree from the source code and then evaluates the syntax tree directly, instead of first compiling it into a more efficiently executable form.&lt;br /&gt;
* Threading&lt;br /&gt;
:Ruby's threading model has some inherent limitations which render it difficult to use or unsafe in some scenarios.&lt;br /&gt;
* Unicode&lt;br /&gt;
:Ruby does not yet have native support for Unicode or multibyte strings.&lt;br /&gt;
* Backward compatibility&lt;br /&gt;
:Ruby suffers from backward compatibility problems. &lt;br /&gt;
However, Ruby 2.0 aims to address all of the aforementioned problems.&lt;br /&gt;
&lt;br /&gt;
Ruby may be considered better than Python in the following cases [25]:&lt;br /&gt;
* Ruby on Rails is considered on of the most efficient web development frameworks (see section 1.3 for details).&lt;br /&gt;
* Ruby provides mutable string support (see section 1.2.1 for more details).&lt;br /&gt;
* Ruby supports usage of constants [19].&lt;br /&gt;
&lt;br /&gt;
==Advantages Over Statically Typed Languages==&lt;br /&gt;
A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. Statically typed languages include Ada, C, C++, C#, JADE, Java, Fortran, Haskell, ML, Pascal, Perl and Scala [26].&lt;br /&gt;
&lt;br /&gt;
====Code Size====&lt;br /&gt;
Python/Ruby are concise and compact as compared to Java which is verbose. This is shown in the example below:&lt;br /&gt;
 &lt;br /&gt;
Python&lt;br /&gt;
 print &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
 public class HelloWorld&lt;br /&gt;
 {&lt;br /&gt;
    public static void main (String[] args)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Static vs. Dynamic====&lt;br /&gt;
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That's what it means to say that Python is a dynamically typed language. Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required [27].&lt;br /&gt;
&lt;br /&gt;
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception. That's what it means to say that Java is a statically typed language. Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn't remember its type, and must be explicitly cast to the desired type [27].&lt;br /&gt;
&lt;br /&gt;
====Flexibility====&lt;br /&gt;
Flexibility of dynamically typed langauges such as Python and Ruby makes writing code significantly easier. Modules are easier to write, and easier to change. There are no build time issues at all [28].&lt;br /&gt;
* Java does not support operator overloading [29].&lt;br /&gt;
* Generators (functions that save state between different results) not present in Java [29].&lt;br /&gt;
* Ruby/Python support metaprogramming as well as the procedural and functional paradigms [30].&lt;br /&gt;
&lt;br /&gt;
==Comparison by Application Domains==&lt;br /&gt;
Since Ruby and Python are almost similar languages built with the same broad goals, we cannot pin point on certain applications that may be built only in Python or Ruby. Yet, due to the certain differences that exist developers may prefer one over the other depending on the application's requirements.&lt;br /&gt;
&lt;br /&gt;
As Rails is one of the most popular web development frameworks, it can be said that Ruby is more popular for web development that Python. Ruby on Rails makes a great framework to develop both small as well as high traffic sites. Ruby is, at present, exceptionally good at one specific kind of small project: database-backed web applications. Ruby on Rails counteracts all of Ruby's small-project disadvantages [31].&lt;br /&gt;
&lt;br /&gt;
Some of the top organizations using Ruby on Rails include NASA, Motorola, Google, Amazon, Cisco, IBM, Oracle, Yahoo [32][33].&lt;br /&gt;
&lt;br /&gt;
Python is better suited to desktop apps on Linux because you can perhaps integrate better to the host platform [34]. Python is believed to give better performance than Ruby and has a large standard library which is why more developers prefer it for areas such as text and numerical processing, operating system interfaces, internet protocols, internet security, software engineering, graphic design. Some of the big companies using Python include Google, Yahoo, CERN and NASA [35][36][1].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Python_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[2] http://wiki.python.org/moin/SimplePrograms&lt;br /&gt;
&amp;lt;br&amp;gt;[3] http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[4] http://www.fincher.org/tips/Languages/Ruby/&lt;br /&gt;
&amp;lt;br&amp;gt;[5] http://en.wikipedia.org/wiki/High-level_programming_language&lt;br /&gt;
&amp;lt;br&amp;gt;[6] http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/&lt;br /&gt;
&amp;lt;br&amp;gt;[7] http://en.wikipedia.org/wiki/Type_system#Dynamic_typing&lt;br /&gt;
&amp;lt;br&amp;gt;[8] http://en.wikipedia.org/wiki/Automatic_memory_management&lt;br /&gt;
&amp;lt;br&amp;gt;[9] http://oreilly.com/catalog/9780596523695/&lt;br /&gt;
&amp;lt;br&amp;gt;[10] http://en.wikipedia.org/wiki/Immutable_object&lt;br /&gt;
&amp;lt;br&amp;gt;[11] http://johan.kiviniemi.name/blag/ruby-vs-python&lt;br /&gt;
&amp;lt;br&amp;gt;[12] http://www.devarticles.com/c/a/Ruby-on-Rails/Code-Blocks-and-Iteration/&lt;br /&gt;
&amp;lt;br&amp;gt;[13] http://www.secnetix.de/olli/Python/lambda_functions.hawk&lt;br /&gt;
&amp;lt;br&amp;gt;[14] http://en.wikipedia.org/wiki/Multiple_inheritance&lt;br /&gt;
&amp;lt;br&amp;gt;[15] http://docs.python.org/tutorial/classes.html&lt;br /&gt;
&amp;lt;br&amp;gt;[16] http://en.wikipedia.org/wiki/Mixin&lt;br /&gt;
&amp;lt;br&amp;gt;[17] http://www.wellho.net/resources/ex.php4?item=r119/mixdem.rb&lt;br /&gt;
&amp;lt;br&amp;gt;[18] http://blog.ianbicking.org/ruby-python-power.html&lt;br /&gt;
&amp;lt;br&amp;gt;[19] http://dev.pocoo.org/~mitsuhiko/pythonruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[20] http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
&amp;lt;br&amp;gt;[21] http://wiki.python.org/moin/WebFrameworks&lt;br /&gt;
&amp;lt;br&amp;gt;[22] http://3columns.net/habitual/docs/RailsVsDjango.pdf&lt;br /&gt;
&amp;lt;br&amp;gt;[23] www.venturedig.com/wordpress/wp-content/uploads/2009/04/django-vs-rails11.jpg&lt;br /&gt;
&amp;lt;br&amp;gt;[24] http://en.wikipedia.org/wiki/Ruby_MRI#Criticism&lt;br /&gt;
&amp;lt;br&amp;gt;[25] Ruby Cookbook: Recipes for Object Oriented Scripting : ISBN 10: 0-596-52369-6 | ISBN 13: 9780596523695&lt;br /&gt;
&amp;lt;br&amp;gt;[26] http://en.wikipedia.org/wiki/Type_system&lt;br /&gt;
&amp;lt;br&amp;gt;[27] http://www.ferg.org/projects/python_java_side-by-side.html&lt;br /&gt;
&amp;lt;br&amp;gt;[28] http://www.artima.com/weblogs/viewpost.jsp?thread=4639&lt;br /&gt;
&amp;lt;br&amp;gt;[29] http://www.razorvine.net/python/PythonComparedToJava&lt;br /&gt;
&amp;lt;br&amp;gt;[30] http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[31] http://www.infoq.com/news/2007/06/rubyvsjava&lt;br /&gt;
&amp;lt;br&amp;gt;[32] http://www.ruby-lang.org/en/documentation/success-stories/&lt;br /&gt;
&amp;lt;br&amp;gt;[33] http://blog.obiefernandez.com/content/2008/03/big-name-compan.html&lt;br /&gt;
&amp;lt;br&amp;gt;[34] http://ubuntuforums.org/showthread.php?t=845563&lt;br /&gt;
&amp;lt;br&amp;gt;[35] http://ubuntuforums.org/archive/index.php/t-416082.html&lt;br /&gt;
&amp;lt;br&amp;gt;[36] http://www.python.org/doc/faq/general&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19396</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 rubyvspython</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19396"/>
		<updated>2009-09-16T21:13:00Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby vs. Python=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Python and Ruby are amongst some of the most popular programming languages in use today. Although this page compares and contrasts the two languages, when compared to the other existing languages in the market today, Ruby and Python are almost similar and developed with the same overall goals. However, the differences that do exist have made these two languages the subject of debate between their users. &lt;br /&gt;
  &lt;br /&gt;
===Brief Descriptions===&lt;br /&gt;
&lt;br /&gt;
====Python====&lt;br /&gt;
Python is a [http://en.wikipedia.org/wiki/High-level_programming_language high-level] programming language with a design philosophy that emphasizes code readability, clear syntax and its standard library is large and comprehensive. Its use of indentation as block delimiters is unusual among popular programming languages. Python supports multiple programming paradigms (primarily object-oriented, imperative, and functional), features a fully dynamic type system and automatic memory management and is often used as a scripting language [1].&lt;br /&gt;
&lt;br /&gt;
Here's some sample python code: [2]&lt;br /&gt;
 name = input('What is your name?\n')&lt;br /&gt;
 print('Hi, ' + name + '.')&lt;br /&gt;
&lt;br /&gt;
====Ruby====&lt;br /&gt;
Ruby is a dynamic, general purpose object-oriented programming language developed and designed by Yukihiro &amp;quot;Matz&amp;quot; Matsumoto who wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and reflective. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Python [3].&lt;br /&gt;
&lt;br /&gt;
Here's some sample ruby code: [4]&lt;br /&gt;
 puts &amp;quot;What is your name?&amp;quot;&lt;br /&gt;
 $name = STDIN.gets&lt;br /&gt;
 puts &amp;quot;Hi &amp;quot; + $name&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
There are a lot of features that Ruby and Python have in common. So before we compare their differences, its a good idea to list their common features:&lt;br /&gt;
* High-level programming languages (language with strong abstraction from the details of the computer [5]).&lt;br /&gt;
* Everything is an object, and variables are just references to objects [6].&lt;br /&gt;
* Fully dynamic type system&lt;br /&gt;
:A language is dynamically typed when majority of its type checking is performed at run-time as opposed to at compile-time [7].&lt;br /&gt;
* Both provide an interactive prompt [6].&lt;br /&gt;
* Automatic memory management&lt;br /&gt;
:In computer science, garbage collection is a form of automatic memory management. The garbage collector attempts to reclaim garbage, or memory used by objects that are no longer in use by the application [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, let us see how these two languages differ in their features:&lt;br /&gt;
&lt;br /&gt;
''For a brief summary of differences, see [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython#Summary_of_Differences table] below.''&lt;br /&gt;
&lt;br /&gt;
====Strings in Python vs. Strings in Ruby====&lt;br /&gt;
String objects in Python are immutable whereas in Ruby strings are mutable objects [9]. &lt;br /&gt;
&lt;br /&gt;
An immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. If an object is known to be immutable, it can be copied simply by making a copy of a reference to it instead of copying the entire object. Because a reference is usually much smaller than the object itself, this results in memory savings and a boost in execution speed [10].&lt;br /&gt;
&lt;br /&gt;
So in Python, adding a string to another can create several unwanted intermediate strings and consume memory. In Ruby however, strings can expand as required without consuming much memory or time [9].  &lt;br /&gt;
&lt;br /&gt;
====Defining Private Variables and Methods==== &lt;br /&gt;
In Python &amp;quot;_&amp;quot; is appended in front of a variable or method name to make it private. &lt;br /&gt;
&lt;br /&gt;
In Ruby, all variables defined in a class are by default private and no specific keyword is required to make them so. For making a method private, a method ''private'' is called just before the actual method.&lt;br /&gt;
 private&lt;br /&gt;
   def sample_method_name&lt;br /&gt;
[11]&lt;br /&gt;
&lt;br /&gt;
====Code Blocks vs. Lambdas====&lt;br /&gt;
In Ruby, a code block is an object which contains certain code along with a context required to execute it. A code block can be thought of as a function not bound to a name. This is one of the most distinctive and unique features in Ruby. A code block in Ruby is defined as follows [12]:&lt;br /&gt;
 [1,2,3].each { |i| puts i}&lt;br /&gt;
&lt;br /&gt;
In Python, the concept of code blocks does not exist but the ability of creating unnamed functions can be achieved using lambdas. The lambda function acts like any standard function in Python. A lambda may be used as follows [13]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; (lambda x: x*2)(3)&lt;br /&gt;
 8&lt;br /&gt;
&lt;br /&gt;
====Functions and Methods==== &lt;br /&gt;
There are no functions and methods separately in Ruby; all of them are methods. &lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, for example, len() is a function, but items() is a method.&lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 print string.count('o'), len(string)  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, one needs to write self as the first parameter of a method definition. In Ruby, self is automatically available in a similar fashion as ''this'' in C++ [11].&lt;br /&gt;
&lt;br /&gt;
====Multiple Inheritance====&lt;br /&gt;
Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. This contrasts with single inheritance, where a class may inherit from at most one superclass [14].&lt;br /&gt;
&lt;br /&gt;
Python offers support for multiple inheritance and a class definition with multiple base classes looks like this [15]:&lt;br /&gt;
 class DerivedClassName(Base1, Base2, Base3):&lt;br /&gt;
    &amp;lt;statement-1&amp;gt;&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    &amp;lt;statement-N&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby does not support multiple inheritance but provides support so that classes can import modules as mixins [3]. &lt;br /&gt;
A mixin is a class that provides a certain functionality to be inherited by a subclass, while not meant for instantiation (the generating of objects of that class). Inheriting from a mixin is not a form of specialization but is rather a means of collecting functionality. A class may inherit most or all of its functionality from one or more mixins through multiple inheritance [16]. &lt;br /&gt;
 require &amp;quot;tcalc&amp;quot;&lt;br /&gt;
 class Invoice&lt;br /&gt;
   include Tcalc    # The line that mixes&lt;br /&gt;
[17]&lt;br /&gt;
&lt;br /&gt;
====Support for Threads==== &lt;br /&gt;
Ruby does not support OS (preemptive) threads and most code is not threadsafe. &lt;br /&gt;
&lt;br /&gt;
Python does support preemptive OS threads which can be used to handle concurrency well when some threads are blocking on external sources (disk access, network IO, waiting on a socket, etc) [18].&lt;br /&gt;
&lt;br /&gt;
====Boolean Values==== &lt;br /&gt;
In Python you have a boolean data type called bool which is a subclass of int and which can either be True or False. Every Python object can either be True or False which is defined by overriding the __nonzero__ method of an object. By default all empty objects (empty lists, dicts, tuples, strings etc) are False. This also applies to 0 and 0.0 [19].&lt;br /&gt;
&lt;br /&gt;
In Ruby the situation is completely different. There is no boolean data type but there are two singletons (true, instance of TrueClass and false, instance of FalseClass). Everything but nil and false is true. It's also not override-able [19].&lt;br /&gt;
&lt;br /&gt;
====Syntax Differences==== &lt;br /&gt;
* Unlike Python, in Ruby indentation is not significant.&lt;br /&gt;
* In Python, one has to write private instance variables using the long form self.__foobar. In Ruby, the form is @foobar.&lt;br /&gt;
* Ruby provides public, private, and protected to enforce access while Python uses underscore __convention__.&lt;br /&gt;
* Unlike Python, in Ruby parentheses for method calls are usually optional.&lt;br /&gt;
* Ruby uses ''elsif'' instead of ''elif'' as in Python.&lt;br /&gt;
* Ruby uses ''require'' instead of ''import'' as in Python. The usage however remains the same.&lt;br /&gt;
[6]&lt;br /&gt;
&lt;br /&gt;
====Summary of Differences====&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!  !! Python !! Ruby           &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Strings&lt;br /&gt;
| Immutable || Mutable&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Variables&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || private by default&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Methods&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || method private called before actual method&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Code Blocks&lt;br /&gt;
| Do not exist - Lambdas used instead. || Exist.&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Functions and Methods&lt;br /&gt;
| Have a different significance || No difference&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Multiple Inheritance&lt;br /&gt;
| Supported || Not Supported - uses mixins&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Threads&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Boolean Data Type&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Differences in (Web) Programming Environments==&lt;br /&gt;
Web development in Ruby is done using the framework, Ruby on Rails. Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework used with an Agile development methodology for rapid development. It uses the Model-View-Controller (MVC) architecture pattern to organize application programming [20]. Considered to be one of the best web development frameworks in the market, Ruby on Rails has helped to substantially increase the popularity of Ruby.&lt;br /&gt;
&lt;br /&gt;
In the case of Python, there are several web development frameworks such as Django, Grok, Pylons, TurboGears, web2py, Zope [21]. Django is designed with a similar architecture and feature set as Rails to be just as efficient without being just a clone. &lt;br /&gt;
&lt;br /&gt;
So while either frameworks may be used to develop a good web application, there are certain differences in both these frameworks [22]:&lt;br /&gt;
* Django has built in support for developer-friendly templates while Rails needs third party library support.&lt;br /&gt;
* Rails has in-built javascript support while Django has no direct support.&lt;br /&gt;
* In terms of Performance and Scalability, Django is considered better.&lt;br /&gt;
* Lesser number of plugins and support available for Django compared to Rails.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rails has for some time retained the top position in the popularity charts with developers. However, the situation seems to be changing with Django beating Rails since 2008 [23].&lt;br /&gt;
&lt;br /&gt;
[[Image:django-vs-rails.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Interesting Feature(s) Comparison: When is Python or Ruby preferred over the other==&lt;br /&gt;
&lt;br /&gt;
Python may be considered better than Ruby in the following cases [24]:&lt;br /&gt;
* Performance&lt;br /&gt;
:Ruby's interpreter performance trails compared to Python mainly due to the design of the interpreter. To execute Ruby code, the interpreter builds a syntax tree from the source code and then evaluates the syntax tree directly, instead of first compiling it into a more efficiently executable form.&lt;br /&gt;
* Threading&lt;br /&gt;
:Ruby's threading model has some inherent limitations which render it difficult to use or unsafe in some scenarios.&lt;br /&gt;
* Unicode&lt;br /&gt;
:Ruby does not yet have native support for Unicode or multibyte strings.&lt;br /&gt;
* Backward compatibility&lt;br /&gt;
:Ruby suffers from backward compatibility problems. &lt;br /&gt;
However, Ruby 2.0 aims to address all of the aforementioned problems.&lt;br /&gt;
&lt;br /&gt;
Ruby may be considered better than Python in the following cases [25]:&lt;br /&gt;
* Ruby on Rails is considered on of the most efficient web development frameworks (see section 1.3 for details).&lt;br /&gt;
* Ruby provides mutable string support (see section 1.2.1 for more details).&lt;br /&gt;
* Ruby supports usage of constants [19].&lt;br /&gt;
&lt;br /&gt;
==Advantages Over Statically Typed Languages==&lt;br /&gt;
A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. Statically typed languages include Ada, C, C++, C#, JADE, Java, Fortran, Haskell, ML, Pascal, Perl and Scala [26].&lt;br /&gt;
&lt;br /&gt;
====Code Size====&lt;br /&gt;
Python/Ruby are concise and compact as compared to Java which is verbose. This is shown in the example below:&lt;br /&gt;
 &lt;br /&gt;
Python&lt;br /&gt;
 print &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
 public class HelloWorld&lt;br /&gt;
 {&lt;br /&gt;
    public static void main (String[] args)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Static vs. Dynamic====&lt;br /&gt;
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That's what it means to say that Python is a dynamically typed language. Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required [27].&lt;br /&gt;
&lt;br /&gt;
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception. That's what it means to say that Java is a statically typed language. Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn't remember its type, and must be explicitly cast to the desired type [27].&lt;br /&gt;
&lt;br /&gt;
====Flexibility====&lt;br /&gt;
Flexibility of dynamically typed langauges such as Python and Ruby makes writing code significantly easier. Modules are easier to write, and easier to change. There are no build time issues at all [28].&lt;br /&gt;
* Java does not support operator overloading [29].&lt;br /&gt;
* Generators (functions that save state between different results) not present in Java [29].&lt;br /&gt;
* Ruby/Python support metaprogramming as well as the procedural and functional paradigms [30].&lt;br /&gt;
&lt;br /&gt;
==Comparison by Application Domains==&lt;br /&gt;
Since Ruby and Python are almost similar languages built with the same broad goals, we cannot pin point on certain applications that may be built only in Python or Ruby. Yet, due to the certain differences that exist developers may prefer one over the other depending on the application's requirements.&lt;br /&gt;
&lt;br /&gt;
As Rails is one of the most popular web development frameworks, it can be said that Ruby is more popular for web development that Python. Ruby on Rails makes a great framework to develop both small as well as high traffic sites. Ruby is, at present, exceptionally good at one specific kind of small project: database-backed web applications. Ruby on Rails counteracts all of Ruby's small-project disadvantages [31].&lt;br /&gt;
&lt;br /&gt;
Some of the top organizations using Ruby on Rails include NASA, Motorola, Google, Amazon, Cisco, IBM, Oracle, Yahoo [32][33].&lt;br /&gt;
&lt;br /&gt;
Python is better suited to desktop apps on Linux because you can perhaps integrate better to the host platform [34]. Python is believed to give better performance than Ruby and has a large standard library which is why more developers prefer it for areas such as text and numerical processing, operating system interfaces, internet protocols, internet security, software engineering, graphic design. Some of the big companies using Python include Google, Yahoo, CERN and NASA [35][36][1].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Python_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[2] http://wiki.python.org/moin/SimplePrograms&lt;br /&gt;
&amp;lt;br&amp;gt;[3] http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[4] http://www.fincher.org/tips/Languages/Ruby/&lt;br /&gt;
&amp;lt;br&amp;gt;[5] http://en.wikipedia.org/wiki/High-level_programming_language&lt;br /&gt;
&amp;lt;br&amp;gt;[6] http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/&lt;br /&gt;
&amp;lt;br&amp;gt;[7] http://en.wikipedia.org/wiki/Type_system#Dynamic_typing&lt;br /&gt;
&amp;lt;br&amp;gt;[8] http://en.wikipedia.org/wiki/Automatic_memory_management&lt;br /&gt;
&amp;lt;br&amp;gt;[9] http://oreilly.com/catalog/9780596523695/&lt;br /&gt;
&amp;lt;br&amp;gt;[10] http://en.wikipedia.org/wiki/Immutable_object&lt;br /&gt;
&amp;lt;br&amp;gt;[11] http://johan.kiviniemi.name/blag/ruby-vs-python&lt;br /&gt;
&amp;lt;br&amp;gt;[12] http://www.devarticles.com/c/a/Ruby-on-Rails/Code-Blocks-and-Iteration/&lt;br /&gt;
&amp;lt;br&amp;gt;[13] http://www.secnetix.de/olli/Python/lambda_functions.hawk&lt;br /&gt;
&amp;lt;br&amp;gt;[14] http://en.wikipedia.org/wiki/Multiple_inheritance&lt;br /&gt;
&amp;lt;br&amp;gt;[15] http://docs.python.org/tutorial/classes.html&lt;br /&gt;
&amp;lt;br&amp;gt;[16] http://en.wikipedia.org/wiki/Mixin&lt;br /&gt;
&amp;lt;br&amp;gt;[17] http://www.wellho.net/resources/ex.php4?item=r119/mixdem.rb&lt;br /&gt;
&amp;lt;br&amp;gt;[18] http://blog.ianbicking.org/ruby-python-power.html&lt;br /&gt;
&amp;lt;br&amp;gt;[19] http://dev.pocoo.org/~mitsuhiko/pythonruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[20] http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
&amp;lt;br&amp;gt;[21] http://wiki.python.org/moin/WebFrameworks&lt;br /&gt;
&amp;lt;br&amp;gt;[22] http://3columns.net/habitual/docs/RailsVsDjango.pdf&lt;br /&gt;
&amp;lt;br&amp;gt;[23] www.venturedig.com/wordpress/wp-content/uploads/2009/04/django-vs-rails11.jpg&lt;br /&gt;
&amp;lt;br&amp;gt;[24] http://en.wikipedia.org/wiki/Ruby_MRI#Criticism&lt;br /&gt;
&amp;lt;br&amp;gt;[25] Ruby Cookbook: Recipes for Object Oriented Scripting : ISBN 10: 0-596-52369-6 | ISBN 13: 9780596523695&lt;br /&gt;
&amp;lt;br&amp;gt;[26] http://en.wikipedia.org/wiki/Type_system&lt;br /&gt;
&amp;lt;br&amp;gt;[27] http://www.ferg.org/projects/python_java_side-by-side.html&lt;br /&gt;
&amp;lt;br&amp;gt;[28] http://www.artima.com/weblogs/viewpost.jsp?thread=4639&lt;br /&gt;
&amp;lt;br&amp;gt;[29] http://www.razorvine.net/python/PythonComparedToJava&lt;br /&gt;
&amp;lt;br&amp;gt;[30] http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[31] http://www.infoq.com/news/2007/06/rubyvsjava&lt;br /&gt;
&amp;lt;br&amp;gt;[32] http://www.ruby-lang.org/en/documentation/success-stories/&lt;br /&gt;
&amp;lt;br&amp;gt;[33] http://blog.obiefernandez.com/content/2008/03/big-name-compan.html&lt;br /&gt;
&amp;lt;br&amp;gt;[34] http://ubuntuforums.org/showthread.php?t=845563&lt;br /&gt;
&amp;lt;br&amp;gt;[35] http://ubuntuforums.org/archive/index.php/t-416082.html&lt;br /&gt;
&amp;lt;br&amp;gt;[36] http://www.python.org/doc/faq/general&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19168</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 rubyvspython</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19168"/>
		<updated>2009-09-15T02:19:01Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: /* Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby vs. Python=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Python and Ruby are amongst some of the most popular programming languages in use today. Although this page compares and contrasts the two languages, when compared to the other existing languages in the market today, Ruby and Python are almost similar and developed with the same overall goals. However, the differences that do exist have made these two languages the subject of debate between their users. &lt;br /&gt;
  &lt;br /&gt;
===Brief Descriptions===&lt;br /&gt;
&lt;br /&gt;
====Python====&lt;br /&gt;
Python is a high-level programming language with a design philosophy that emphasizes code readability, clear syntax and its standard library is large and comprehensive. Its use of indentation as block delimiters is unusual among popular programming languages. Python supports multiple programming paradigms (primarily object-oriented, imperative, and functional), features a fully dynamic type system and automatic memory management and is often used as a scripting language [1].&lt;br /&gt;
&lt;br /&gt;
Here's some sample python code: [2]&lt;br /&gt;
 name = input('What is your name?\n')&lt;br /&gt;
 print('Hi, ' + name + '.')&lt;br /&gt;
&lt;br /&gt;
====Ruby====&lt;br /&gt;
Ruby is a dynamic, general purpose object-oriented programming language developed and designed by Yukihiro &amp;quot;Matz&amp;quot; Matsumoto who wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and reflective. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Python [3].&lt;br /&gt;
&lt;br /&gt;
Here's some sample ruby code: [4]&lt;br /&gt;
 puts &amp;quot;What is your name?&amp;quot;&lt;br /&gt;
 $name = STDIN.gets&lt;br /&gt;
 puts &amp;quot;Hi &amp;quot; + $name&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
There are a lot of features that Ruby and Python have in common. So before we compare their differences, its a good idea to list their common features:&lt;br /&gt;
* High-level programming languages (language with strong abstraction from the details of the computer [5]).&lt;br /&gt;
* Everything is an object, and variables are just references to objects [6].&lt;br /&gt;
* Fully dynamic type system&lt;br /&gt;
:A language is dynamically typed when majority of its type checking is performed at run-time as opposed to at compile-time [7].&lt;br /&gt;
* Both provide an interactive prompt [6].&lt;br /&gt;
* Automatic memory management&lt;br /&gt;
:In computer science, garbage collection is a form of automatic memory management. The garbage collector attempts to reclaim garbage, or memory used by objects that are no longer in use by the application [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, let us see how these two languages differ in their features:&lt;br /&gt;
&lt;br /&gt;
''For a brief summary of differences, see [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython#Summary_of_Differences table] below.''&lt;br /&gt;
&lt;br /&gt;
====Strings in Python vs. Strings in Ruby====&lt;br /&gt;
String objects in Python are immutable whereas in Ruby strings are mutable objects [9]. &lt;br /&gt;
&lt;br /&gt;
An immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. If an object is known to be immutable, it can be copied simply by making a copy of a reference to it instead of copying the entire object. Because a reference is usually much smaller than the object itself, this results in memory savings and a boost in execution speed [10].&lt;br /&gt;
&lt;br /&gt;
So in Python, adding a string to another can create several unwanted intermediate strings and consume memory. In Ruby however, strings can expand as required without consuming much memory or time [9].  &lt;br /&gt;
&lt;br /&gt;
====Defining Private Variables and Methods==== &lt;br /&gt;
In Python &amp;quot;_&amp;quot; is appended in front of a variable or method name to make it private. &lt;br /&gt;
&lt;br /&gt;
In Ruby, all variables defined in a class are by default private and no specific keyword is required to make them so. For making a method private, a method ''private'' is called just before the actual method.&lt;br /&gt;
 private&lt;br /&gt;
   def sample_method_name&lt;br /&gt;
[11]&lt;br /&gt;
&lt;br /&gt;
====Code Blocks vs. Lambdas====&lt;br /&gt;
In Ruby, a code block is an object which contains certain code along with a context required to execute it. A code block can be thought of as a function not bound to a name. This is one of the most distinctive and unique features in Ruby. A code block in Ruby is defined as follows [12]:&lt;br /&gt;
 [1,2,3].each { |i| puts i}&lt;br /&gt;
&lt;br /&gt;
In Python, the concept of code blocks does not exist but the ability of creating unnamed functions can be achieved using lambdas. The lambda function acts like any standard function in Python. A lambda may be used as follows [13]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; (lambda x: x*2)(3)&lt;br /&gt;
 8&lt;br /&gt;
&lt;br /&gt;
====Functions and Methods==== &lt;br /&gt;
There are no functions and methods separately in Ruby; all of them are methods. &lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, for example, len() is a function, but items() is a method.&lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 print string.count('o'), len(string)  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, one needs to write self as the first parameter of a method definition. In Ruby, self is automatically available in a similar fashion as ''this'' in C++ [11].&lt;br /&gt;
&lt;br /&gt;
====Multiple Inheritance====&lt;br /&gt;
Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. This contrasts with single inheritance, where a class may inherit from at most one superclass [14].&lt;br /&gt;
&lt;br /&gt;
Python offers support for multiple inheritance and a class definition with multiple base classes looks like this [15]:&lt;br /&gt;
 class DerivedClassName(Base1, Base2, Base3):&lt;br /&gt;
    &amp;lt;statement-1&amp;gt;&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    &amp;lt;statement-N&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby does not support multiple inheritance but provides support so that classes can import modules as mixins [3]. &lt;br /&gt;
A mixin is a class that provides a certain functionality to be inherited by a subclass, while not meant for instantiation (the generating of objects of that class). Inheriting from a mixin is not a form of specialization but is rather a means of collecting functionality. A class may inherit most or all of its functionality from one or more mixins through multiple inheritance [16]. &lt;br /&gt;
 require &amp;quot;tcalc&amp;quot;&lt;br /&gt;
 class Invoice&lt;br /&gt;
   include Tcalc    # The line that mixes&lt;br /&gt;
[17]&lt;br /&gt;
&lt;br /&gt;
====Support for Threads==== &lt;br /&gt;
Ruby does not support OS (preemptive) threads and most code is not threadsafe. &lt;br /&gt;
&lt;br /&gt;
Python does support preemptive OS threads which can be used to handle concurrency well when some threads are blocking on external sources (disk access, network IO, waiting on a socket, etc) [18].&lt;br /&gt;
&lt;br /&gt;
====Boolean Values==== &lt;br /&gt;
In Python you have a boolean data type called bool which is a subclass of int and which can either be True or False. Every Python object can either be True or False which is defined by overriding the __nonzero__ method of an object. By default all empty objects (empty lists, dicts, tuples, strings etc) are False. This also applies to 0 and 0.0 [19].&lt;br /&gt;
&lt;br /&gt;
In Ruby the situation is completely different. There is no boolean data type but there are two singletons (true, instance of TrueClass and false, instance of FalseClass). Everything but nil and false is true. It's also not override-able [19].&lt;br /&gt;
&lt;br /&gt;
====Syntax Differences==== &lt;br /&gt;
* Unlike Python, in Ruby indentation is not significant.&lt;br /&gt;
* In Python, one has to write private instance variables using the long form self.__foobar. In Ruby, the form is @foobar.&lt;br /&gt;
* Ruby provides public, private, and protected to enforce access while Python uses underscore __convention__.&lt;br /&gt;
* Unlike Python, in Ruby parentheses for method calls are usually optional.&lt;br /&gt;
* Ruby uses ''elsif'' instead of ''elif'' as in Python.&lt;br /&gt;
* Ruby uses ''require'' instead of ''import'' as in Python. The usage however remains the same.&lt;br /&gt;
[6]&lt;br /&gt;
&lt;br /&gt;
====Summary of Differences====&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!  !! Python !! Ruby           &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Strings&lt;br /&gt;
| Immutable || Mutable&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Variables&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || private by default&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Methods&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || method private called before actual method&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Code Blocks&lt;br /&gt;
| Do not exist - Lambdas used instead. || Exist.&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Functions and Methods&lt;br /&gt;
| Have a different significance || No difference&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Multiple Inheritance&lt;br /&gt;
| Supported || Not Supported - uses mixins&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Threads&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Boolean Data Type&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Differences in (Web) Programming Environments==&lt;br /&gt;
Web development in Ruby is done using the framework, Ruby on Rails. Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework used with an Agile development methodology for rapid development. It uses the Model-View-Controller (MVC) architecture pattern to organize application programming [20]. Considered to be one of the best web development frameworks in the market, Ruby on Rails has helped to substantially increase the popularity of Ruby.&lt;br /&gt;
&lt;br /&gt;
In the case of Python, there are several web development frameworks such as Django, Grok, Pylons, TurboGears, web2py, Zope [21]. Django is designed with a similar architecture and feature set as Rails to be just as efficient without being just a clone. &lt;br /&gt;
&lt;br /&gt;
So while either frameworks may be used to develop a good web application, there are certain differences in both these frameworks [22]:&lt;br /&gt;
* Django has built in support for developer-friendly templates while Rails needs third party library support.&lt;br /&gt;
* Rails has in-built javascript support while Django has no direct support.&lt;br /&gt;
* In terms of Performance and Scalability, Django is considered better.&lt;br /&gt;
* Lesser number of plugins and support available for Django compared to Rails.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rails has for some time retained the top position in the popularity charts with developers. However, the situation seems to be changing with Django beating Rails since 2008 [23].&lt;br /&gt;
&lt;br /&gt;
[[Image:django-vs-rails.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Interesting Feature(s) Comparison: When is Python or Ruby preferred over the other==&lt;br /&gt;
&lt;br /&gt;
Python may be considered better than Ruby in the following cases [24]:&lt;br /&gt;
* Performance&lt;br /&gt;
:Ruby's interpreter performance trails compared to Python mainly due to the design of the interpreter. To execute Ruby code, the interpreter builds a syntax tree from the source code and then evaluates the syntax tree directly, instead of first compiling it into a more efficiently executable form.&lt;br /&gt;
* Threading&lt;br /&gt;
:Ruby's threading model has some inherent limitations which render it difficult to use or unsafe in some scenarios.&lt;br /&gt;
* Unicode&lt;br /&gt;
:Ruby does not yet have native support for Unicode or multibyte strings.&lt;br /&gt;
* Backward compatibility&lt;br /&gt;
:Ruby suffers from backward compatibility problems. &lt;br /&gt;
However, Ruby 2.0 aims to address all of the aforementioned problems.&lt;br /&gt;
&lt;br /&gt;
Ruby may be considered better than Python in the following cases [25]:&lt;br /&gt;
* Ruby on Rails is considered on of the most efficient web development frameworks (see section 1.3 for details).&lt;br /&gt;
* Ruby provides mutable string support (see section 1.2.1 for more details).&lt;br /&gt;
* Ruby supports usage of constants [19].&lt;br /&gt;
&lt;br /&gt;
==Advantages Over Statically Typed Languages==&lt;br /&gt;
A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. Statically typed languages include Ada, C, C++, C#, JADE, Java, Fortran, Haskell, ML, Pascal, Perl and Scala [26].&lt;br /&gt;
&lt;br /&gt;
====Code Size====&lt;br /&gt;
Python/Ruby are concise and compact as compared to Java which is verbose. This is shown in the example below:&lt;br /&gt;
 &lt;br /&gt;
Python&lt;br /&gt;
 print &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
 public class HelloWorld&lt;br /&gt;
 {&lt;br /&gt;
    public static void main (String[] args)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Static vs. Dynamic====&lt;br /&gt;
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That's what it means to say that Python is a dynamically typed language. Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required [27].&lt;br /&gt;
&lt;br /&gt;
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception. That's what it means to say that Java is a statically typed language. Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn't remember its type, and must be explicitly cast to the desired type [27].&lt;br /&gt;
&lt;br /&gt;
====Flexibility====&lt;br /&gt;
Flexibility of dynamically typed langauges such as Python and Ruby makes writing code significantly easier. Modules are easier to write, and easier to change. There are no build time issues at all [28].&lt;br /&gt;
* Java does not support operator overloading [29].&lt;br /&gt;
* Generators (functions that save state between different results) not present in Java [29].&lt;br /&gt;
* Ruby/Python support metaprogramming as well as the procedural and functional paradigms [30].&lt;br /&gt;
&lt;br /&gt;
==Comparison by Application Domains==&lt;br /&gt;
Since Ruby and Python are almost similar languages built with the same broad goals, we cannot pin point on certain applications that may be built only in Python or Ruby. Yet, due to the certain differences that exist developers may prefer one over the other depending on the application's requirements.&lt;br /&gt;
&lt;br /&gt;
As Rails is one of the most popular web development frameworks, it can be said that Ruby is more popular for web development that Python. Ruby on Rails makes a great framework to develop both small as well as high traffic sites. Ruby is, at present, exceptionally good at one specific kind of small project: database-backed web applications. Ruby on Rails counteracts all of Ruby's small-project disadvantages [31].&lt;br /&gt;
&lt;br /&gt;
Some of the top organizations using Ruby on Rails include NASA, Motorola, Google, Amazon, Cisco, IBM, Oracle, Yahoo [32][33].&lt;br /&gt;
&lt;br /&gt;
Python is better suited to desktop apps on Linux because you can perhaps integrate better to the host platform [34]. Python is believed to give better performance than Ruby and has a large standard library which is why more developers prefer it for areas such as text and numerical processing, operating system interfaces, internet protocols, internet security, software engineering, graphic design. Some of the big companies using Python include Google, Yahoo, CERN and NASA [35][36][1].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Python_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[2] http://wiki.python.org/moin/SimplePrograms&lt;br /&gt;
&amp;lt;br&amp;gt;[3] http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[4] http://www.fincher.org/tips/Languages/Ruby/&lt;br /&gt;
&amp;lt;br&amp;gt;[5] http://en.wikipedia.org/wiki/High-level_programming_language&lt;br /&gt;
&amp;lt;br&amp;gt;[6] http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/&lt;br /&gt;
&amp;lt;br&amp;gt;[7] http://en.wikipedia.org/wiki/Type_system#Dynamic_typing&lt;br /&gt;
&amp;lt;br&amp;gt;[8] http://en.wikipedia.org/wiki/Automatic_memory_management&lt;br /&gt;
&amp;lt;br&amp;gt;[9] http://oreilly.com/catalog/9780596523695/&lt;br /&gt;
&amp;lt;br&amp;gt;[10] http://en.wikipedia.org/wiki/Immutable_object&lt;br /&gt;
&amp;lt;br&amp;gt;[11] http://johan.kiviniemi.name/blag/ruby-vs-python&lt;br /&gt;
&amp;lt;br&amp;gt;[12] http://www.devarticles.com/c/a/Ruby-on-Rails/Code-Blocks-and-Iteration/&lt;br /&gt;
&amp;lt;br&amp;gt;[13] http://www.secnetix.de/olli/Python/lambda_functions.hawk&lt;br /&gt;
&amp;lt;br&amp;gt;[14] http://en.wikipedia.org/wiki/Multiple_inheritance&lt;br /&gt;
&amp;lt;br&amp;gt;[15] http://docs.python.org/tutorial/classes.html&lt;br /&gt;
&amp;lt;br&amp;gt;[16] http://en.wikipedia.org/wiki/Mixin&lt;br /&gt;
&amp;lt;br&amp;gt;[17] http://www.wellho.net/resources/ex.php4?item=r119/mixdem.rb&lt;br /&gt;
&amp;lt;br&amp;gt;[18] http://blog.ianbicking.org/ruby-python-power.html&lt;br /&gt;
&amp;lt;br&amp;gt;[19] http://dev.pocoo.org/~mitsuhiko/pythonruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[20] http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
&amp;lt;br&amp;gt;[21] http://wiki.python.org/moin/WebFrameworks&lt;br /&gt;
&amp;lt;br&amp;gt;[22] http://3columns.net/habitual/docs/RailsVsDjango.pdf&lt;br /&gt;
&amp;lt;br&amp;gt;[23] www.venturedig.com/wordpress/wp-content/uploads/2009/04/django-vs-rails11.jpg&lt;br /&gt;
&amp;lt;br&amp;gt;[24] http://en.wikipedia.org/wiki/Ruby_MRI#Criticism&lt;br /&gt;
&amp;lt;br&amp;gt;[25] Ruby Cookbook: Recipes for Object Oriented Scripting : ISBN 10: 0-596-52369-6 | ISBN 13: 9780596523695&lt;br /&gt;
&amp;lt;br&amp;gt;[26] http://en.wikipedia.org/wiki/Type_system&lt;br /&gt;
&amp;lt;br&amp;gt;[27] http://www.ferg.org/projects/python_java_side-by-side.html&lt;br /&gt;
&amp;lt;br&amp;gt;[28] http://www.artima.com/weblogs/viewpost.jsp?thread=4639&lt;br /&gt;
&amp;lt;br&amp;gt;[29] http://www.razorvine.net/python/PythonComparedToJava&lt;br /&gt;
&amp;lt;br&amp;gt;[30] http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[31] http://www.infoq.com/news/2007/06/rubyvsjava&lt;br /&gt;
&amp;lt;br&amp;gt;[32] http://www.ruby-lang.org/en/documentation/success-stories/&lt;br /&gt;
&amp;lt;br&amp;gt;[33] http://blog.obiefernandez.com/content/2008/03/big-name-compan.html&lt;br /&gt;
&amp;lt;br&amp;gt;[34] http://ubuntuforums.org/showthread.php?t=845563&lt;br /&gt;
&amp;lt;br&amp;gt;[35] http://ubuntuforums.org/archive/index.php/t-416082.html&lt;br /&gt;
&amp;lt;br&amp;gt;[36] http://www.python.org/doc/faq/general&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19062</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 11 rubyvspython</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython&amp;diff=19062"/>
		<updated>2009-09-12T04:00:04Z</updated>

		<summary type="html">&lt;p&gt;Snirgud: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Ruby vs. Python=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Python and Ruby are amongst some of the most popular programming languages in use today. Although this page compares and contrasts the two languages, when compared to the other existing languages in the market today, Ruby and Python are almost similar and developed with the same overall goals. However, the differences that do exist have made these two languages the subject of debate between their users. &lt;br /&gt;
  &lt;br /&gt;
===Brief Descriptions===&lt;br /&gt;
&lt;br /&gt;
====Python====&lt;br /&gt;
Python is a high-level programming language with a design philosophy that emphasizes code readability, clear syntax and its standard library is large and comprehensive. Its use of indentation as block delimiters is unusual among popular programming languages. Python supports multiple programming paradigms (primarily object oriented, imperative, and functional), features a fully dynamic type system and automatic memory management and is often used as a scripting language [1].&lt;br /&gt;
&lt;br /&gt;
Here's some sample python code: [2]&lt;br /&gt;
 name = input('What is your name?\n')&lt;br /&gt;
 print('Hi, ' + name + '.')&lt;br /&gt;
&lt;br /&gt;
====Ruby====&lt;br /&gt;
Ruby is a dynamic, general purpose object-oriented programming language developed and designed by Yukihiro &amp;quot;Matz&amp;quot; Matsumoto who wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and reflective. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Python [3].&lt;br /&gt;
&lt;br /&gt;
Here's some sample ruby code: [4]&lt;br /&gt;
 puts &amp;quot;What is your name?&amp;quot;&lt;br /&gt;
 $name = STDIN.gets&lt;br /&gt;
 puts &amp;quot;Hi &amp;quot; + $name&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
There are a lot of features that Ruby and Python have in common. So before we compare their differences, its a good idea to list their common features:&lt;br /&gt;
* High-level programming languages (language with strong abstraction from the details of the computer [5]).&lt;br /&gt;
* Everything is an object, and variables are just references to objects [6].&lt;br /&gt;
* Fully dynamic type system&lt;br /&gt;
:A language is dynamically typed when majority of its type checking is performed at run-time as opposed to at compile-time [7].&lt;br /&gt;
* Both provide an interactive prompt [6].&lt;br /&gt;
* Automatic memory management&lt;br /&gt;
:In computer science, garbage collection is a form of automatic memory management. The garbage collector attempts to reclaim garbage, or memory used by objects that are no longer in use by the application [8].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, let us see how these two languages differ in their features:&lt;br /&gt;
&lt;br /&gt;
''For a brief summary of differences, see [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_11_rubyvspython#Summary_of_Differences table] below.''&lt;br /&gt;
&lt;br /&gt;
====Strings in Python vs. Strings in Ruby====&lt;br /&gt;
String objects in Python are immutable whereas in Ruby strings are mutable objects [9]. &lt;br /&gt;
&lt;br /&gt;
An immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. If an object is known to be immutable, it can be copied simply by making a copy of a reference to it instead of copying the entire object. Because a reference is usually much smaller than the object itself, this results in memory savings and a boost in execution speed [10].&lt;br /&gt;
&lt;br /&gt;
So in Python, adding a string to another can create several unwanted intermediate strings and consume memory. In Ruby however, strings can expand as required without consuming much memory or time [9].  &lt;br /&gt;
&lt;br /&gt;
====Defining Private Variables and Methods==== &lt;br /&gt;
In Python &amp;quot;_&amp;quot; is appended in front of a variable or method name to make it private. &lt;br /&gt;
&lt;br /&gt;
In Ruby, all variables defined in a class are by default private and no specific keyword is required to make them so. For making a method private, a method ''private'' is called just before the actual method.&lt;br /&gt;
 private&lt;br /&gt;
   def sample_method_name&lt;br /&gt;
[11]&lt;br /&gt;
&lt;br /&gt;
====Code Blocks vs. Lambdas====&lt;br /&gt;
In Ruby, a code block is an object which contains certain code along with a context required to execute it. A code block can be thought of as a function not bound to a name. This is one of the most distinctive and unique features in Ruby. A code block in Ruby is defined as follows [12]:&lt;br /&gt;
 [1,2,3].each { |i| puts i}&lt;br /&gt;
&lt;br /&gt;
In Python, the concept of code blocks does not exist but the ability of creating unnamed functions can be achieved using lambdas. The lambda function acts like any standard function in Python. A lambda may be used as follows [13]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; (lambda x: x*2)(3)&lt;br /&gt;
 8&lt;br /&gt;
&lt;br /&gt;
====Functions and Methods==== &lt;br /&gt;
There are no functions and methods separately in Ruby; all of them are methods. &lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 puts string.count('o'), string.length  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, for example, len() is a function, but items() is a method.&lt;br /&gt;
 string = 'Hello world'&lt;br /&gt;
 print string.count('o'), len(string)  # prints 2, 11&lt;br /&gt;
&lt;br /&gt;
In Python, one needs to write self as the first parameter of a method definition. In Ruby, self is automatically available in a similar fashion as ''this'' in C++ [11].&lt;br /&gt;
&lt;br /&gt;
====Multiple Inheritance====&lt;br /&gt;
Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. This contrasts with single inheritance, where a class may inherit from at most one superclass [14].&lt;br /&gt;
&lt;br /&gt;
Python offers support for multiple inheritance and a class definition with multiple base classes looks like this [15]:&lt;br /&gt;
 class DerivedClassName(Base1, Base2, Base3):&lt;br /&gt;
    &amp;lt;statement-1&amp;gt;&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    .&lt;br /&gt;
    &amp;lt;statement-N&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby does not support multiple inheritance but provides support so that classes can import modules as mixins [3]. &lt;br /&gt;
A mixin is a class that provides a certain functionality to be inherited by a subclass, while not meant for instantiation (the generating of objects of that class). Inheriting from a mixin is not a form of specialization but is rather a means of collecting functionality. A class may inherit most or all of its functionality from one or more mixins through multiple inheritance [16]. &lt;br /&gt;
 require &amp;quot;tcalc&amp;quot;&lt;br /&gt;
 class Invoice&lt;br /&gt;
   include Tcalc    # The line that mixes&lt;br /&gt;
[17]&lt;br /&gt;
&lt;br /&gt;
====Support for Threads==== &lt;br /&gt;
Ruby does not support OS (preemptive) threads and most code is not threadsafe. &lt;br /&gt;
&lt;br /&gt;
Python does support preemptive OS threads which can be used to handle concurrency well when some threads are blocking on external sources (disk access, network IO, waiting on a socket, etc) [18].&lt;br /&gt;
&lt;br /&gt;
====Boolean Values==== &lt;br /&gt;
In Python you have a boolean data type called bool which is a subclass of int and which can either be True or False. Every Python object can either be True or False which is defined by overriding the __nonzero__ method of an object. By default all empty objects (empty lists, dicts, tuples, strings etc) are False. This also applies to 0 and 0.0 [19].&lt;br /&gt;
&lt;br /&gt;
In Ruby the situation is completely different. There is no boolean data type but there are two singletons (true, instance of TrueClass and false, instance of FalseClass). Everything but nil and false is true. It's also not override-able [19].&lt;br /&gt;
&lt;br /&gt;
====Syntax Differences==== &lt;br /&gt;
* Unlike Python, in Ruby indentation is not significant.&lt;br /&gt;
* In Python, one has to write private instance variables using the long form self.__foobar. In Ruby, the form is @foobar.&lt;br /&gt;
* Ruby provides public, private, and protected to enforce access while Python uses underscore __convention__.&lt;br /&gt;
* Unlike Python, in Ruby parentheses for method calls are usually optional.&lt;br /&gt;
* Ruby uses ''elsif'' instead of ''elif'' as in Python.&lt;br /&gt;
* Ruby uses ''require'' instead of ''import'' as in Python. The usage however remains the same.&lt;br /&gt;
[6]&lt;br /&gt;
&lt;br /&gt;
====Summary of Differences====&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!  !! Python !! Ruby           &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Strings&lt;br /&gt;
| Immutable || Mutable&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Variables&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || private by default&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Private Methods&lt;br /&gt;
| &amp;quot;_&amp;quot; is appended in front || method private called before actual method&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Code Blocks&lt;br /&gt;
| Do not exist - Lambdas used instead. || Exist.&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Functions and Methods&lt;br /&gt;
| Have a different significance || No difference&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Multiple Inheritance&lt;br /&gt;
| Supported || Not Supported - uses mixins&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Threads&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
! Boolean Data Type&lt;br /&gt;
| Supported || Not Supported&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Differences in (Web) Programming Environments==&lt;br /&gt;
Web development in Ruby is done using the framework, Ruby on Rails. Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework used with an Agile development methodology for rapid development. It uses the Model-View-Controller (MVC) architecture pattern to organize application programming [20]. Considered to be one of the best web development frameworks in the market, Ruby on Rails has helped to substantially increase the popularity of Ruby.&lt;br /&gt;
&lt;br /&gt;
In the case of Python, there are several web development frameworks such as Django, Grok, Pylons, TurboGears, web2py, Zope [21]. Django is designed with a similar architecture and feature set as Rails to be just as efficient without being just a clone. &lt;br /&gt;
&lt;br /&gt;
So while either frameworks may be used to develop a good web application, there are certain differences in both these frameworks [22]:&lt;br /&gt;
* Django has built in support for developer-friendly templates while Rails needs third party library support.&lt;br /&gt;
* Rails has in-built javascript support while Django has no direct support.&lt;br /&gt;
* In terms of Performance and Scalability, Django is considered better.&lt;br /&gt;
* Lesser number of plugins and support available for Django compared to Rails.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rails has for some time retained the top position in the popularity charts with developers. However, the situation seems to be changing with Django beating Rails since 2008 [23].&lt;br /&gt;
&lt;br /&gt;
[[Image:django-vs-rails.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Interesting Feature(s) Comparison: When is Python or Ruby preferred over the other==&lt;br /&gt;
&lt;br /&gt;
Python may be considered better than Ruby in the following cases [24]:&lt;br /&gt;
* Performance&lt;br /&gt;
:Ruby's interpreter performance trails compared to Python mainly due to the design of the interpreter. To execute Ruby code, the interpreter builds a syntax tree from the source code and then evaluates the syntax tree directly, instead of first compiling it into a more efficiently executable form.&lt;br /&gt;
* Threading&lt;br /&gt;
:Ruby's threading model has some inherent limitations which render it difficult to use or unsafe in some scenarios.&lt;br /&gt;
* Unicode&lt;br /&gt;
:Ruby does not yet have native support for Unicode or multibyte strings.&lt;br /&gt;
* Backward compatibility&lt;br /&gt;
:Ruby suffers from backward compatibility problems. &lt;br /&gt;
However, Ruby 2.0 aims to address all of the aforementioned problems.&lt;br /&gt;
&lt;br /&gt;
Ruby may be considered better than Python in the following cases [25]:&lt;br /&gt;
* Ruby on Rails is considered on of the most efficient web development frameworks (see section 1.3 for details).&lt;br /&gt;
* Ruby provides mutable string support (see section 1.2.1 for more details).&lt;br /&gt;
* Ruby supports usage of constants [19].&lt;br /&gt;
&lt;br /&gt;
==Advantages Over Statically Typed Languages==&lt;br /&gt;
A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. Statically typed languages include Ada, C, C++, C#, JADE, Java, Fortran, Haskell, ML, Pascal, Perl and Scala [26].&lt;br /&gt;
&lt;br /&gt;
====Code Size====&lt;br /&gt;
Python/Ruby are concise and compact as compared to Java which is verbose. This is shown in the example below:&lt;br /&gt;
 &lt;br /&gt;
Python&lt;br /&gt;
 print &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
 public class HelloWorld&lt;br /&gt;
 {&lt;br /&gt;
    public static void main (String[] args)&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
====Static vs. Dynamic====&lt;br /&gt;
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That's what it means to say that Python is a dynamically typed language. Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required [27].&lt;br /&gt;
&lt;br /&gt;
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception. That's what it means to say that Java is a statically typed language. Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn't remember its type, and must be explicitly cast to the desired type [27].&lt;br /&gt;
&lt;br /&gt;
====Flexibility====&lt;br /&gt;
Flexibility of dynamically typed langauges such as Python and Ruby makes writing code significantly easier. Modules are easier to write, and easier to change. There are no build time issues at all [28].&lt;br /&gt;
* Java does not support operator overloading [29].&lt;br /&gt;
* Generators (functions that save state between different results) not present in Java [29].&lt;br /&gt;
* Ruby/Python support metaprogramming as well as the procedural and functional paradigms [30].&lt;br /&gt;
&lt;br /&gt;
==Comparison by Application Domains==&lt;br /&gt;
Since Ruby and Python are almost similar languages built with the same broad goals, we cannot pin point on certain applications that may be built only in Python or Ruby. Yet, due to the certain differences that exist developers may prefer one over the other depending on the application's requirements.&lt;br /&gt;
&lt;br /&gt;
As Rails is one of the most popular web development frameworks, it can be said that Ruby is more popular for web development that Python. Ruby on Rails makes a great framework to develop both small as well as high traffic sites. Ruby is, at present, exceptionally good at one specific kind of small project: database-backed web applications. Ruby on Rails counteracts all of Ruby's small-project disadvantages [31].&lt;br /&gt;
&lt;br /&gt;
Some of the top organizations using Ruby on Rails include NASA, Motorola, Google, Amazon, Cisco, IBM, Oracle, Yahoo [32][33].&lt;br /&gt;
&lt;br /&gt;
Python is better suited to desktop apps on Linux because you can perhaps integrate better to the host platform [34]. Python is believed to give better performance than Ruby and has a large standard library which is why more developers prefer it for areas such as text and numerical processing, operating system interfaces, internet protocols, internet security, software engineering, graphic design. Some of the big companies using Python include Google, Yahoo, CERN and NASA [35][36][1].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Python_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[2] http://wiki.python.org/moin/SimplePrograms&lt;br /&gt;
&amp;lt;br&amp;gt;[3] http://en.wikipedia.org/wiki/Ruby_%28programming_language%29&lt;br /&gt;
&amp;lt;br&amp;gt;[4] http://www.fincher.org/tips/Languages/Ruby/&lt;br /&gt;
&amp;lt;br&amp;gt;[5] http://en.wikipedia.org/wiki/High-level_programming_language&lt;br /&gt;
&amp;lt;br&amp;gt;[6] http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/&lt;br /&gt;
&amp;lt;br&amp;gt;[7] http://en.wikipedia.org/wiki/Type_system#Dynamic_typing&lt;br /&gt;
&amp;lt;br&amp;gt;[8] http://en.wikipedia.org/wiki/Automatic_memory_management&lt;br /&gt;
&amp;lt;br&amp;gt;[9] http://oreilly.com/catalog/9780596523695/&lt;br /&gt;
&amp;lt;br&amp;gt;[10] http://en.wikipedia.org/wiki/Immutable_object&lt;br /&gt;
&amp;lt;br&amp;gt;[11] http://johan.kiviniemi.name/blag/ruby-vs-python&lt;br /&gt;
&amp;lt;br&amp;gt;[12] http://www.devarticles.com/c/a/Ruby-on-Rails/Code-Blocks-and-Iteration/&lt;br /&gt;
&amp;lt;br&amp;gt;[13] http://www.secnetix.de/olli/Python/lambda_functions.hawk&lt;br /&gt;
&amp;lt;br&amp;gt;[14] http://en.wikipedia.org/wiki/Multiple_inheritance&lt;br /&gt;
&amp;lt;br&amp;gt;[15] http://docs.python.org/tutorial/classes.html&lt;br /&gt;
&amp;lt;br&amp;gt;[16] http://en.wikipedia.org/wiki/Mixin&lt;br /&gt;
&amp;lt;br&amp;gt;[17] http://www.wellho.net/resources/ex.php4?item=r119/mixdem.rb&lt;br /&gt;
&amp;lt;br&amp;gt;[18] http://blog.ianbicking.org/ruby-python-power.html&lt;br /&gt;
&amp;lt;br&amp;gt;[19] http://dev.pocoo.org/~mitsuhiko/pythonruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[20] http://en.wikipedia.org/wiki/Ruby_on_Rails&lt;br /&gt;
&amp;lt;br&amp;gt;[21] http://wiki.python.org/moin/WebFrameworks&lt;br /&gt;
&amp;lt;br&amp;gt;[22] http://3columns.net/habitual/docs/RailsVsDjango.pdf&lt;br /&gt;
&amp;lt;br&amp;gt;[23] www.venturedig.com/wordpress/wp-content/uploads/2009/04/django-vs-rails11.jpg&lt;br /&gt;
&amp;lt;br&amp;gt;[24] http://en.wikipedia.org/wiki/Ruby_MRI#Criticism&lt;br /&gt;
&amp;lt;br&amp;gt;[25] Ruby Cookbook: Recipes for Object Oriented Scripting : ISBN 10: 0-596-52369-6 | ISBN 13: 9780596523695&lt;br /&gt;
&amp;lt;br&amp;gt;[26] http://en.wikipedia.org/wiki/Type_system&lt;br /&gt;
&amp;lt;br&amp;gt;[27] http://www.ferg.org/projects/python_java_side-by-side.html&lt;br /&gt;
&amp;lt;br&amp;gt;[28] http://www.artima.com/weblogs/viewpost.jsp?thread=4639&lt;br /&gt;
&amp;lt;br&amp;gt;[29] http://www.razorvine.net/python/PythonComparedToJava&lt;br /&gt;
&amp;lt;br&amp;gt;[30] http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html&lt;br /&gt;
&amp;lt;br&amp;gt;[31] http://www.infoq.com/news/2007/06/rubyvsjava&lt;br /&gt;
&amp;lt;br&amp;gt;[32] http://www.ruby-lang.org/en/documentation/success-stories/&lt;br /&gt;
&amp;lt;br&amp;gt;[33] http://blog.obiefernandez.com/content/2008/03/big-name-compan.html&lt;br /&gt;
&amp;lt;br&amp;gt;[34] http://ubuntuforums.org/showthread.php?t=845563&lt;br /&gt;
&amp;lt;br&amp;gt;[35] http://ubuntuforums.org/archive/index.php/t-416082.html&lt;br /&gt;
&amp;lt;br&amp;gt;[36] http://www.python.org/doc/faq/general&lt;/div&gt;</summary>
		<author><name>Snirgud</name></author>
	</entry>
</feed>