<?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>Anay Kamat's Weblog &#187; Programming</title>
	<atom:link href="http://anaykamat.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://anaykamat.com</link>
	<description>Technology, Programming, Career, Fun, Friends And Thoughts</description>
	<lastBuildDate>Fri, 26 Nov 2010 08:02:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Understanding and Applying Artificial Neural Networks : Engineering Perspective</title>
		<link>http://anaykamat.com/2010/11/26/understanding-and-applying-artificial-neural-networks-engineering-perspective/</link>
		<comments>http://anaykamat.com/2010/11/26/understanding-and-applying-artificial-neural-networks-engineering-perspective/#comments</comments>
		<pubDate>Fri, 26 Nov 2010 07:57:02 +0000</pubDate>
		<dc:creator>Anay</dc:creator>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technologies]]></category>
		<category><![CDATA[ann]]></category>
		<category><![CDATA[artificial neural networks]]></category>
		<category><![CDATA[engineering perspective]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://anaykamat.com/?p=127</guid>
		<description><![CDATA[Lasts week (15th November to 19th November), NITTTR (National Institute of Technical Teachers Training and Research) had organized a course on Artificial Neural Networks at Government College Of Engineering &#8211; Farmagudi, Goa. I was appointed as course faculty for this event. Personally, I do not believe in concept of teaching. Humans are smart and intelligent [...]]]></description>
			<content:encoded><![CDATA[<p>Lasts week (15th November to 19th November), <a href="http://www.nitttrbhopal.org/index.php?option=com_content&amp;view=article&amp;id=237:goa-extension-centre&amp;catid=52:articles&amp;Itemid=261" target="_blank">NITTTR</a> (National Institute of Technical Teachers Training and Research) had organized a course on Artificial Neural Networks at <a href="http://www.gec.ac.in/">Government College Of Engineering &#8211; Farmagudi, Goa</a>. I was appointed as course faculty for this event.</p>
<p>Personally, I do not believe in concept of teaching. Humans are smart and intelligent animals and as such, they are capable of learning new things themselves based on their experience and observations. Thus, rather than providing a training, I preferred sharing my experience and knowledge on ANN with the members attending the course.</p>
<p>Considering the fact that this event was organized for staff of engineering colleges, the &#8220;Joint &#8211; Discussion&#8221; was titled, &#8220;<strong>Engineering Solutions With Artificial Intelligence Using A System Popularized As Artificial Neural Networks</strong>&#8220;.</p>
<p>Generally, we discuss Artificial Neural Networks either in theoretical perspective or in terms of purely scientific applications. However, the world of practical engineering is always different from theoretical or purely scientific perspective. The same applies to applications of ANN in perspective of modern digital engineering.</p>
<p>In this joint discussion, we spent first two days trying to understand the concept of artificial neural networks. To understand it practically, demonstrations were provided using the examples developed in JRuby. The code written for this purpose is now available on GitHub (The link is provided at the end of this post).</p>
<p>For next two days, all the participants were allowed to experiment with the JRuby code. Participants could play around with different training sets while modifying variables like learning rate, momentum, activation functions, number of hidden layers, number of neurons in hidden layers etc. They could also experiment with performing the same training using backpropagation algorithm and genetic algorithm. This helped them in understanding the challenges faced by engineers in practically implementing the solutions using ANN.</p>
<p>On the last day (Friday 19th, November 2010), we concluded the joint discussion by determining the capabilities and limitations of ANN based on the experience and knowledge obtained by participants in four days. At the end, a demo of <a href="http://userscripts.org/scripts/review/38736" target="_blank">OCR written in Javascript</a> was given by Tejas Vernekar.</p>
<p>During the joint discussion, some of the alternative non-neural solutions for few problems were discussed as well. A ruby equivalent of spell checker (which uses statistical language processing) originally developed in python was also demonstrated. The ruby equivalent code is available in the code in GitHub Repository.</p>
<p>In case you are interested in JRuby code used during the joint discussion, you can download it from <a href="https://github.com/kamatanay/JRuby-Neural-Networks" target="_blank">this GitHub repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2010/11/26/understanding-and-applying-artificial-neural-networks-engineering-perspective/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Just Released: Maya Programming Language</title>
		<link>http://anaykamat.com/2010/08/25/just-released-maya-programming-language/</link>
		<comments>http://anaykamat.com/2010/08/25/just-released-maya-programming-language/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 12:14:15 +0000</pubDate>
		<dc:creator>Anay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technologies]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[language translators]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://anaykamat.com/?p=123</guid>
		<description><![CDATA[Around one year ago, I had started experimenting with concepts of creating programming languages. I first started with building few DSLs (Domain Specific Languages) using Ruby and Boo. It was quite interesting to work on development of DSLs. While doing this, I learnt a lot about how the programming languages are developed. Eventually, I thought [...]]]></description>
			<content:encoded><![CDATA[<p>Around one year ago, I had started experimenting with concepts of creating programming languages. I first started with building few DSLs (Domain Specific Languages) using Ruby and Boo. It was quite interesting to work on development of DSLs. While doing this, I learnt a lot about how the programming languages are developed.</p>
<p>Eventually, I thought of writing my own programming language. While I was in engineering college as a student, we had a subject on language translators. This subject taught us lot of theory on how languages are compiled or interpreted. However, we never got a chance to write even a simple programming language during our practicals. According to few, it was not possible to write one in one semester&#8217;s time.</p>
<p>That turned out to be my main motivation. I decided to write this programming language without using any compiler tools like LEX and YACC. I ended up writing my own lexical analyzer, the grammar parser and the language using the concepts taught to us in engineering college only. I worked on it daily for around an hour and within two weeks, I had the basic language ready.</p>
<p>Today, the code is released under GPL license. It&#8217;s available on GitHub at <a href="http://github.com/kamatanay/MayaLanguage" target="_blank">http://github.com/kamatanay/MayaLanguage</a></p>
<p>I hope it would be useful for students learning language translators.</p>
<p>Why did I name it Maya? Well, that&#8217;s the name of my sweetheart wife. Isn&#8217;t that a sweet name?</p>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2010/08/25/just-released-maya-programming-language/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Error in ruby on rails documentation for ActionController::UrlWriter</title>
		<link>http://anaykamat.com/2010/05/30/error-in-ruby-on-rails-documentation-for-actioncontroller-urlwriter/</link>
		<comments>http://anaykamat.com/2010/05/30/error-in-ruby-on-rails-documentation-for-actioncontroller-urlwriter/#comments</comments>
		<pubDate>Sun, 30 May 2010 18:25:02 +0000</pubDate>
		<dc:creator>Anay</dc:creator>
				<category><![CDATA[My Thoughts]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technologies]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://anaykamat.com/?p=110</guid>
		<description><![CDATA[In Ruby on rails, methods that generate urls from named routes are not globally accessible. For example, you can&#8217;t access them from console (script/console). If you want to use these methods from such places, then the rails documentation for ActionController::UrlWriter suggests two ways of doing it. According to this documentation, you can: Include ActionController::UrlWriter in [...]]]></description>
			<content:encoded><![CDATA[<p>In Ruby on rails, methods that generate urls from named routes are not globally accessible. For example, you can&#8217;t access them from console (script/console). If you want to use these methods from such places, then the <a href="http://api.rubyonrails.org/classes/ActionController/UrlWriter.html" target="_blank">rails documentation for ActionController::UrlWriter</a> suggests two ways of doing it. According to this documentation, you can:</p>
<ol>
<li>Include ActionController::UrlWriter in your class</li>
<li>Call the method directly on ActionController::UrlWriter</li>
</ol>
<p>When I tried it out, only the first method worked. I was able to use methods generated from named routes in console after including ActionController::UrlWriter. However, it was not possible to call those methods on ActionController::UrlWriter. This looks like an issue with documentation to me.</p>
<p>It might be the case that the second method used to work in earlier version of rails. As rails is constantly being developed, some refactoring might have made the second method obsolete. I hope rails community will fix such issues in documentation soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2010/05/30/error-in-ruby-on-rails-documentation-for-actioncontroller-urlwriter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpec Matchers: Be careful while testing boolean values</title>
		<link>http://anaykamat.com/2010/05/30/rspec-matchers-be-careful-while-testing-boolean-values/</link>
		<comments>http://anaykamat.com/2010/05/30/rspec-matchers-be-careful-while-testing-boolean-values/#comments</comments>
		<pubDate>Sun, 30 May 2010 14:19:55 +0000</pubDate>
		<dc:creator>Anay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technologies]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[unit tests]]></category>

		<guid isPermaLink="false">http://anaykamat.com/?p=105</guid>
		<description><![CDATA[While testing methods that return boolean values in ruby (the ones that end in &#8216;?&#8217;), try to avoid following matchers: method_returning_true?.should be_true or method_returning_false?should be_false This is because, &#8216;be_true&#8217; and &#8216;be_false&#8217; matchers considers &#8216;nil&#8217; to be false and anything other than &#8216;nil&#8217; to be true. When we write methods in ruby which end with question [...]]]></description>
			<content:encoded><![CDATA[<p>While testing methods that return boolean values in ruby (the ones that end in &#8216;?&#8217;), try to avoid following matchers:</p>
<pre class="brush: ruby;">
method_returning_true?.should be_true
</pre>
<p>or</p>
<pre class="brush: ruby;">
method_returning_false?should be_false
</pre>
<p>This is because, &#8216;be_true&#8217; and &#8216;be_false&#8217; matchers considers &#8216;nil&#8217; to be false and anything other than &#8216;nil&#8217; to be true. When we write methods in ruby which end with question mark (&#8216;?&#8217;), intent is that the method will return boolean value. To ensure that our tests will always reflect the intent of code, use following to assert boolean values instead of using &#8216;be_true&#8217; or &#8216;be_false&#8217; matchers:</p>
<pre class="brush: ruby;">
method_returning_true?.should == true
</pre>
<p>or</p>
<pre class="brush: ruby;">
method_returning_false?.should == false
</pre>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2010/05/30/rspec-matchers-be-careful-while-testing-boolean-values/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple equivalent of &#8220;With&#8221; statement in C#</title>
		<link>http://anaykamat.com/2009/08/09/simple-equivalent-of-with-statement-in-c-sharp/</link>
		<comments>http://anaykamat.com/2009/08/09/simple-equivalent-of-with-statement-in-c-sharp/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 16:06:29 +0000</pubDate>
		<dc:creator>Anay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[lambdas]]></category>

		<guid isPermaLink="false">http://anaykamat.com/?p=84</guid>
		<description><![CDATA[Consider the following class in C# public class Person { private string name; private int age; public string Name{ get {return name;} set { name = value; } } public int Age{ get {return age;} set { age = value; } } } If I want to set the value of Name and Age property [...]]]></description>
			<content:encoded><![CDATA[<p>Consider the following class in C#</p>
<pre class="brush: csharp;">
	public class Person
	{
		private string name;
		private int age;

		public string Name{
			get {return name;}
			set { name = value; }
		}

		public int Age{
			get {return age;}
			set { age = value; }
		}
	}
</pre>
<p>If I want to set the value of Name and Age property on the instance of Person class, I&#8217;ll need to refer to that instance for every property I need to set in the code. For example:</p>
<pre class="brush: csharp;">
var person = new Person();
person.Name = &quot;Super Man&quot;;
person.Age = 30;
</pre>
<p>It would have been great if C# had an equivalent of VB&#8217;s &#8220;With..End&#8221; statement, where we could refer to the instance of Person class only once and then refer to properties only.</p>
<p>Today, I came across this post &#8220;<a href="http://blog.bittercoder.com/PermaLink,guid,d1831805-dbf7-4b74-a6fd-2e9ed437c3d9.aspx" target="_blank">mucking about with hashes&#8230;</a>&#8220;, which shows how C# lambdas could be used as hashes. Using this concept, I implemented a simple extension method that simulates the behavior of VB&#8217;s &#8220;With..End&#8221; statement to some extent.</p>
<p>Here is the code for extension method:</p>
<pre class="brush: csharp;">
	public static class MetaExtensions
	{
		public static void Set(this object obj,params Func&lt;string,object&gt;[] hash){
				foreach(Func&lt;string,object&gt; member in hash){
					var propertyName = member.Method.GetParameters()[0].Name;
					var propertyValue = member(string.Empty);
					obj.GetType()
						.GetProperty(propertyName)
							.SetValue(obj,propertyValue,null);
				};
		}
	}
</pre>
<p>Using this extension method, we can set the value of properties on instance of Person class as follows:</p>
<pre class="brush: csharp;">
var person = new Person();
person.Set(
	Name =&gt; &quot;Super Man&quot;,
	Age =&gt; 30
);
</pre>
<p>Isn&#8217;t that cool?</p>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2009/08/09/simple-equivalent-of-with-statement-in-c-sharp/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Y-Combinator in C#</title>
		<link>http://anaykamat.com/2009/04/08/y-combinator-in-csharp/</link>
		<comments>http://anaykamat.com/2009/04/08/y-combinator-in-csharp/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 14:19:26 +0000</pubDate>
		<dc:creator>Anay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technologies]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[functional programming]]></category>

		<guid isPermaLink="false">http://anaykamat.com/?p=58</guid>
		<description><![CDATA[For last few days, I was trying to use lambda feature of C# to implement Y-Combinator. After few trial and errors, I was able to implement it in C# 3.5. I&#8217;m currently posting the code here and in my next blog, I&#8217;ll explain how I derived it. In this code, Y-Combinator function, is used to [...]]]></description>
			<content:encoded><![CDATA[<p>For last few days, I was trying to use lambda feature of C# to implement Y-Combinator. After few trial and errors, I was able to implement it in C# 3.5. I&#8217;m currently posting the code here and in my next blog, I&#8217;ll explain how I derived it.</p>
<p>In this code, Y-Combinator function, is used to implement anonymous recursive-factorial function called &#8216;factorial&#8217;.</p>
<pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YCombinator
{
    class Program
    {
        delegate Func RecursiveFunction(RecursiveFunction f);

        static void Main(string[] args)
        {

            Func, Func&gt;, Func&gt; Y = (f) =&gt;
            {
                RecursiveFunction function = (h) =&gt;
                {
                    return (x) =&gt;
                    {
                        return f(h(h))(x);
                    };
                };
                return function(function);
            };

            Func factorial = Y(function=&gt;
            {
                return x =&gt;
                {
                    return x == 0 ? 1 : x * function(x - 1);
                };
            });
            Console.WriteLine(factorial(5));
            Console.ReadLine();
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2009/04/08/y-combinator-in-csharp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Be careful while using ‘replaceAll’ and ‘replaceFirst’ methods of String class in Java</title>
		<link>http://anaykamat.com/2008/10/27/be-careful-while-using-%e2%80%98replaceall%e2%80%99-and-%e2%80%98replacefirst%e2%80%99-methods-of-string-class-in-java/</link>
		<comments>http://anaykamat.com/2008/10/27/be-careful-while-using-%e2%80%98replaceall%e2%80%99-and-%e2%80%98replacefirst%e2%80%99-methods-of-string-class-in-java/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 07:55:50 +0000</pubDate>
		<dc:creator>Anay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[replaceAll]]></category>
		<category><![CDATA[replaceFirst]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://anaykamat.com/?p=54</guid>
		<description><![CDATA[Most of the time, while trying to replace a substring in a given string, either all its occurrences or just the first one, java programmers tend to use ‘replaceAll’ and ‘replaceFirst’ methods provided by String class in Java. Java programmers like to use these methods to replace substrings as compared to ‘replace’ method of String [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the time, while trying to replace a substring in a given string, either all its occurrences or just the first one, java programmers tend to use ‘replaceAll’ and ‘replaceFirst’ methods provided by String class in Java. Java programmers like to use these methods to replace substrings as compared to ‘replace’ method of String class because of different reasons like:</p>
<ol>
<li>‘replaceAll’ and ‘replaceFirst’ methods use regular expressions instead of character sequence. It is pre-assumed most of the time that using these methods will allow us to replace a given pattern in future, instead of just replacing a substring.</li>
<li>‘replaceAll’ and ‘replaceFirst’ methods are named such that they clarify the intent of their execution.</li>
</ol>
<p>However, while using these methods, we need to be very careful while providing the string value which would replace a given substring or a pattern. Let’s understand why with the following example:</p>
<p>Run the following java code:</p>
<pre class="brush: java;">public class StringReplace {

public static void main(String[] args){
String stringValue = &quot;test1 test2 test1 test3&quot;;
String replaceValue = &quot;test&quot;;
stringValue = stringValue.replaceAll(&quot;test1&quot;, replaceValue);
System.out.print(stringValue);
}

}</pre>
<p>This code works properly. But now try running the same code by changing the value of variable ‘replaceValue’ as:</p>
<pre class="brush: java;">String replaceValue = &quot;$100&quot;;</pre>
<p>This would result in an exception of type ‘IndexOutOfBoundException’. This is because the ‘$’ symbol is used to identify a group from the regular expression which is the first parameter of ‘replaceAll’ or ‘replaceFirst’ method. We can solve this problem by:</p>
<ol>
<li>Using ‘replace’ method: This would be the good choice if you want to replace a string literal and not a pattern.</li>
<li>Escaping ‘$’ symbol: If you need to a use regular expression, and your pattern has no groups identified, then you can escape any group identification symbols from your replace string as shown below:</li>
</ol>
<p style="text-align: center;">
<pre class="brush: java;">String replaceValue = java.util.regex.Matcher.quoteReplacement(&quot;$100&quot;);</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2008/10/27/be-careful-while-using-%e2%80%98replaceall%e2%80%99-and-%e2%80%98replacefirst%e2%80%99-methods-of-string-class-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Taking a close look at inheritance and closures in Javascript</title>
		<link>http://anaykamat.com/2008/06/30/taking-a-close-look-at-inheritance-and-closures-in-javascript/</link>
		<comments>http://anaykamat.com/2008/06/30/taking-a-close-look-at-inheritance-and-closures-in-javascript/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 10:03:24 +0000</pubDate>
		<dc:creator>Anay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://anaykamat.com/?p=53</guid>
		<description><![CDATA[Let’s play with inheritance and closures in Javascript. Take a look at the following javascript code: function BaseClass(){ var id=200; this.Id=function(){ return id; } } function ChildClass(){ var id=500; } ChildClass.prototype = new BaseClass(); var childObject=new ChildClass(); In Javascript, inheritance is achieved using prototype. When we try to access any member on Javascript object, it [...]]]></description>
			<content:encoded><![CDATA[<p>Let’s play with inheritance and closures in Javascript. Take a look at the following javascript code:</p>
<pre class="brush: jscript;">
function BaseClass(){
	var id=200;
	this.Id=function(){
		return id;
	}
}

function ChildClass(){
	var id=500;
}

ChildClass.prototype = new BaseClass();
var childObject=new ChildClass();
</pre>
<p>In Javascript, inheritance is achieved using prototype. When we try to access any member on Javascript object, it first tries to search for the member within that object. If the member is found, then its accessed otherwise it tries to search for that member in its prototype object.</p>
<p>We make BaseClass the parent class of ChildClass with the following instruction:</p>
<pre class="brush: jscript;">ChildClass.prototype = new BaseClass();</pre>
<p>Notice that ChildClass does not have a method called ‘Id’. When we make a call to method ‘Id’ on childObject, it will see that ChildClass does not have ‘Id’ method and so will take it from its prototype object which is nothing but the object of BaseClass.</p>
<p>Based on this knowledge, what do you think will be the output of the following instruction?</p>
<pre class="brush: jscript;">childObject.Id()</pre>
<p>If you think it should be 500, then you are wrong. The correct answer is 200. This happens due to what is known as Closures. According to a <a title="Javascript Closure Tutorial" href="http://www.javascriptkit.com/javatutors/closures.shtml" target="_blank">tutorial on javascript closures</a> by Morris Johns:</p>
<blockquote><p>&#8220;a closure is the local variables for a function &#8211; kept alive after the function has returned&#8221;</p></blockquote>
<p>To understand how this works in our case, let’s try to understand how javascript actually executes a call to the method ‘Id’ on childObject.</p>
<p>As childObject does not have a method called ‘Id’, it takes that method from its prototype and then executes it. You can imagine that Javascript performs the following steps to execute a call to the method ‘Id’ on childObject.</p>
<pre class="brush: jscript;">
childObject.Id = ChildClass.prototype.Id;
childObject.Id();
</pre>
<p>But does its mean that in Javascript, it’s not possible to override the values from base class/object at all? Well, It is possible by making a small change to our code. Javascript has a keyword called ‘this’. The ‘this’ keyword points to the object in which the method being called is present. For more information on ‘this’ keyword, refer to the article ‘<a title="this keyword tutorial" href="http://www.quirksmode.org/js/this.html" target="_blank">The this keyword</a>’.</p>
<p>In our current code, we are defining a variable using keyword ‘var’ which makes it local to the function in which it is defined. Due to this, closure comes into picture and call to the method ‘Id’ always prints the value from the BaseClass. To solve this problem, we need to refer to the variable ‘id’ using ‘this’ keyword. This will tell our method to use the value from the object in which the method has been placed. In this way, when the method is placed in ChildClass object, it will print the value of ‘id’ from ChildClass and not from BaseClass. Thus, the modified code which allows overriding is given below:</p>
<pre class="brush: jscript;">
function BaseClass(){
	this.id=200;
	this.Id=function(){
		return this.id;
	}
}

function ChildClass(){
	this.id=500;
}

ChildClass.prototype = new BaseClass();
var childObject=new ChildClass();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2008/06/30/taking-a-close-look-at-inheritance-and-closures-in-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Is JavaScript more object-oriented than other programming languages?</title>
		<link>http://anaykamat.com/2008/06/28/is-javascript-more-object-oriented-than-other-programming-languages/</link>
		<comments>http://anaykamat.com/2008/06/28/is-javascript-more-object-oriented-than-other-programming-languages/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 16:19:26 +0000</pubDate>
		<dc:creator>shareapost</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://anaykamat.com/2008/06/28/is-javascript-more-object-oriented-than-other-programming-languages/</guid>
		<description><![CDATA[Like this post? Publish It On Your Own Blog I started my career as a web developer before the dot.com crash. I learnt all about HTML, IIS, ASP, SQL Server and JavaScript. Equipped with the knowledge I built a few dynamic websites and carried my laptop with me to all my interviews and walked out [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<div align="center">
<b>Like this post? <a href='http://shareapost.com/?action=category&#38;id=19&#38;order=1&#38;blog=615' class='external' target='_blank'>Publish It On Your Own Blog</a></b></div>
<p></p>
<p>I started my career as a web developer before the dot.com crash.  I learnt all about HTML, IIS, ASP, SQL Server and JavaScript.  Equipped with the knowledge I built a few dynamic websites and carried my laptop with me to all my interviews and walked out of an interview with a job as a senior web developer.  Before .NET existed, creating scalable and maintainable web application was not easy.  ASP had a VB scripting engine.  It was not scalable and it did its best to glue the web front end design with the backend database access.  Most of the middle tier business logic and data access work had to be done using COM.  Looking back you couldn&#8217;t build an elegant web application without .NET.   JavaScript was used a lot in front-end web development mainly for client-side validation, scrolling tickers and special effects.  But most developers never took Javascript seriously as a programming language.  I know I didn&#8217;t but who would have guess that AJAX gave Javascript a more important position in the world of web development.  Its power is hidden in the browser!<br />
<span></span><br />
If you are not a Javascript developer, you will find writing client-side AJAX application in JavaScript a daunting task.  That was one of the reasons Microsoft extended Javascript so that the Javascript language more closely resembles .NET languages such as C# and VB.NET.  Actually JavaScript is an object-oriented programming language but there are a lot of C# and VB.NET OO type programmers who found coding in JavaScript less palatable.</p>
<p>In fact I read that some argue JavaScript is more object-oriented than C# or VB.NET.  In C# and VB.NET, there are objects and classes and an object is an instance of a class but a class does not exist in its own right.  In JavaScript, there are no classes.  Classes do not exist.  Only objects exist in JavaScript.  One of the best feature of JavaScript is you can easily extend it.  What is your thought on this?</p>
<p><!--adsense--></p>
<p>Douglas Crockford shares his knowledge on JavaScript through his article &#8220;<a href="http://javascript.crockford.com/survey.html" target="_blank">A Survey of the JavaScript Programming Language</a>&#8221; which I think all web developers should read for a more in depth understanding of JavaScript as a programming language.</p>
<p>Here&#8217;s what Douglas Crockford say about JavaScript.</strong></p>
<p>1. JavaScript is not Java.  Neither is it a subset of Java.  JavaScript shares C-family syntax with Java, but at a deeper level it shows greater similarity to the languages Scheme and Self. It is a small language, but it is also a suprisingly powerful and expressive language.</p>
<p>2.  It is not a toy language, but a full programming language with many distinctive properties.</p>
<p>3. JavaScript contains a small set of data types. It has the three primitive types boolean, number, and string and the special values null and undefined. Everything else is variations on the object type.</p>
<p>4. Objects can easily be nested inside of other objects, and expressions can reach into the inner objects.</p>
<p>5. Arrays in JavaScript are hashtable objects.</p>
<p>6. Functions in JavaScript look like C functions, except that they are declared with the function keyword instead of a type.</p>
<p>7. Functions which are used to initialize objects are called constructors. The calling sequence for a constructor is slightly different than for ordinary functions.</p>
<p>8. Named variables are defined with the var statement. When used inside of a function, var defines variables with function-scope. The vars are not accessible from outside of the function.</p>
<div><a href="http://www.addthis.com/bookmark.php" title="Bookmark using any bookmark manager!" target="_blank"><img src="http://s3.addthis.com/button1-bm.gif" width="125" height="16" border="0" /></a></div>
<p><a href="http://feeds.feedburner.com/~a/Ashchuan?a=rgzzyn"><img src="http://feeds.feedburner.com/~a/Ashchuan?i=rgzzyn" border="0"></img></a></p>
<p><img src="http://feeds.feedburner.com/~r/Ashchuan/~4/306661493" height="1">
<p><b>Source:</b> <a href="http://www.ashchuan.com/blog/2008/06/07/is-javascript-more-object-oriented-than-other-programming-languages/">Development</a></p>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2008/06/28/is-javascript-more-object-oriented-than-other-programming-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binding HTML Form Fields To Javascript Objects</title>
		<link>http://anaykamat.com/2008/05/22/binding-html-form-fields-to-javascript-objects/</link>
		<comments>http://anaykamat.com/2008/05/22/binding-html-form-fields-to-javascript-objects/#comments</comments>
		<pubDate>Thu, 22 May 2008 15:42:58 +0000</pubDate>
		<dc:creator>Anay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[data bindings]]></category>
		<category><![CDATA[databindings]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://anaykamat.com/?p=50</guid>
		<description><![CDATA[Consider that I have a object called &#8216;person&#8217; with a property called &#8216;Name&#8217; which returns me the name of a particular person. I want to assign this object property to a form element such that: The form element will display the value of object property (In our case, the value of person.Name) If I change [...]]]></description>
			<content:encoded><![CDATA[<p>Consider that I have a object called &#8216;person&#8217; with a property called &#8216;Name&#8217; which returns me the name of a particular person. I want to assign this object property to a form element such that:</p>
<ol>
<li>The form element will display the value of object property (In our case, the value of person.Name)</li>
<li>If I change the value in form, then it should automatically get assigned to the object property</li>
</ol>
<p>In C#, it could be done by using the following piece of code:</p>
<pre class="brush: csharp;">nameTextBox.DataBindings.Add(&quot;Text&quot;, person, &quot;Name&quot;);</pre>
<p>I really like the way DataBinding works and would really like have something like this when I&#8217;m working on web applications to bind a object property to input elements in HTML forms. So I decided to write a small javascript that would allow me to bind object properties to form elements. For example, I wanted to write something like this:</p>
<pre class="brush: xml;">&lt;input type=&quot;text&quot; object=&quot;person&quot; property=&quot;firstName&quot; /&gt;</pre>
<p>Thanks to the power of Javascript and prototype library, I was able to use data binding in html forms using code:</p>
<pre class="brush: jscript;">
function initializeFormBinding()
{
	var formElements = document.getElementsByTagName('input');
	$A(formElements).each(function(formElement)
				{
					Element.extend(formElement);
					initializeFormElement(formElement);
				});
}

function initializeFormElement(formElement)
{
	if (!(formElementHasObjectAttribute(formElement) &amp;amp;&amp;amp; formElementHasPropertyAttribute(formElement)))
		return;
	var objectName = getAttributeValue(formElement,'object');
	var propertyName = getAttributeValue(formElement,'property');
	window.eval('formElement.value = '+objectName+'.'+propertyName);
	window.eval('formElement.onchange=function(){ '+objectName+'.'+propertyName+' = formElement.value; }');
}

function formElementHasObjectAttribute(formElement)
{
	return getAttributeValue(formElement,'object')!=null;
}

function formElementHasPropertyAttribute(formElement)
{
	return getAttributeValue(formElement,'property')!=null;
}

function getAttributeValue(element, attributeName)
{
	return element.readAttribute(attributeName);
}
</pre>
<p>Lets see how to use this: First, create a javascript object. For example:</p>
<pre class="brush: jscript;">
var person = {};
person.firstName = '';
person.lastName = '';
person.age = '';
person.country = '';
</pre>
<p>After that call initializeFormBinding() function using onLoad attribute of body tag. For example:</p>
<pre class="brush: xml;">
&lt;body onLoad=&quot;javascript:initializeFormBinding();&quot;&gt;
</pre>
<p>Now, in each of your input elements, put the name of the object in &#8216;object&#8217; attribute and name of property in &#8216;property&#8217; attribute as follows:</p>
<pre class="brush: xml;">
&lt;form&gt;
First Name:
&lt;input type=&quot;text&quot; object=&quot;person&quot; property=&quot;firstName&quot; /&gt;&lt;br&gt;
Last Name:
&lt;input type=&quot;text&quot; object=&quot;person&quot; property=&quot;lastName&quot; /&gt;&lt;br&gt;
Age:
&lt;input type=&quot;text&quot; object=&quot;person&quot; property=&quot;age&quot; /&gt;&lt;br&gt;
Country:
&lt;input type=&quot;text&quot; object=&quot;person&quot; property=&quot;country&quot; /&gt;&lt;br&gt;
&lt;/form&gt;
</pre>
<p>Thats it&#8230;. If you initialize properties of person object, you would see those values in respective form elements. On the other hand, if you modify the value in a particular input element then it would get reflected in the corresponding object property. Anybody is free to use this code in their applications.</p>
<p><a title="Application example" href="http://www.anaykamat.com/fileuploads/JavascriptDataBinding.zip">Download a small example application.</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2008/05/22/binding-html-form-fields-to-javascript-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

