<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/1.5.1-alpha" -->
<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/"
>

<channel>
	<title>code::gallery</title>
	<link>http://codegallery.blogsome.com</link>
	<description>all about code</description>
	<pubDate>Tue, 25 Jul 2006 03:17:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=1.5.1-alpha</generator>
	<language>en</language>

		<item>
		<title>Merging With Main Blog</title>
		<link>http://codegallery.blogsome.com/2006/07/25/merging-with-main-blog/</link>
		<comments>http://codegallery.blogsome.com/2006/07/25/merging-with-main-blog/#comments</comments>
		<pubDate>Tue, 25 Jul 2006 03:15:34 +0000</pubDate>
		<dc:creator>Abhijit Nadgouda</dc:creator>
		
	<category>misc</category>
		<guid>http://codegallery.blogsome.com/2006/07/25/merging-with-main-blog/</guid>
		<description><![CDATA[	This blog has been merged with my main blog. There will be no more posts on this blog.
	Since there are not many posts on this blog, they will be reposted on the main blog acknowledging that they were already published there. Most of the posts here will be categorized under programming.

]]></description>
			<content:encoded><![CDATA[	<p>This blog has been <a title="Merging Blogs" href="http://codegallery.blogsome.com/go.php?http://iface.wordpress.com/2006/07/23/merging-blogs/">merged</a> with <a title="Abhijit Nadgouda @ iface" href="http://codegallery.blogsome.com/go.php?http://iface.wordpress.com/">my main blog</a>. There will be no more posts on this blog.</p>
	<p>Since there are not many posts on this blog, they will be reposted on the main blog acknowledging that they were already published there. Most of the posts here will be categorized under <a title="programming category" href="http://codegallery.blogsome.com/go.php?http://iface.wordpress.com/tag/programming/">programming</a>.
</p>
]]></content:encoded>
			<wfw:commentRss>http://codegallery.blogsome.com/2006/07/25/merging-with-main-blog/feed/</wfw:commentRss>
	</item>
		<item>
		<title>Single, Double And Multiple Dispatch</title>
		<link>http://codegallery.blogsome.com/2006/07/22/single-double-and-multiple-dispatch/</link>
		<comments>http://codegallery.blogsome.com/2006/07/22/single-double-and-multiple-dispatch/#comments</comments>
		<pubDate>Sat, 22 Jul 2006 16:07:32 +0000</pubDate>
		<dc:creator>Abhijit Nadgouda</dc:creator>
		
	<category>commons</category>
		<guid>http://codegallery.blogsome.com/2006/07/22/single-double-and-multiple-dispatch/</guid>
		<description><![CDATA[	These are mechanisms in object oriented programming languages to identify the funciton/method to be invoked. The dispatch in the nomenclature is about dispatching messages to objects, as it is said in Smalltalk. It is equivalent of saying invoking methods of an object.
	Single Dispatch
	Typically, multiple methods or functions are given the same name, because the represent [...]]]></description>
			<content:encoded><![CDATA[	<p>These are mechanisms in object oriented programming languages to identify the funciton/method to be invoked. The <em>dispatch</em> in the nomenclature is about dispatching messages to objects, as it is said in Smalltalk. It is equivalent of saying invoking methods of an object.</p>
	<h3>Single Dispatch</h3>
	<p>Typically, multiple methods or functions are given the same name, because the represent the same purpose. In the single dispatch mechanism, the method to be invoked in determined using the object, usually type of the object, on which it is invoked. It also includes the parameters, but the parameter types are identified at the compile time whereas dynamic binding or dynamic dispatch can be used for object on which method is invoked. This object is also syntatically highlighed, like</p>
	<pre>
obj.behave(the, arguments)
</pre>
	<p>Most of the conventional and popular languages, like C++, Java or Smallatalk inherently support single dispatch mechanism.</p>
	<h3>Double</h3>
	<p>Why is anything more than single dispatch is being considered? Because in the real world it is required. In the real world, the behavior between two objects is not dependent on both of them and not just one. Lets consider an example.</p>
	<p>Your behavior would change when you face other humans, the domestic cat or the tiger. This means that your actions are dependent not only on you but also on whom you face. This cannot be incorporated using the single dispatch mechanism.</p>
	<p>So we come up with double dispatch. It is in fact a simulation using the single dispatch mechanism, and hence is not completely extensible. Consider the following example code:</p>
	<pre>
class Human;
class Cat;
	
class Animal
{
    public:
        virtual void face (Animal&#038; animal);
        virtual void face (Human&#038; human);
        virtual void face (Cat&#038; cat);
}
	
class Human : public Animal
{
        virtual void face (Animal&#038; animal)
        {
            animal.face(*this);
        }
	
        virtual void face (Human&#038; human);
        {
            // shakehand
        }
	
        virtual void face (Cat&#038; cat);
        {
            cat.face(*this);
        }
}
	
class Cat : public Animal
{
        virtual void face (Animal&#038; animal)
        {
            animal.face(*this);
        }
	
        virtual void face (Human&#038; human);
        {
            human.face(*this);
        }
	
        virtual void face (Cat&#038; cat);
        {
            // run
        }
}
</pre>
	<p>This code works. What is done here is that two calls are used to identify both the types involved. Consider this code:</p>
	<pre>
        Animal&#038; acat = Cat();
        Animal&#038; ahuman = Human();
        ahuman.face(acat);
</pre>
	<p>Here, when <code>ahuman.face(acat)</code> is invoked, it in turn invokes <code>Cat::face(Human&#038;)</code> at which point both the types are determined. This is the double dispatch mechanism.</p>
	<p>However, as you can see, the biggest disadvantage is that the base class <code>Animal</code> has to know all the derived classes. Everytime a new animal is added, the interface of <code>Animal</code> has to change making it impractical, exactly what the <a title="Dependency Inversion Principle" href="http://codegallery.blogsome.com/go.php?http://iface.wordpress.com/2006/03/16/dependency-inversion-principle-and-interface/">Dependency Inverstion Principle</a> advises us to avoid.</p>
	<h3>Multiple Dispatch</h3>
	<p>So we need multi dispatch, also called multimethods. The multidispatch mechanism considers all parameters equally and hence can provide easier and more extensible implementations. Some of the languages that support multiple dispatch are Common Lisp, Dylan, Nice, Scheme and Slate.</p>
	<p>One of the common designs of multiple dispatch is to separate the methods from the class (which contains the structure). This allows for treating all the parameters equally.</p>
	<p>Some of the conventional languages also support multimethods through extensions - <a title="by Gnosis" href="http://codegallery.blogsome.com/go.php?http://gnosis.cx/download/gnosis/magic/multimethods.py">Multimethods for Python</a>, <a title="CPAN Multimethods" href="http://codegallery.blogsome.com/go.php?http://search.cpan.org/~dconway/Class-Multimethods/lib/Class/Multimethods.pod">Multimethods for Perl</a>, <a title="MultiJava" href="http://codegallery.blogsome.com/go.php?http://multijava.sourceforge.net/">MultiJava</a>, <a title="Multimethods" href="http://codegallery.blogsome.com/go.php?http://rubyforge.org/projects/multi/">Ruby</a>, <a title="Cmm" href="http://codegallery.blogsome.com/go.php?http://www.op59.net/cmm/readme.html">C++ with Multimethods</a>.</p>
	<p>More Reading:</p>
	<ul>
	<li><a title="Double dispatch" href="http://codegallery.blogsome.com/go.php?http://en.wikipedia.org/wiki/Double_dispatch">Double dispatch @ Wikipedia</a></li>
	<li><a title="Multiple dispatch" href="http://codegallery.blogsome.com/go.php?http://en.wikipedia.org/wiki/Multimethods">Multiple dispatch @ Wikipedia</a></li>
	<li><a title="Multiple Dispatch for C++" href="http://codegallery.blogsome.com/go.php?http://www.eptacom.net/pubblicazioni/pub_eng/mdisp.html">Multiple Dispatch - A new approach using templates and <abbr title="RunTime Type Identification">RTTI</a></a></li>
	<li><a title="Beyond mainstream object oriented programming" href="http://codegallery.blogsome.com/go.php?http://jaortega.wordpress.com/2006/02/05/beyond-mainstream-object-oriented-programming/">Beyond mainstream object oriented programming</a></li>
	</ul>
	<p>Tags: <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/single+dispatch">single dispatch</a>, <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/double+dispatch">double dispatch</a>, <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/multiple+dispatch">multiple dispatch</a>, <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/multimethods">multimethods</a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://codegallery.blogsome.com/2006/07/22/single-double-and-multiple-dispatch/feed/</wfw:commentRss>
	</item>
		<item>
		<title>Overcautious Coding</title>
		<link>http://codegallery.blogsome.com/2006/07/15/overcautions-coding/</link>
		<comments>http://codegallery.blogsome.com/2006/07/15/overcautions-coding/#comments</comments>
		<pubDate>Sat, 15 Jul 2006 03:25:20 +0000</pubDate>
		<dc:creator>Abhijit Nadgouda</dc:creator>
		
	<category>commons</category>
		<guid>http://codegallery.blogsome.com/2006/07/15/overcautions-coding/</guid>
		<description><![CDATA[	Michael Feathers illustrates nicely the problem of overcautious coding. The following should probably be coding principles:
	
Spurious null checks are a symptom of bad code.

	The reactive thing whenever there is a core dump or crash because of nulls or empty pointers is to add a check of null and wash your hands off it. The right [...]]]></description>
			<content:encoded><![CDATA[	<p>Michael Feathers illustrates nicely the problem of <a title="Offensive Coding" href="http://codegallery.blogsome.com/go.php?http://www.artima.com/weblogs/viewpost.jsp?thread=168511">overcautious coding</a>. The following should probably be coding principles:</p>
	<blockquote><p>
Spurious null checks are a symptom of bad code.
</p></blockquote>
	<p>The reactive thing whenever there is a core dump or crash because of <code>null</code>s or empty pointers is to add a check of null and wash your hands off it. The right thing would be to find out origin of the <code>null</code> and try to avoid it as much as possible. It is not only that the <code>if</code> can cause performance loss, it can inadvertently cover up the malicious code that generates the <code>null</code>.</p>
	<p>It is also easier to program to an interface where the callee does not throw <code>null</code>s so that the multiple callers don&#8217;t have to check for them.</p>
	<p>Tags: <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/null">null</a>, <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/conditional">conditional</a>, <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/defensive+coding">coding</a>.
</p>
]]></content:encoded>
			<wfw:commentRss>http://codegallery.blogsome.com/2006/07/15/overcautions-coding/feed/</wfw:commentRss>
	</item>
		<item>
		<title>Generate Regular Expressions</title>
		<link>http://codegallery.blogsome.com/2006/07/11/generate-regular-expressions/</link>
		<comments>http://codegallery.blogsome.com/2006/07/11/generate-regular-expressions/#comments</comments>
		<pubDate>Tue, 11 Jul 2006 04:48:39 +0000</pubDate>
		<dc:creator>Abhijit Nadgouda</dc:creator>
		
	<category>commons</category>
		<guid>http://codegallery.blogsome.com/2006/07/11/generate-regular-expressions/</guid>
		<description><![CDATA[	Roy Osherov has created Regulator - a regular expression generator. And it has a nice visual interface to specify the data and the parsing rules that creates the regular expression. If you want to know more about regular expressions head over here. Developers can use this to be more productive in creating regular expressions and [...]]]></description>
			<content:encoded><![CDATA[	<p><a title="Roy Osherov" href="http://codegallery.blogsome.com/go.php?http://weblogs.asp.net/rosherove/">Roy Osherov</a> has created <a title="Regulator" href="http://codegallery.blogsome.com/go.php?http://regex.osherove.com/">Regulator - a regular expression generator</a>. And it has a nice visual interface to specify the data and the parsing rules that creates the <a title="Regular Expressions @ Wikipedia" href="http://codegallery.blogsome.com/go.php?http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>. If you want to know more about regular expressions <a title="Regular-Expressions" href="http://codegallery.blogsome.com/go.php?http://www.regular-expressions.info/">head over here</a>. Developers can use this to be more productive in creating regular expressions and use them in their own programming environment.</p>
	<blockquote><p>
The Regulator is an advanced, free regular expressions testing and learning tool written by Roy Osherove.<br />
It allows you to build and verify a regular expression against any text input, file or web, and displays matching, splitting or replacement results within an easy to understand, hierarchical tree.
</p></blockquote>
	<p>However in such applications the real challenge is to create a rich <abbr title="User Interface">UI</abbr> that will enable expressing all the possible formats of data and all the possible ways of specifying the parsing rules. More fiddling with it will tell us whether it is really upto the challenge, but a brief introduction has resulted in a pleasing experience.</p>
	<p>You will also find a link to a more ambitious project - <a title="Point and Click Regular Expressions" href="http://codegallery.blogsome.com/go.php?http://tools.osherove.com/Regulazy/tabid/182/Default.aspx">Regulazy</a>.</p>
	<blockquote><p>
Regulazy is an attempt to build a small &#8220;Expert System&#8221; for creating .NET Regular Expressions.<br />
It lets the user create an expression based on a real life example of text they would like to parse.<br />
As the user interacts with Regulazy using the mouse, Regulazy offers the user possible expressions that would fit the currently selected text. As the user selects &#8220;rules&#8221; to apply on various parts of the text,<br />
a regular expression is built automatically in the lower application pane.
</p></blockquote>
	<p>Regulazy goes a step further from Regulator to suggest the best matches for a real life data. Users can use sample text to specify the kind of data and see real time preview of the results. It is still in alpha stage.</p>
	<p>Regular Expressions themselves are technology agnostic, I really wish that both these tools are not OS or platform specific. I will try and see if they work on other OSs by using <a title="Mono" href="http://codegallery.blogsome.com/go.php?http://www.mono-project.com/">Mono</a>.</p>
	<p>Tags: <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/regular+expressions">regular expressions</a>, <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/regulator">regulator</a>, <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/regulazy">regulazy</a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://codegallery.blogsome.com/2006/07/11/generate-regular-expressions/feed/</wfw:commentRss>
	</item>
		<item>
		<title>Javaref</title>
		<link>http://codegallery.blogsome.com/2006/06/29/javaref/</link>
		<comments>http://codegallery.blogsome.com/2006/06/29/javaref/#comments</comments>
		<pubDate>Thu, 29 Jun 2006 14:10:09 +0000</pubDate>
		<dc:creator>Abhijit Nadgouda</dc:creator>
		
	<category>Java</category>
		<guid>http://codegallery.blogsome.com/2006/06/29/javaref/</guid>
		<description><![CDATA[	I think Javaref (via Ajaxian) displays one of the best uses of AJAX. It has injected usability and ease in refering to the Java documentation.
	So welcome to the Web 2.0 JavaDoc. The default way of looking up is searching. This is made easier with features like autocomplete.
	
Java API documentation are displayed in a style that [...]]]></description>
			<content:encoded><![CDATA[	<p>I think <a title="Javaref" href="http://codegallery.blogsome.com/go.php?http://www.javaref.com/">Javaref</a> (via <a title="Javaref: Ajaxified JavaDoc" href="http://codegallery.blogsome.com/go.php?http://ajaxian.com/archives/javaref-ajaxified-javadoc">Ajaxian</a>) displays one of the best uses of <abbr title="Asynchronous JavaScript and XML">AJAX</abbr>. It has injected usability and ease in refering to the Java documentation.</p>
	<p>So welcome to the Web 2.0 JavaDoc. The default way of looking up is searching. This is made easier with features like autocomplete.</p>
	<blockquote><p>
Java API documentation are displayed in a style that is radically different from the classic javadoc style that ships with the JDK. The documentation includes class source code (where available), ability to leave user notes and ability to transparently navigate between APIs by following code references.
</p></blockquote>
	<p>However, the drawback is that it does not have Sun&#8217;s JDK documentation, as mentioned in the <a title="FAQ" href="http://codegallery.blogsome.com/go.php?http://www.javaref.com/app?service=page/FAQ">FAQ</a>.</p>
	<p>I hope even <a title="API Reference Heaven" href="http://codegallery.blogsome.com/go.php?http://codegallery.blogsome.com/2006/05/26/api-reference-heaven/">gotAPI</a> follows this.</p>
	<p>Tags: <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/javadoc">javadoc</a>, <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/javaref">javaref</a>, <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/api">api</a>, <a rel="tag" href="http://codegallery.blogsome.com/go.php?http://technorati.com/tag/documentation">documentation</a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://codegallery.blogsome.com/2006/06/29/javaref/feed/</wfw:commentRss>
	</item>
	</channel>
</rss>
