<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coding N Design</title>
	<atom:link href="http://codingndesign.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://codingndesign.com/blog</link>
	<description>Design and Coding Beautiful Software</description>
	<lastBuildDate>Tue, 01 May 2012 06:14:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Learning The Dart Language-Classes-Part3</title>
		<link>http://codingndesign.com/blog/?p=283</link>
		<comments>http://codingndesign.com/blog/?p=283#comments</comments>
		<pubDate>Tue, 01 May 2012 06:05:30 +0000</pubDate>
		<dc:creator>sankarsan</dc:creator>
				<category><![CDATA[Programming & Languages]]></category>
		<category><![CDATA[Dart]]></category>
		<category><![CDATA[DartLang]]></category>

		<guid isPermaLink="false">http://codingndesign.com/blog/?p=283</guid>
		<description><![CDATA[In the last post we discussed about method &#38; getter/setter, we will continue our discussion on other aspects of Dart classes in this post, as well. Operators can be thought of as functions with special notation ,like other OO languages Dart also supports operator overloading. You have to use the operator keyword to redefine an [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D283"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D283&amp;source=sankarsan&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In the <a href="http://codingndesign.com/blog/?p=280" target="_blank">last post</a> we discussed about method &amp; getter/setter, we will continue our discussion on other aspects of Dart classes in this post, as well.</p>
<p>Operators can be thought of as functions with special notation ,like other OO languages Dart also supports operator overloading. You have to use the <font size="5">operator</font> keyword to redefine an operator as shown below:</p>
<pre class="brush: csharp; title: ; notranslate">
class Complex
{
  int real,imaginary;
  Complex(this.real,this.imaginary){}

  Complex operator +(Complex c){
    return new Complex(this.real+c.real,this.imaginary+c.imaginary);
  }
  Complex operator -(Complex c){
    return new Complex(this.real-c.real,this.imaginary-c.imaginary);
  }
  String toString(){
    var retval;
    if(imaginary&lt;0) {
      retval = real.toString() + &quot; -i&quot; + imaginary.abs().toString();
    }
    else{
      retval = real.toString() + &quot; +i&quot; + imaginary.toString();
    }
    return retval;
  }
}
</pre>
<p>Last but not the least, is inheritance.Dart allows us to create subclasses from a base class using the <font size="5">extends</font> keyword like Java.The following snippet demonstrates inheritance and method overriding.</p>
<pre class="brush: java; title: ; notranslate">
class A{
  void M1(){
    print(&quot;A::M1()&quot;);
  }
}
class B extends A{
  void M1(){
    print(&quot;B::M1()&quot;);
  }
}

void main() {
 var a = new B();
 a.M1();
}

//Prints:B::M1()
</pre>
<p>We will add an instance variable and try to override the same.</p>
<pre class="brush: java; title: ; notranslate">
class A{
  var x = 10;
  void M1(){
    print(&quot;A::M1()&quot;);
  }
}
class B extends A{
  var x = 1;
}
</pre>
<p>There is an exception:</p>
<p><font color="#ff0000">&#8216;D:\Dart\DartFunctionsDemo.dart&#8217;: Error: line 24 pos 7: field &#8216;x&#8217; of class &#8216;B&#8217; conflicts with instance member &#8216;x&#8217; of super class &#8216;A&#8217;.</font></p>
<p>Apparently it seems that Dart does not support overriding instance variables. But to my surprise the code compiles in <a title="http://try.dartlang.org/s/i20r" href="http://try.dartlang.org/s/i20r">http://try.dartlang.org/s/i20r</a>. Not sure if I am landing up in any version issues or what exactly is going on.</p>
<p>Similar to get the methods the getter/setters can also be overridden as shown below:</p>
<pre class="brush: java; title: ; notranslate">
class A{
  var x = 10;
  int get X() {
    print(&quot;A::X()&quot;);
    return x;
  }
  void M1(){
    print(&quot;A::M1()&quot;);
  }
}
class B extends A{
  var x_ = 1;
  int get X() =&gt; x_;
  void M1(){
    print(&quot;B::M1()&quot;);
  }
}
void main() {
 var a = new B();
 a.M1();
 print(a.X);
}
//Prints:10
</pre>
<p>We can invoke the base class functions using <font size="5">super</font> keyword as in Java.</p>
<pre class="brush: java; title: ; notranslate">
class B extends A{
  var x_ = 1;
  int get X() =&gt; x_;
  void M1(){
    super.M1();
    print(&quot;B::M1()&quot;);
  }
}
</pre>
<p>Let’s add constructors in the class A and B as shown below:</p>
<pre class="brush: java; title: ; notranslate">
void main() {

 var a = new B();

}

class A{
  var x = 10;
  int get X() {
    print(&quot;A::X()&quot;);
    return x;
  }
  A(){

    print(&quot;A constructor&quot;);

  }
  void M1(){
    print(&quot;A::M1()&quot;);
  }
}
class B extends A{
  var x_ = 1;
  int get X() =&gt; x_;
  B() {
    print(&quot;B constructor&quot;);
  }
  void M1(){
    super.M1();
    print(&quot;B::M1()&quot;);
  }
}
</pre>
<p>The program prints:</p>
<p>A constructor   <br />B constructor</p>
<p>This clearly shows that the base constructor is invoked followed by the derived class. </p>
<p>Let’s tweak the code in A by adding a parameter in the constructor.</p>
<pre class="brush: java; title: ; notranslate">
class A{
  var x = 10;
  int get X() {
    print(&quot;A::X()&quot;);
    return x;
  }
  A(this.x){

    print(&quot;A constructor&quot;);

  }
  void M1(){
    print(&quot;A::M1()&quot;);
  }
}
</pre>
<p>After running the program we will get the following error.</p>
<p><font color="#ff0000">&#8216;D:\Dart\DartFunctionsDemo.dart&#8217;: Error: line 26 pos 7: unresolved implicit call to super constructor &#8216;A()&#8217;     <br />&#160; B() {      <br />&#160;&#160;&#160;&#160;&#160; ^</font></p>
<p>This is because there is no call made to the constructor A(this.x) while instantiating B. Changing the constructor definition in B and explicitly invoking the super class constructor solves the problem.</p>
<pre class="brush: java; title: ; notranslate">
B(a):super(a) {
  print(&quot;B constructor&quot;);
}
</pre>
<p>This is all about classes in the next post we will discuss about interfaces.</p>
]]></content:encoded>
			<wfw:commentRss>http://codingndesign.com/blog/?feed=rss2&#038;p=283</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning The Dart Language&#8211;Classes&#8211;Part 2</title>
		<link>http://codingndesign.com/blog/?p=280</link>
		<comments>http://codingndesign.com/blog/?p=280#comments</comments>
		<pubDate>Sat, 28 Apr 2012 22:30:00 +0000</pubDate>
		<dc:creator>sankarsan</dc:creator>
				<category><![CDATA[Programming & Languages]]></category>
		<category><![CDATA[Dart]]></category>
		<category><![CDATA[DartLang]]></category>

		<guid isPermaLink="false">http://codingndesign.com/blog/?p=280</guid>
		<description><![CDATA[In the last post we have discussed about classes and object instantiation/initialization in Dart.In this post we will take a look methods and getter/setters. Methods in Dart are two types : instance methods and class level static methods like any other OO language. The code below shows the definition &#38; invocation of a typical instance [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D280"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D280&amp;source=sankarsan&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In the <a href="http://codingndesign.com/blog/?p=278" target="_blank">last post</a> we have discussed about classes and object instantiation/initialization in Dart.In this post we will take a look methods and getter/setters.</p>
<p>Methods in Dart are two types : <font size="4"><strong>instance</strong></font> methods and class level <font size="4"><strong>static</strong></font> methods like any other OO language. The code below shows the definition &amp; invocation of a typical instance method.</p>
<pre class="brush: csharp; title: ; notranslate">
class Customer
{
  int id;
  String fn;
  String ln; 

  String getFullName(){
    return fn + &quot; &quot; + ln;
  }
}

void main() { 

  var a = new Customer();
  a.fn =&quot;Sankarsan&quot;;
  a.ln =&quot;Bose&quot;;
  print(a.getFullName());
}
//Prints: Sankarsan Bose
</pre>
<p>The following example shows the definition &amp; invocation of a typical class level static method.</p>
<pre class="brush: csharp; title: ; notranslate">
class Logger
{
  static void LogToConsole(String msg)
  {
    print(msg);
  }
}

void main() { 

  Logger.LogToConsole(&quot;Hello World !!&quot;);
}
</pre>
<p>Dart also let you define getter/setter using get and set keywords as shown below:</p>
<pre class="brush: csharp; title: ; notranslate">
class Customer
{
  int id;
  String fn;
  String ln; 

  String get firstName() =&gt; fn;
  set firstName(String value) =&gt; fn = value; 

  String get lastName() =&gt; ln;
  set lastName(String value) =&gt; ln = value; 

  String get fullName() =&gt; firstName + &quot; &quot; + lastName;
}

void main() { 

  var c = new Customer();
  c.firstName =&quot;Sankarsan&quot;;
  c.lastName = &quot;Bose&quot;; 

  print(c.fullName);
}
</pre>
<p>The getter/setter are defined as methods and accessed as fields/properties.Since these are defined as methods you can provide additional validations here as shown below:</p>
<pre class="brush: csharp; title: ; notranslate">
set firstName(String value) {
  if(value != null &amp;&amp; value.trim().length&gt;0) fn = value;
}
</pre>
<p>But if I compare to a language like C# where there is support for properties, the major difference is that Dart does not let you define access modifier (private) at class level and the whole purpose from encapsulation standpoint seems to be lost.</p>
<p>However the Dart designers feel differently &#8211; <a title="http://www.dartlang.org/articles/idiomatic-dart/#fields-getters-setters" href="http://www.dartlang.org/articles/idiomatic-dart/#fields-getters-setters">http://www.dartlang.org/articles/idiomatic-dart/#fields-getters-setters</a></p>
<blockquote><p>This blurring the line between fields and getters/setters is fundamental to the language. The clearest way to think of it is that fields <em>are</em> just getters and setters with magical implementations. This means that you can do fun stuff like override an inherited getter with a field and vice versa. If an interface defines a getter, you can implement it by simply having a field with the same name and type. If the field is mutable (not <code>final</code>) it can implement a setter that an interface requires.</p>
<p>In practice, what this means is that you don&#8217;t have to insulate your fields by defensively hiding them behind boilerplate getters and setters like you would in Java or C#. If you have some exposed property, feel free to make it a public field. If you don&#8217;t want it to be modified, just make it <code>final</code>.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://codingndesign.com/blog/?feed=rss2&#038;p=280</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning The Dart Language&#8211;Classes</title>
		<link>http://codingndesign.com/blog/?p=278</link>
		<comments>http://codingndesign.com/blog/?p=278#comments</comments>
		<pubDate>Sat, 21 Apr 2012 19:42:17 +0000</pubDate>
		<dc:creator>sankarsan</dc:creator>
				<category><![CDATA[Programming & Languages]]></category>
		<category><![CDATA[Dart]]></category>
		<category><![CDATA[DartLang]]></category>

		<guid isPermaLink="false">http://codingndesign.com/blog/?p=278</guid>
		<description><![CDATA[Dart is an object oriented language and supports classes and inheritance. A typical Dart class definition is shown below. The object of this class is created using the new operator as shown below. One notable difference with most of the typical OO languages we work with is, the access modifier. Here everything is public by [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D278"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D278&amp;source=sankarsan&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Dart is an object oriented language and supports classes and inheritance. A typical Dart class definition is shown below.</p>
<pre class="brush: csharp; title: ; notranslate">
class Customer
{
  int id;
  String firstName;
  String lastName; 

  String toString() {
    return firstName + &quot; &quot; + lastName;
  }
}
</pre>
<p>The object of this class is created using the <font color="#0000ff" size="4">new</font> operator as shown below.</p>
<pre class="brush: csharp; title: ; notranslate">
void main() {
  var c = new Customer();
  c.id = 1;
  c.firstName = &quot;Sankarsan&quot;;
  c.lastName  = &quot;Bose&quot;;
  print(c);
}
</pre>
<p>One notable difference with most of the typical OO languages we work with is, the access modifier. Here everything is <font size="4"><strong>public by default and privacy level is controlled at the package level</strong></font> rather than the class level. You can find an interesting discussion in the thread below on such a design decision:</p>
<p><a title="http://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/5a5951ae0d334dde" href="http://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/5a5951ae0d334dde">http://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/5a5951ae0d334dde</a></p>
<p>Each class has a default constructor. The above example makes use of the same.We can also define constructor with parameters as shown below:</p>
<pre class="brush: csharp; title: ; notranslate">
class Customer
{
  int id;
  String firstName;
  String lastName; 

  Customer(id,firstName,lastName){
    this.id = id;
    this.firstName = firstName;
    this.lastName = lastName;
  }
  String toString() {
    return firstName + &quot; &quot; + lastName;
  }
}
</pre>
<p>This needs to be instantiated as </p>
<pre class="brush: csharp; title: ; notranslate">
var c = new Customer(1,&quot;Sankarsan&quot;,&quot;Bose&quot;);
</pre>
<p>We can shorten the constructor as</p>
<pre class="brush: csharp; title: ; notranslate">
Customer(this.id,this.firstName,this.lastName){}
</pre>
<p>If we try to define another constructor as</p>
<pre class="brush: csharp; title: ; notranslate">
Customer(id,firstName){
  this.id = id;
  this.firstName = firstName;
  this.lastName =&quot;&quot;;
}
</pre>
<p>We get the error</p>
<p><font color="#ff0000" size="4">&#8216;D:\Dart\DartFunctionsDemo.dart&#8217;: Error: line 33 pos 3: field or method &#8216;Customer.&#8217; already defined      <br />&#160; Customer(id,firstName){</font></p>
<p>This is because overloading is not supported.</p>
<p>However we can have multiple constructors using <font size="4"><strong>named constructor</strong></font>. Some best examples of named constructors are there in the library class <font color="#0000ff">Date</font>.</p>
<pre class="brush: csharp; title: ; notranslate">
/**
  * Constructs a new [Date] instance with current date time value.
  * The [timeZone] of this instance is set to the local time-zone.
  */
Date.now();
</pre>
<p>We can create a Date instance as,</p>
<pre class="brush: csharp; title: ; notranslate">
Date d = new Date.now();
</pre>
<p>Now let’s add two final variables to our class definition.</p>
<pre class="brush: csharp; title: ; notranslate">
class Customer
{
  final int x,y;
  int id;
  String firstName;
  String lastName; 

  Customer(this.id,this.firstName,this.lastName){}

  String toString() {
    return firstName + &quot; &quot; + lastName;
  }
}
</pre>
<p>The <font color="#0000ff" size="4">final</font> variables needs to be initialized before object creation and it will lead to the following error:</p>
<p><font color="#ff0000" size="4">&#8216;D:\Dart\DartFunctionsDemo.dart&#8217;: Error: line 32 pos 49: <strong>final field &#8216;x&#8217; not initialized        <br /></strong>&#160; Customer(this.id,this.firstName,this.lastName){}</font></p>
<p>This can be achieved through <strong><font size="4">Initializer List</font></strong> as shown below:</p>
<pre class="brush: csharp; title: ; notranslate">
Customer(this.id,this.firstName,this.lastName):x=0,y=0{}
</pre>
<p>There is another type of constructor called <font size="4"><strong>F<font color="#000000">actory Constructor</font></strong></font>. This constructor does not create a new instance of the class but returns an instance based on logic like Singleton or from a cache.</p>
<p>The code below shows a Singleton implementation. The _internal is basically like a private constructor used from the factory constructor to internally create an instance.</p>
<pre class="brush: csharp; title: ; notranslate">
class Config
{
  static Config cfg ;
  int x;
  factory Config(){
    if(cfg==null)
      {
       cfg = new Config._internal();
      }
    return cfg;
  }
  Config._internal(){}
}
</pre>
<p>The snippet shown below will print 10 proving that factory constructor is returning the same instance every time it is invoked.</p>
<pre class="brush: csharp; title: ; notranslate">
void main() {
  Config c = new Config();
  c.x =10;

  c = new Config();
  print(c.x);

}
</pre>
<p>There is another type of constructor called <font size="4"><strong>Constant Constructors</strong></font> used to create compile time constant or immutable object using <font color="#0000ff" size="4">const</font> keyword as shown below:</p>
<pre class="brush: csharp; title: ; notranslate">
class Test{
  final int x,y;
  const Test (this.x,this.y);
}
</pre>
<p>Constant object with identical properties are basically the same object instance. So the code below will print true.</p>
<pre class="brush: csharp; title: ; notranslate">
void main() {
  var a = const Test(10,20);
  var b = const Test(10,20);
  print(a==b);
}
</pre>
<p>So far we have discussed only about constructor, more to follow on classes.</p>
]]></content:encoded>
			<wfw:commentRss>http://codingndesign.com/blog/?feed=rss2&#038;p=278</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning The Dart Language&#8211;Functions</title>
		<link>http://codingndesign.com/blog/?p=275</link>
		<comments>http://codingndesign.com/blog/?p=275#comments</comments>
		<pubDate>Thu, 19 Apr 2012 17:39:15 +0000</pubDate>
		<dc:creator>sankarsan</dc:creator>
				<category><![CDATA[Programming & Languages]]></category>
		<category><![CDATA[Dart]]></category>
		<category><![CDATA[DartLang]]></category>

		<guid isPermaLink="false">http://codingndesign.com/blog/?p=275</guid>
		<description><![CDATA[In the Dart world functions are first class citizens, they can be treated as objects, passed as parameters to other functions and returned from functions.To start with let’s look at the simplest notation. The definition of m1 is quite same as a function definition in javascript apart from the fact that here even the function [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D275"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D275&amp;source=sankarsan&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><font size="6">I</font>n the Dart world functions are first class citizens, they can be treated as objects, passed as parameters to other functions and returned from functions.To start with let’s look at the simplest notation.</p>
<pre class="brush: jscript; title: ; notranslate">
void main() {

  print(m1(10,20));
}

m1(a,b)
{
  return a+b;
}
//prints 30
</pre>
<p>The definition of m1 is quite same as a function definition in javascript apart from the fact that here even the <font color="#0000ff" size="4">function</font> keyword is also not required.However it is advised to use the types in the function definition. With types the function definition will change to:</p>
<pre class="brush: csharp; title: ; notranslate">
int m1(int a,int b)
{
  return a+b;
}
</pre>
<p>The following variation is also supported:</p>
<pre class="brush: csharp; title: ; notranslate">
m1(int a,int b)
{
  return a+b;
}
</pre>
<p>Here the return type is not specified and hence it is dynamic.But,in this case obviously the return type will be expected to be an “<font color="#0000ff" size="4">int</font>”. So the following call will give an error in checked execution mode.</p>
<p>String s =m1(10,20);</p>
<p><font color="#ff0000" size="3">Unhandled exception:      <br />&#8216;D:\Dart\DartFunctionsDemo.dart&#8217;: Failed type check: line 3 pos 15: type &#8216;Smi&#8217; is not assignable to type &#8216;String&#8217; of &#8216;s&#8217;.       <br />0. Function: &#8216;::main&#8217; url: &#8216;D:\Dart\DartFunctionsDemo.dart&#8217; line:3 col:15</font></p>
<p>Don’t get confused by the word <font color="#0000ff" size="4">Smi</font> that stands for small int. VM internally treats it as small int. I think error message&#160; is not that user friendly as “int” is the type available for programmers.</p>
<p>The other two possible variations can be:</p>
<pre class="brush: csharp; title: ; notranslate">
m1(int a,b)
{
  return a+b;
}

m1(a,int b)
{
  return a+b;
}
</pre>
<p>The following call to the above function definition returns 1020.</p>
<p>String s =m1(&quot;10&quot;,20);</p>
<p>Okay. So the dynamic type is determined to be of type String. Good. As expected. Let’s change the function a little bit by reversing parameters a and b in the addition expression:</p>
<pre class="brush: csharp; title: ; notranslate">
 m1( a,int b)
 {
  return b+a;
 }
</pre>
<p>This leads to an error quite obviously adding string to an int.</p>
<p><font color="#ff0000" size="3">Failed type check: line 1468 pos 22: type &#8216;OneByteString&#8217; is not assignable to type &#8216;num&#8217; of &#8216;other&#8217;.</font></p>
<p>Dart also supports optional arguments and named parameters.</p>
<pre class="brush: csharp; title: ; notranslate">
 m1( int a,int b,[int c])
 {
   return (b+a)*c;
 }
</pre>
<p>Here c is the optional argument.</p>
<p>The following code leads to a <font color="#0000ff">NullPointerException</font> as the default value of optional argument is null.</p>
<pre class="brush: csharp; title: ; notranslate">
print(m1(10,20));
</pre>
<p>We can also provide default values as shown below:</p>
<pre class="brush: csharp; title: ; notranslate">
m1( int a,int b,[int c=1])
{
  return (b+a)*c;
}
</pre>
<p>In case there are multiple optional arguments we can also specify their names during function call.</p>
<pre class="brush: csharp; title: ; notranslate">
void main() {

  print(m1(10,20,c:10));
}

m1( int a,int b,[int c=1,int d=1])
{
  return (b+a)*(c+d);
}
</pre>
<p>As mentioned in the beginning here functions are first class citizens. The following code shows how we can pass function as arguments.Here m1 is passed as&#160; argument to m2.</p>
<pre class="brush: csharp; title: ; notranslate">
void main() {
  print(m2(m1,20,30));
}

m1( int a,int b,[int c=1,int d=1])
{
  return (b+a)*(c+d);
}

m2(f,a,b)
{
  return f(a,b);
}
//prints 100
</pre>
<p>Here we can further simplify the function definition as [Quite similar to Lambda expressions for those who are familiar with C#]</p>
<pre class="brush: csharp; title: ; notranslate">
 var m = (a,b) =&gt; a+b;
</pre>
<p>And then calling,</p>
<pre class="brush: csharp; title: ; notranslate">
print(m2(m,20,30));
</pre>
<p>Similarly a function can also return a function. In the code below we are returning a function to add/multiply based on an input flag.</p>
<pre class="brush: csharp; title: ; notranslate">
m1(flag)
{
  var r;
  if(flag==1) r = (x,y) =&gt; x+y;
  if(flag==2) r = (x,y) =&gt; x*y;
  return r;
}
</pre>
<p>Then we can invoke the same as,</p>
<pre class="brush: csharp; title: ; notranslate">
print(m2(m1(1),20,30));
</pre>
<p>This is all about functions in brief. In the next post we will move into Classes.</p>
]]></content:encoded>
			<wfw:commentRss>http://codingndesign.com/blog/?feed=rss2&#038;p=275</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning The Dart Language &#8211; Variables</title>
		<link>http://codingndesign.com/blog/?p=272</link>
		<comments>http://codingndesign.com/blog/?p=272#comments</comments>
		<pubDate>Wed, 18 Apr 2012 17:11:11 +0000</pubDate>
		<dc:creator>sankarsan</dc:creator>
				<category><![CDATA[Programming & Languages]]></category>
		<category><![CDATA[Dart]]></category>
		<category><![CDATA[DartLang]]></category>

		<guid isPermaLink="false">http://codingndesign.com/blog/?p=272</guid>
		<description><![CDATA[Dart is inherently a dynamically typed language like Javascript. The variables can be declared using the “var” keyword as shown below: This program quite obviously prints out 11 as expected. Let’s modify it further by assigning a String value as shown below: The program will print 11 and A1. So this is a typical behavior [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D272"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D272&amp;source=sankarsan&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><font size="6">D</font>art is inherently a <font size="4">dynamically typed language</font> like Javascript. The variables can be declared using the “<font color="#0000ff" size="4">var</font>” keyword as shown below:</p>
<pre class="brush: jscript; title: ; notranslate">
void main() {

  var i=10;
  i=10;
  print(++i);
}
</pre>
<p>This program quite obviously prints out 11 as expected.</p>
<p>Let’s modify it further by assigning a String value as shown below:</p>
<pre class="brush: jscript; title: ; notranslate">
void main() {

  var i=10;
  i=10;
  print(++i);
  i=&quot;A&quot;;
  print(++i);
}
</pre>
<p>The program will print 11 and A1. So this is a typical behavior same as any dynamic language e.g. javascript.</p>
<p>Dart also support optional static typing.I can change the declaration of i to a Built-In type <font color="#0000ff" size="4">int</font>.</p>
<pre class="brush: jscript; title: ; notranslate">
void main() {

  int i=10;
  i=10;
  print(++i);
  i=&quot;A&quot;;
  print(++i);
}
</pre>
<p>But to my surprise the program still runs in Dart Editor without any error.This is because Dart support two execution modes:</p>
<ol>
<li>Checked Mode – If optional static types are provided while defining the variables then the type checks are performed at runtime.</li>
<li>Production Mode – No type checkings are performed. This is the default mode.</li>
</ol>
<p>I can switch the execution mode in Dart Editor as shown below:</p>
<p><a href="http://codingndesign.com/blog/wp-content/uploads/2012/04/dartvar.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="dartvar" border="0" alt="dartvar" src="http://codingndesign.com/blog/wp-content/uploads/2012/04/dartvar_thumb.png" width="558" height="387" /></a></p>
<p>As expected I get an error at runtime:</p>
<p><font color="#ff0000">Unhandled exception:     <br />&#8216;D:\Dart\DartFunctionsDemo.dart&#8217;: <font size="4"><em>Failed type check: line 8 pos 5: type &#8216;OneByteString&#8217; is not assignable to type &#8216;int&#8217; of &#8216;i&#8217;.         <br /></em></font> 0. Function: &#8216;::main&#8217; url: &#8216;D:\Dart\DartFunctionsDemo.dart&#8217; line:8 col:5</font></p>
<p>This in short is all about variables in Dart.. Next we will look into functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://codingndesign.com/blog/?feed=rss2&#038;p=272</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebSockets using Socket.IO</title>
		<link>http://codingndesign.com/blog/?p=267</link>
		<comments>http://codingndesign.com/blog/?p=267#comments</comments>
		<pubDate>Sun, 01 Jan 2012 06:46:21 +0000</pubDate>
		<dc:creator>sankarsan</dc:creator>
				<category><![CDATA[Framework & Libraries]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Socket.IO]]></category>
		<category><![CDATA[WebSockets]]></category>

		<guid isPermaLink="false">http://codingndesign.com/blog/?p=267</guid>
		<description><![CDATA[Prologue Today, web is all about being near real-time.We all expect to see the updates we are supposed to see e.g.what my friends are doing on Facebook, we expect our messages &#38; news will be refreshed instantly in our web pages. With advent of technologies like AJAX , Comet etc. gone are the days where [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D267"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D267&amp;source=sankarsan&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><u><strong>Prologue</strong></u></p>
<p>Today, web is all about being near real-time.We all expect to see the updates we are supposed to see e.g.what my friends are doing on Facebook, we expect our messages &amp; news will be refreshed instantly in our web pages. With advent of technologies like AJAX , Comet etc. gone are the days where we will have to refresh our web pages (using browser refresh button) every now and then, to see updated data.But all this partial page refreshes are happening using XmlHttpRequest , iframes or long polling. There was no standardized protocol to handle this and each of these techniques landed up initiating multiple HTTP connections to the server.So here comes <font size="4"><strong>WebSocket</strong></font> – a new protocol specification from W3C as part of HTML5.</p>
<p><u><strong>WebSocket</strong></u></p>
<p>WebSocket is a protocol for <font size="4"><em>two-way communication</em></font> between client (in most cases you can assume it will be the browser) and server (a TCP/HTTP server supporting WebSocket) using a <font size="4"><em>single TCP connection</em></font>.This will take away the overhead of </p>
<ul>
<li>Multiple TCP connections </li>
<li>Same/similar header data being transferred each time over the wire </li>
<li>Customized ways to tracking or correlating requests and responses. </li>
</ul>
<p>The WebSocket specification has two parts one, the WebSocket protocol specification and another the WebSocket API specification which is the spec for client API used for communicating to the server.As of now,</p>
<ul>
<li>Google Chrome natively supports WebSocket API </li>
<li>Mozilla Firefox supports the same with a different interface called MozWebSocket instead of WebSocket </li>
<li>IE 9 does not support WebSocket API at all </li>
</ul>
<p>The webservers supporting WebSockets are</p>
<ul>
<li>Jetty </li>
<li>Node.js with Socket.IO </li>
<li>IIS 8 on Windows 8 ( This is still in a developer preview and not commercially released) </li>
<li>Tornado </li>
</ul>
<p>In this post we will focus on how we can work with WebSocket with<font size="4"> Node.js</font> and <font size="4">Socket.IO</font></p>
<p><u><strong>Node.js</strong></u></p>
<p><font size="4"><strong><a href="http://nodejs.org/" target="_blank">Node.JS</a></strong></font> is a javascript based <font size="4"><em>event driven</em></font> highly scalable server framework running on <a href="http://code.google.com/p/v8/" target="_blank">Google’s V8 Javascript Engine</a>.</p>
<p>Node now has a windows installer which can be downloaded from <a title="http://nodejs.org/dist/v0.6.6/node-v0.6.6.msi" href="http://nodejs.org/dist/v0.6.6/node-v0.6.6.msi">http://nodejs.org/dist/v0.6.6/node-v0.6.6.msi</a></p>
<p>Once you have installed node you need a good javascript editor (Sublime Text is my choice) to develop your first HTTP Server as shown below:</p>
<pre class="brush: jscript; title: ; notranslate">
//Import module http
var http = require('http');
http.createServer(function(request,response){
    //Set response header
    response.writeHead(200,{'Content-Type':'text/html'});
    //Write response html
    response.end(&quot;&lt;h1&gt;Hello World !!!! I am running on Node.js&lt;/h1&gt;&quot;);
}).listen(8124); // HTTP Server listens at port 8124, default host is localhost
console.log('Server started at http://localhost:8124')
</pre>
<p>There are many objects in Node which generates or emits events. These are called the event emitters.e.g. the http.Server object is an event emitter. The event emitter expose a generic function named <em><font size="3"><strong>on</strong></font></em>, this function takes in event name and callback as arguments.    <br />Using this function we can add call back to the server which will get fired when any new user gets connected as shown in the snippet below:</p>
<pre class="brush: jscript; title: ; notranslate">
//Import module http
var http = require('http');

var server = http.createServer(function(request,response){
    //Set response header
    response.writeHead(200,{'Content-Type':'text/html'});
    //Write response html
    response.end(&quot;&lt;h1&gt;Hello World !!!! I am running on Node.js&lt;/h1&gt;&quot;);
}).listen(8124); // HTTP Server listens at port 8124, default host is localhost

server.on('connection', function (stream) {
  console.log('Connection !!!!');
});

console.log('Server started at http://localhost:8124')
</pre>
<p>Now let’s take a quick look into what socket.io is about.</p>
<p><u><strong>Socket.io</strong></u></p>
<p><font size="4"><strong><a href="http://socket.io/" target="_blank">Socket.io</a></strong></font> is a module for for node.js which enables socket like near real-time communication over browser. In reality it supports the following transport along with web sockets:</p>
<ul>
<li>xhr-polling </li>
<li>xhr-multipart </li>
<li>htmlfile </li>
<li>websocket </li>
<li>flashsocket </li>
<li>jsonp-polling </li>
</ul>
<p>So it support communication even with browsers where WebSocket is not supported.But we will restrict this discussion primarily to WebSockets.</p>
<p>The code for a simple socket server is shown in the code below:</p>
<pre class="brush: jscript; title: ; notranslate">
//Import Socket.io module
var io = require('socket.io');
//Creates a HTTP Server
var socket = io.listen(8124);
//Bind the Connection Event
//This will be fired every time when a new connection is made
socket.sockets.on('connection',function(socket){

        //This will be fired when data is received from client over a single socket
        socket.on('message', function(msg){
            console.log('Received message from client ',msg);
        });
        //Emit a message to client
        socket.emit('greet',{hello: 'world'});
        //This will fire when the client has disconnected
        socket.on('disconnect', function(){
            console.log('Server has disconnected');
        });
});
</pre>
<p>Now let’s look at the following client code.We need to do the following to build a simple HTML client.</p>
<ul>
<li>We need to add a reference socket.io.js. In this case I have referenced it from my node server itself.If the HTML is also rendered from the node server we can use relative path for the same.</li>
<li>Create a socket and then bind the appropriate event listeners.</li>
</ul>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
    &lt;title&gt;WebSocket Client Demo&lt;/title&gt;
    script src=&quot;http://localhost:8124/socket.io/socket.io.js&quot;&gt;&lt;/script
   script&gt;
        //Create a socket and connect to the server
        var socket = io.connect('http://localhost:8124/');
        //This event will be emitted once connection is made to the server
        socket.on(&quot;connect&quot;,function(){
            alert(&quot;Client has connected to the server&quot;);
        });
        //This event will be client receives a &quot;greet&quot; message from server
        socket.on('greet', function (data) {
            alert(data.hello);
            }
        );
    &lt;/script
&lt;/html&gt;
</pre>
<p>Now with all these code (server and client) we will run the same and analyze the network calls to understand how the interaction is happening.</p>
<p>The code shows two alerts once when it’s connected to the server and then when it receives the greet message from the server.</p>
<p>The general URL scheme followed by socket.io is</p>
<p>[scheme] &#8216;://&#8217; [host] &#8216;/&#8217; [namespace] &#8216;/&#8217; [protocol version] &#8216;/&#8217; [transport id] &#8216;/&#8217; [session id] &#8216;/&#8217; ( &#8216;?&#8217; [query] )</p>
<p>Here ,</p>
<ul>
<li><strong>Scheme</strong> http/https</li>
<li><strong>Host</strong> is the hostname of the socket server</li>
<li><strong>Namespace</strong> is the Socket.IO namespace default is socket.io</li>
<li><strong>Protocol Version</strong> client support default is 1</li>
<li><strong>Transport ID</strong> is for different supported transports like WebSockets, xhr-polling etc.</li>
<li>Session ID , the web socket session unique session id for the client.</li>
</ul>
<p>First a http request is issued as shown below with a timestamp parameter.</p>
<p><a href="http://codingndesign.com/blog/wp-content/uploads/2012/01/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codingndesign.com/blog/wp-content/uploads/2012/01/image_thumb.png" width="634" height="317" /></a></p>
<p>Due to the absence of transport and session id server identifies this to be a new connection request and returns the following response containing <em><strong><font size="3">session id and transport options</font></strong></em>.</p>
<p><a href="http://codingndesign.com/blog/wp-content/uploads/2012/01/image1.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codingndesign.com/blog/wp-content/uploads/2012/01/image_thumb1.png" width="564" height="72" /></a></p>
<p>Here I am using Google Chrome which supports websocket so another request (HTTP 101 – Protocol Switching request) is issued switching the protocol to websocket as shown below.</p>
<p><a href="http://codingndesign.com/blog/wp-content/uploads/2012/01/image2.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codingndesign.com/blog/wp-content/uploads/2012/01/image_thumb2.png" width="522" height="278" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://codingndesign.com/blog/?feed=rss2&#038;p=267</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actors in Akka&#8211;Part 1</title>
		<link>http://codingndesign.com/blog/?p=254</link>
		<comments>http://codingndesign.com/blog/?p=254#comments</comments>
		<pubDate>Sun, 11 Dec 2011 11:14:51 +0000</pubDate>
		<dc:creator>sankarsan</dc:creator>
				<category><![CDATA[Framework & Libraries]]></category>
		<category><![CDATA[Akka]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://codingndesign.com/blog/?p=254</guid>
		<description><![CDATA[Akka is a framework providing Erlang like Actor based concurrency.It runs on the JVM, and has both Scala and Java APIs available.In this post we will take a look into the actors in Akka and how we can perform some basic tasks like starting, stopping the actors and passing messages. We first need to define [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D254"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D254&amp;source=sankarsan&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://akka.io" target="_blank"><font size="5">Akka</font></a> is a framework providing Erlang like Actor based concurrency.It runs on the JVM, and has both Scala and Java APIs available.In this post we will take a look into the actors in Akka and how we can perform some basic tasks like starting, stopping the actors and passing messages. </p>
<p>We first need to define an actor by extending <font color="#0000ff">akka.actor.Actor</font> class and overriding the <font color="#0000ff">receive</font> method as shown below.This is a simple actor just echoes on the console whatever input is fed to it.</p>
<pre class="brush: scala; title: ; notranslate">
class EchoActor extends Actor {
  def receive = {
    case s: String =&gt; println(s)
  }
}
</pre>
<p>To create an instance of the Actor we need to use the static member <font color="#0000ff">Actor.actorOf</font> as shown below:</p>
<pre class="brush: scala; title: ; notranslate">
val echo = Actor.actorOf[EchoActor]
</pre>
<p>It can also be instantiated as </p>
<pre class="brush: scala; title: ; notranslate">
val echo = Actor.actorOf(new EchoActor())
</pre>
<p>The actorOf method return reference of an actor as instance of <font color="#0000ff">akka.actor.ActorRef</font> class.</p>
<p>Next step is to start the actor as shown below:</p>
<pre class="brush: scala; title: ; notranslate">
echo.start()
</pre>
<p>We can pass a message to the actor using <strong><font color="#0000ff">!</font></strong> symbol as:</p>
<pre class="brush: scala; title: ; notranslate">
echo ! &quot;Hello World&quot;
</pre>
<p>The complete program looks something like.</p>
<pre class="brush: scala; title: ; notranslate">
package main
import akka.actor.Actor

case object Start

object Main {
  def main(args: Array[String]): Unit = {
    println(&quot;Start&quot;);
    val echo = Actor.actorOf[EchoActor]
    echo.start()
    echo ! &quot;Hello World&quot;
    echo.stop()
  }
}
class EchoActor extends Actor {
  def receive = {
    case s: String =&gt; println(s)
  }
}
</pre>
<p>This is simple…really very very simple. With this much of knowledge about the Akka API let us try to address the problem of creating a circular ring of N nodes, where each node will pass the message received to it’s next node and so on. M no of messages will be passed through the ring so that there are total N*M message exchange.</p>
<p>The steps followed in creating this is</p>
<ul>
<li>Create a list of N nodes</li>
<li>Link them together using message passing</li>
<li>Send M messages to the first node which will relay it through the ring.</li>
</ul>
<pre class="brush: scala; title: ; notranslate">
package main
import akka.actor.Actor
import akka.actor.Actor._
import akka.actor.ActorRef
import scala.collection.mutable.ListBuffer

case class Link (node:ActorRef)
object Ring {

  def main(args: Array[String]): Unit = {
    start(2,2)
  }
  def create(N:Int): IndexedSeq[ActorRef] = {
    for(i&lt;-1 to N) yield actorOf(new RingNode(&quot;NODE&quot;+i)).start()
  }
  def link(nodes:IndexedSeq[ActorRef]){
    for(i&lt;-0 to nodes.length-1){
      if(i!=nodes.length-1) nodes(i) ! Link(nodes(i+1))
      else nodes(i) ! Link(nodes(0))
    }
  }
  def message(M:Int,node:ActorRef){
    for(i&lt;-1 to M) node ! &quot;Message&quot;+i
  }
  def start(N: Int, M:Int)  {
    val nodes = create(N)
    link(nodes)
    message(M,nodes(0))
  }
}
class RingNode(name: String) extends Actor{
  var  next:ActorRef = null;
  var buffer: ListBuffer[String] = new ListBuffer()
  def receive = {
    case Link(node:ActorRef) =&gt; next = node
    case s:String =&gt; process(s,next)
  }
  private def process(msg:String,next:ActorRef){
    if(!buffer.contains(msg)){
        println(&quot;Node:::&quot;+name)
        println(&quot;Received message: %s&quot;.format(msg))
        buffer.append(msg)
        next ! msg
    }

  }
}
</pre>
<p>The output will be,</p>
<p>Node:::NODE1   <br />Received message: Message1    <br />Node:::NODE1    <br />Received message: Message2    <br />Node:::NODE2    <br />Received message: Message1    <br />Node:::NODE2    <br />Received message: Message2    </p>
]]></content:encoded>
			<wfw:commentRss>http://codingndesign.com/blog/?feed=rss2&#038;p=254</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TPL Dataflows &#8211; DevCon 2011</title>
		<link>http://codingndesign.com/blog/?p=248</link>
		<comments>http://codingndesign.com/blog/?p=248#comments</comments>
		<pubDate>Sun, 27 Nov 2011 04:59:36 +0000</pubDate>
		<dc:creator>sankarsan</dc:creator>
				<category><![CDATA[In Focus]]></category>

		<guid isPermaLink="false">http://codingndesign.com/blog/?p=248</guid>
		<description><![CDATA[Task Parallel Library Data Flows View more presentations from SANKARSAN BOSE]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D248"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D248&amp;source=sankarsan&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://codingndesign.com/blog/wp-content/uploads/2011/11/tpl.png"><img src="http://codingndesign.com/blog/wp-content/uploads/2011/11/tpl.png" alt="" title="tpl" width="581" height="437" class="alignnone size-full wp-image-251" /></a></p>
<div id="__ss_10137094" style="width: 425px;">
<p><strong style="display: block; margin: 12px 0 4px;"></strong></p>
<p><strong style="display: block; margin: 12px 0 4px;"></strong></p>
<p><strong style="display: block; margin: 12px 0 4px;"></strong></p>
<p><strong style="display: block; margin: 12px 0 4px;"><a title="Task Parallel Library Data Flows" href="http://www.slideshare.net/sankarsan78/task-parallel-library-data-flows" target="_blank">Task Parallel Library Data Flows</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/10137094" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="425" height="355"></iframe></p>
<div style="padding: 5px 0 12px;">View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/sankarsan78" target="_blank">SANKARSAN BOSE</a></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://codingndesign.com/blog/?feed=rss2&#038;p=248</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Go Language &#8211; Variable Declaration</title>
		<link>http://codingndesign.com/blog/?p=242</link>
		<comments>http://codingndesign.com/blog/?p=242#comments</comments>
		<pubDate>Sat, 19 Nov 2011 19:20:47 +0000</pubDate>
		<dc:creator>sankarsan</dc:creator>
				<category><![CDATA[Programming & Languages]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Go]]></category>

		<guid isPermaLink="false">http://codingndesign.com/blog/?p=242</guid>
		<description><![CDATA[Since last two weeks, I am trying to play around with Go language from Google as and when I am getting some time.But till now I am stuck in the basics only.The variable declaration part seemed very interesting to me. Two important point needs to be noted: The variable declaration must be preceded by the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D242"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D242&amp;source=sankarsan&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Since last two weeks, I am trying to play around with Go language from Google as and when I am getting some time.But till now I am stuck in the basics only.The variable declaration part seemed very interesting to me.</p>
<div>Two important point needs to be noted:</div>
<div>
<div>
<ul>
<li>The variable declaration must be preceded by the keyword <span class="Apple-style-span" style="color: #0000c0; font-size: medium;">&#8220;var&#8221;</span></li>
<li>The variable declaration is reversed when compared to C i.e. type name comes after the variable name as shown below</li>
</ul>
<pre class="brush: csharp; title: ; notranslate">
var i = 10
</pre>
<div>In case the variable is initialized the type information can be omitted as shown below:</div>
<div>var i = 10;</div>
<div>This is exactly similar to the implicitly typed local variables in C# 3.0+.</div>
<div>Consider a situation where we need to declare many variables together.</div>
<pre class="brush: csharp; title: ; notranslate">
var i =10
var j=20
var s = &quot;Hello World&quot;
</pre>
<div>Here Go offers a nice feature to do away with the repeated &#8220;var&#8221;s and group them together as shown below:</p>
<pre class="brush: csharp; title: ; notranslate">
var{
     i= 10
     j=20
     s = &quot;Hello World&quot;
}
</pre>
<div><em>However the C# still lacks this nice productivity feature leading to clean code.Hope we will see the same in the later versions of C#.</em></div>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://codingndesign.com/blog/?feed=rss2&#038;p=242</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coming Close To Clojure&#8211;Part 1</title>
		<link>http://codingndesign.com/blog/?p=239</link>
		<comments>http://codingndesign.com/blog/?p=239#comments</comments>
		<pubDate>Sun, 14 Aug 2011 19:59:58 +0000</pubDate>
		<dc:creator>sankarsan</dc:creator>
				<category><![CDATA[Programming & Languages]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Clojure]]></category>
		<category><![CDATA[Forms]]></category>

		<guid isPermaLink="false">http://codingndesign.com/blog/?p=239</guid>
		<description><![CDATA[Learning new programming languages always has been a fun.To me, it is a way to learn about solving problems in a different ways.Sometimes efficient and sometimes inefficient compared to languages you already know, obviously that depends upon the problem you are trying to solve.Recently I have started learning Clojure – A primarily JVM based (also [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D239"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcodingndesign.com%2Fblog%2F%3Fp%3D239&amp;source=sankarsan&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Learning new programming languages always has been a fun.To me, it is a way to learn about solving problems in a different ways.Sometimes efficient and sometimes inefficient compared to languages you already know, obviously that depends upon the problem you are trying to solve.Recently I have started learning Clojure – A primarily JVM based (also has it’s CLR version) dynamic language, designed as dialect of LISP.In recent years Clojure has gained popularity quite fast.I first got interested to learn this language after the watching the video( though it’s a two year old one) embedded below.</p>
<p> <iframe style="width: 512px; height: 288px" src="http://channel9.msdn.com/Shows/Going+Deep/Expert-to-Expert-Rich-Hickey-and-Brian-Beckman-Inside-Clojure/player?w=512&amp;h=288" frameborder="0" scrolling="no"></iframe>
<p>To get started with Clojure I used the Clojure REPL (Read-Eval-Print-Loop) where we can type in our program and see the output immediately.The actions of the REPL steps are shown in the figure below:</p>
<p><a href="http://codingndesign.com/blog/wp-content/uploads/2011/08/Drawing1.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Drawing1" border="0" alt="Drawing1" src="http://codingndesign.com/blog/wp-content/uploads/2011/08/Drawing1_thumb.png" width="480" height="300" /></a></p>
<p>The above steps are quite straightforward to understand but the term marked in red “Clojure Form”.In strict technical terms Clojure is a <a href="http://c2.com/cgi/wiki?HomoiconicLanguages" target="_blank">homoiconic</a> language i.e here code is data. In the evaluation step code is parsed as blocks (FORMS) and converted to data structures. These data structures are then compiled and executed. So we can day Clojure programs are composed of FORMS. Different types of Clojure Forms is shown in the figure below:</p>
<p><a href="http://codingndesign.com/blog/wp-content/uploads/2011/08/Drawing11.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Drawing1" border="0" alt="Drawing1" src="http://codingndesign.com/blog/wp-content/uploads/2011/08/Drawing1_thumb1.png" width="455" height="465" /></a></p>
<p>We will explore each of these in the upcoming posts but to have an initial understanding let us consider the following examples.</p>
<p>&#160;</p>
<p>       <a href="http://codingndesign.com/blog/wp-content/uploads/2011/08/clojuref.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="clojure f" border="0" alt="clojure f" src="http://codingndesign.com/blog/wp-content/uploads/2011/08/clojuref_thumb.png" width="634" height="243" /></a>
<p>In the next post we will talk a little bit about available IDEs and tools before we jump on actual programming stuff.</p>
]]></content:encoded>
			<wfw:commentRss>http://codingndesign.com/blog/?feed=rss2&#038;p=239</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

