<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>The Shyam!</title>
	
	<link>http://theshyam.com</link>
	<description>Thoughts and factoids from the Real Shyam. You know, unlike those fake ones!!</description>
	<lastBuildDate>Thu, 04 Mar 2010 20:01:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/theshyam" /><feedburner:info uri="theshyam" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Ftheshyam" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Ftheshyam" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/theshyam" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Ftheshyam" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2Ftheshyam" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2Ftheshyam" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><item>
		<title>Is Strong Typing really needed?</title>
		<link>http://feedproxy.google.com/~r/theshyam/~3/nN6xGrnbVP4/</link>
		<comments>http://theshyam.com/2010/03/is-strong-typing-really-needed/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 19:36:40 +0000</pubDate>
		<dc:creator>Shyam</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[dynamic languages]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://theshyam.com/?p=282</guid>
		<description><![CDATA[This is something I have been struggling with for the last few months. I have had people argue ardently that all Strong typing is good for is false comfort and lots of unneeded typing. But I was strong. I was undeterred. I dismissed this as the crazy rants of those JS developers, those dynamic language [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">This is something I have been struggling with for the last few months. I have had people argue ardently that all Strong typing is good for is false comfort and lots of unneeded typing. But I was strong. I was undeterred. I dismissed this as the crazy rants of those JS developers, those dynamic language people who believe that obfuscation and compactness is everything, even at the cost of maintainability. I mean, how could a language where you didn&#8217;t even know what was getting passed in in any ways better than something where the APIs are explicit and stop you from making mistakes. A dynamic language could work for a single developer, but definitely not for a team. That was my whole hearted conclusion.</div>
<div id="_mcePaste">Now, I&#8217;m not so sure anymore. Its been 3 weeks since our team made the whole hearted switch. Has it been roses and sunshine? No. But it hasn&#8217;t been as bad as I expected it to be. And there are a few reasons for that. But before that, I&#8217;ll lay down the pros and cons the way I see them from my (assuredly very limited) experience :</div>
<p></p>
<div id="_mcePaste"><strong>Benefits of Strong Typing :</strong></div>
<div>
<ol>
<li><strong>Errors / Warnings in your editor</strong><br />
Simply put, this might just be the single most greatest benefit of strong typing, and the single reason why most java developers (a lot rightly so) will never even consider leaving the safety of strong typing. While compilation support doesn&#8217;t necessarily go hand in hand with strong typing, most people tend to associate Java with it, so lets run with that. Simply put, with Strong typing, your editor can (and should, I mean, if you are not going to get immd. feedback, what&#8217;s the point?) give you immediate feedback when you messed something up. Whether this be using the wrong variable name or trying to call a method that either does not exist or with the wrong parameters. Or if you are trying to use the wrong type of object.</p>
<p>To a Java developer, an IDE like Eclipse or IntelliJ is godsend, as it tells you what is wrong in your world and lets you jump to them, gives you suggestions and autofixes and generally makes your life as painless as it can. And it is brilliant, I can tell you that.</p>
<p>In Javascript (or any other dynamic language), everything is fine and dandy for the first 100 lines. After that, it becomes scarily unmanageable. The only way around this that I have found so far is to be super paranoid and write tests for every single line of code. If you can&#8217;t do that, stay far far away.</li>
<li><strong>Generics (but this is also a negative, in my opinion, which I&#8217;ll get to below)</strong><br />
The idea behind generics is that gives developers some assurances about the types in a collection (or whatever it is you are genericizing). That way, all operations are type safe, without having to convert to and from different types. And you are assured that you will not be surprised suddenly by a different type of object popping up when you least expect it. But there are a lot of issues with them that I&#8217;ll cover in the second section.</li>
<li><strong>Ability to follow a chain and figure out what type of object is required at each step</strong><br />
Now this is something I definitely miss in languages like Javascript and Python. The fact that I can trace (in my IDE, note that part) what the type of each variable / method call in an expression chain is simply amazing, especially when you are working with a new codebase. You never have to wonder what the parameter types of the method you are calling are. You don&#8217;t have to wonder what methods are available or visible. You just know this information (Again, assuming you are using an IDE. If not, god help you)</li>
<li><strong>Refactoring</strong>
<p>The biggest advantage of Strong typing though, in my opinion, is the ability to create IDEs which make refactoring a breeze. Renaming a method / variable? Trivial. Moving or extracting a method? Simple key combination. Stuff which can be extremely tedious and mind numbing are accomplished in a matter of minutes. (Want to know more about these shortcuts? Check out Eclipse shortcuts). This is simply not possible with languages like Python and Javascript.</li>
</ol>
</div>
<div id="_mcePaste"><strong>Disadvantages of Strong typing :</strong></div>
<div>
<ol>
<li><strong>More concise and precise, less typing</strong><br />
Dynamic languages do tend to be more dense, and it is much easier to accomplish in 10 lines what can easily take 50-100 in a language like Java, which is especially verbose. Consider trying to pass in a chunk of code to be executed at the end of a function in both Java and javascript (this is pretty common in web apps and task runners)<br />
<em>Java :</em></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">interface</span> Function <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; T execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// Optional parameters is not easy here :(</span><br />
<span style="color: #009900;">&#125;</span><br />
taskRunner.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>taskArgument, <span style="color: #000000; font-weight: bold;">new</span> Function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;Success&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><em>Javascript</em>:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">taskRunner.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span>params<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>response<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Success&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</li>
<li><strong>No badly implemented generics</strong><br />
This is mostly Java&#8217;s fault of getting generics pretty badly wrong. The idea behind generics is sound, its the implementation that is horribly broken. Here are a few things which are wrong with it :<br />
<em>Type erasure</em> : This basically involves the fact that at runtime, there is no way to differentiate between say, a List&lt;String&gt; and a List&lt;Integer&gt; If you never work with reflection or Guice, then this might not be a problem. But it also is a pain with deeply nested generics and wildcards. I have seen compiling code which blows up at runtime because it cannot differentiate between a Provider&lt;? extends Repository&gt; and Provider&lt;? extends Resource&gt; and neither Resource nor Repository have anything in common. Crazy&#8230;.</p>
<p><em>Verbosity</em> : Map&lt;String, List&lt;String&gt;&gt; myMap = new HashMap&lt;String, List&lt;String&gt;&gt;();. Enuff said.</p>
<p><em>Guice &amp; Reflection </em>: Generics and java.lang.reflect just don&#8217;t mix. They just don&#8217;t. Type erasure blows away all type information, so you are bound to be using stuff like new Entity&lt;?&gt; which totally defeats the purpose. And don&#8217;t get me started on Guice. In guice, normal bindings (non generic classes) look as follows :</p>
<p><em>bind(MyInterface.class).toInstance(instance);</em></p>
<p>With Generics involved, they now look as follows :</p>
<p><em>bind(new TypeLiteral&lt;MyInterface&lt;String&gt;&gt;(){}).toInstance(instance);</em></p>
<p>What the heck just happened there???</li>
<li><strong>Closures / Functions :</strong><br />
Closures are a form of anonymous inner functions which can have an environment of their own, including variables bound to the scope of the function. The inner function has access to the local variables of the outer scope and can change state. But what it does allow is creating functions, as callbacks or for performing some quick little task in a repeated fashion, easily and quickly and pretty darn cheaply.Java has had a few proposals to add it (http://javac.info/) but it has not passed the review committee yet. And probably won&#8217;t for the next few years. So till then, in Java, you are stuck creating interfaces, creating an implementation of it at runtime, passing in variables you need access to in the constructor or through some other mechanism, and generally be in a lot of pain. Thanks, but no thanks.</li>
</ol>
</div>
<!-- Adsense Immediately! V1.0 -->
<!-- Post[count: 2] -->
<div class="adsense adsense-leadout" style="text-align:center;margin: 12px;"><script type="text/javascript"><!--
google_ad_client = "pub-7044872323760461";
/* Homepage */
google_ad_slot = "8323895038";
google_ad_width = 600;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p><a href="http://feedads.g.doubleclick.net/~a/Uz22YkzPn1n_FaB2ENWK5nBLC3s/0/da"><img src="http://feedads.g.doubleclick.net/~a/Uz22YkzPn1n_FaB2ENWK5nBLC3s/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Uz22YkzPn1n_FaB2ENWK5nBLC3s/1/da"><img src="http://feedads.g.doubleclick.net/~a/Uz22YkzPn1n_FaB2ENWK5nBLC3s/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/theshyam?a=nN6xGrnbVP4:8r0CyxLZhGg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=nN6xGrnbVP4:8r0CyxLZhGg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/theshyam?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=nN6xGrnbVP4:8r0CyxLZhGg:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/theshyam/~4/nN6xGrnbVP4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://theshyam.com/2010/03/is-strong-typing-really-needed/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://theshyam.com/2010/03/is-strong-typing-really-needed/</feedburner:origLink></item>
		<item>
		<title>What I miss in Java</title>
		<link>http://feedproxy.google.com/~r/theshyam/~3/BqvOWl-PTh8/</link>
		<comments>http://theshyam.com/2009/11/what-i-miss-in-java/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 17:39:02 +0000</pubDate>
		<dc:creator>Shyam</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[type]]></category>
		<category><![CDATA[wordy]]></category>

		<guid isPermaLink="false">http://theshyam.com/?p=252</guid>
		<description><![CDATA[So I finally got some time to sit down and write, after being knee deep in work the past month or two. And without a doubt, I wanted to write about what has been heckling and annoying me over the past month. I am an ardent defender of Java as a good language, especially defending [...]]]></description>
			<content:encoded><![CDATA[<p>So I finally got some time to sit down and write, after being knee deep in work the past month or two. And without a doubt, I wanted to write about what has been heckling and annoying me over the past month. I am an ardent defender of Java as a good language, especially defending it from Misko day in and day out, but even I will agree that it does suck at times. So today, Java, the gloves are off. I love you, but this is the way things are.</p>
<p>To give some context, I have been working on <a href="http://code.google.com/webtoolkit/" target="_blank">GWT</a> a lot recently, and have done some crazy things with GWT generators (which I might cover in a few posts later). I love GWT, but for all of GWT&#8217;s aims to allow developing modern web apps without losing any of Java&#8217;s tooling support, there are a lot of things which are made easier in javascript. Lets take a look at them one by one, shall we?</p>
<h3>Closures (Abiity to pass around methods)</h3>
<p>So this was the straw that broke the camel&#8217;s back. I had this use case today where I wanted to set some fields through setters on a POJO. Simple enough right? Well, NO, because someone used defensive programming (Don&#8217;t get me started about precondition checks, thats for another post) and so it through a null pointer exception. Ok, since I can&#8217;t change the POJO (since it is in someone else&#8217;s code base), I needed to check for nulls on my side and not call the setter if the value was null. Simple enough, I do a check and call the method conditionally. Except when you have a few 10 odd properties, thats a lot of conditionally crappy code.</p>
<p>Ok, so my other option is write a function which checks that, right? Except in java, you can&#8217;t pass around functions or closures. Ideally, I want to have a closure which takes a value and a function, and let the closure handle the null check and conditional calling. Something like :</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">callConditionally<span style="color: #009900;">&#40;</span>myPojo.<span style="color: #006633;">setValue</span>, actualValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Except you can&#8217;t. Not in java. I mean, I could create an interface to wrap it, but that just adds more boilerplate than necessary. I ended up creating a method which uses reflection to find the method by name and calls it, but my point is that it shouldn&#8217;t be necessary. What should be two or three lines of code ended up being a 20 line monstrosity. And yes, before some smart aleck replies that if I wanted closures, I should go to javascript, I will point out that there have multiple proposals to include closures in Java, and Scala, which compiles into java, supports closures as well.</p>
<p>There are multiple JSR&#8217;s and open source libraries which try to implement this for Java, and one of these days, I&#8217;m gonna give it a try. But for those interested, check out <a href="http://javac.info" target="_blank">http://javac.info/</a> and <a href="http://code.google.com/p/lambdaj/" target="_blank">http://code.google.com/p/lambdaj/</a>. Both of them look promising.</p>
<h3>Type inference and General Wordiness</h3>
<p>They say a picture is worth a thousand words. Well, with java, and especially with generics, it seems that even a simple declaration is atleast a thousand words. For example :</p>
<pre>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Map<span style="color: #339933;">&lt;</span>String, List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;&gt;</span> myMap <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</pre>
<p>The above line could be so much shorter and sweeter as :</p>
<pre>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Map<span style="color: #339933;">&lt;</span>String, List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;&gt;</span> myMap <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ahashmap+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">HashMap</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</pre>
<p>There are very few cases when I would want a map of something else when I just declared it of a particular types. Other examples like reading a file, working with regexes abound, all of which require much more syntax than other languages. And I definitely do miss being able to say</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myValue<span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>instead of</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myValue <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>Sigh&#8230; And don&#8217;t even get me started with reflection. Reflection in Java is extremely powerful, but man is it wordy. Not only can you not recurse over the properties of an object directly (like say, in javascript), you also have to worry about exceptions (which I&#8217;ll get to in the next section)</p>
<h3>Checked exceptions</h3>
<p>That brings me to my last and biggest complaint. Checked exceptions in Java. They are just plain evil. I know people swear by them, and some of their arguments even make sense. Sometimes. But the fact remains that they make me write more boilerplate, more code that I don&#8217;t even care about than anything else in Java. The idea behind checked exceptions is sound. Its a great way to declare what the caller of a method needs to worry about. But the thing is, I should have an option other than rethrowing or logging it.</p>
<p>I did a very unscientific data gathering experiment of just looking at code randomly in different code bases (<a href="http://www.google.com/codesearch" target="_blank">Codesearch</a> was especially useful for this). And the majority of catch blocks I found either</p>
<ul>
<li>Logged it using logger or System.err</li>
<li>Rethrew it as a wrapped exception</li>
</ul>
<p>Me personally, I have changed Eclipse to generate all catch clauses for me by wrapping and rethrowing it as a RuntimeException so I don&#8217;t have to worry about adding a throws to my method declaration, when it is a non recoverable exception for the most part.</p>
<p>Furthermore, sometimes Checked exceptions can even lead to clauses which will never ever be executed. Point in case :</p>
<pre>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; java.<span style="color: #006633;">net</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aurlencoder+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">URLEncoder</span></a>.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span>myString, <span style="color: #0000ff;">&quot;UTF8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aunsupportedencodingexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">UnsupportedEncodingException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #666666; font-style: italic;">// Can never be thrown, but I am forced to catch it.</span><br />
&nbsp;<span style="color: #666666; font-style: italic;">// Because its a checked exception!!!</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</pre>
<p>There are many more cases like this, but I think this is enough of a rant for now.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/yDrxnGF0YwB4hTEDAe-0QKnYqvI/0/da"><img src="http://feedads.g.doubleclick.net/~a/yDrxnGF0YwB4hTEDAe-0QKnYqvI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/yDrxnGF0YwB4hTEDAe-0QKnYqvI/1/da"><img src="http://feedads.g.doubleclick.net/~a/yDrxnGF0YwB4hTEDAe-0QKnYqvI/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/theshyam?a=BqvOWl-PTh8:gAr03wC-NkA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=BqvOWl-PTh8:gAr03wC-NkA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/theshyam?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=BqvOWl-PTh8:gAr03wC-NkA:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/theshyam/~4/BqvOWl-PTh8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://theshyam.com/2009/11/what-i-miss-in-java/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://theshyam.com/2009/11/what-i-miss-in-java/</feedburner:origLink></item>
		<item>
		<title>How to build a Deeplinking capable Flex / GWT App</title>
		<link>http://feedproxy.google.com/~r/theshyam/~3/sJvo4fNsZJ0/</link>
		<comments>http://theshyam.com/2009/10/how-to-build-a-deeplinking-capable-flex-gwt-app/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 21:19:57 +0000</pubDate>
		<dc:creator>Shyam</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[deeplinking]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://theshyam.com/?p=242</guid>
		<description><![CDATA[I have been working extensively with GWT recently, and worked on a flash based webpage before that. And we tried many different approaches before finally settling down on a particular approach that works across all frameworks which are GWT / Flash-like. What do I mean by GWT / Flash-like? Well, these are frameworks which rely [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working extensively with GWT recently, and worked on a flash based webpage before that. And we tried many different approaches before finally settling down on a particular approach that works across all frameworks which are GWT / Flash-like. What do I mean by GWT / Flash-like? Well, these are frameworks which rely on on one page serving the entire content. The state of the page changes, but the web browser does not navigate between pages unlike a traditional website.</p>
<p>And both of these frameworks do not make it easy to provide deeplinking. Oh sure, its easy to add the functionality to hit the Back button in your browser and navigate in both GWT and Flex, its not as trivial to implement a way to provide a URL and browse immediately to the corresponding page without a lot of effort on the part of the developer. And this is where the following structure makes life a little bit easier.</p>
<p>The central concept in either of these is something called a <strong>Workspace</strong>. The workspace in this architecture represents the <strong>truth of the UI</strong>. Whatever the workspace contains is displayed in the UI. It is the backing model of the View. Now, for a mail app, it might represent the current view, like Inbox or Sent mail, and maybe the mails contained in it. And any other information needed to build and display the View. The workspace is also responsible for two more things, firing an event to all the Views saying that it has been updated, and another to a controller to tell it to go fetch data from the backend server.</p>
<p>Now the <strong>Views</strong> themselves are stateless to an extent, other than holding a reference to the Workspace. These would be the Panel classes in GWT. Their only responsibility is in channelling information to and from the workspace. They also listen to events on the Workspace. So whenever a Workspace_Changed event fires, the views go and grab relevant data from the workspace and render it.</p>
<p>The workspace also fires an event whenever a View tells it it needs more information. In that case, the controller goes and fetches the data, stuffs it in the workspace, and the workspace then fires an event to tell the Views that they should now update themselves. So basically, there are two events propagating through the system :</p>
<ul>
<li><strong>UPDATE_VIEWS</strong> : The workspace controller fires these when it has stuffed the information from the server into the workspace. The views listen on this event and update themselves accordingly</li>
<li><strong>UPDATE_WORKSPACE</strong> : The views fire these when it wants more data loaded from the server. The Workspace controller listens on this, and based on the state of the workspace, fetches relevant information. The catch is that it should always be possible to compute what data is needed based on the workspace. When the controller finishes, it fires the <strong>UPDATE_VIEWS</strong> event.</li>
</ul>
<p>Ok, so what does this give us with regards to Deeplinking? Well now, your URL / Token parser should be able to parse the URL or tokens (it is trivial to add a HistoryChangeListener in both GWT and Flex). And based on the parsed tokens, it should just update the workspace with the relevant fields. And go off and fire a UPDATE_WORKSPACE call. This will trigger a server call, get the relevant information, fire an UPDATE_VIEWS event, which tells the Views to go update themselves based on the state of the workspace. Voila, you have a working Deeplinking implementation.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/EdMprCdVubrefT-YZI7VKVWg0-o/0/da"><img src="http://feedads.g.doubleclick.net/~a/EdMprCdVubrefT-YZI7VKVWg0-o/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/EdMprCdVubrefT-YZI7VKVWg0-o/1/da"><img src="http://feedads.g.doubleclick.net/~a/EdMprCdVubrefT-YZI7VKVWg0-o/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/theshyam?a=sJvo4fNsZJ0:f_fLPqlroF0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=sJvo4fNsZJ0:f_fLPqlroF0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/theshyam?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=sJvo4fNsZJ0:f_fLPqlroF0:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/theshyam/~4/sJvo4fNsZJ0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://theshyam.com/2009/10/how-to-build-a-deeplinking-capable-flex-gwt-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://theshyam.com/2009/10/how-to-build-a-deeplinking-capable-flex-gwt-app/</feedburner:origLink></item>
		<item>
		<title>Using Polymorphism instead of Conditionals</title>
		<link>http://feedproxy.google.com/~r/theshyam/~3/1w9_zyInOwA/</link>
		<comments>http://theshyam.com/2009/09/using-polymorphism-instead-of-conditionals/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 16:49:38 +0000</pubDate>
		<dc:creator>Shyam</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[conditionals]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[polymorphism]]></category>

		<guid isPermaLink="false">http://theshyam.com/?p=223</guid>
		<description><![CDATA[Interviewing nowadays with tech companies has become run of the mill. You have phone screens, then you are brought on for on site interviews. And in each one of these, you are asked one mind-bending, off-ball algorithm question after another. I personally have been on both sides of the interview table, having asked and been [...]]]></description>
			<content:encoded><![CDATA[<p>Interviewing nowadays with tech companies has become run of the mill. You have phone screens, then you are brought on for on site interviews. And in each one of these, you are asked one mind-bending, off-ball algorithm question after another. I personally have been on both sides of the interview table, having asked and been asked my fair share of these. And after a while, I started questioning whether these questions provided any insight into how interviewees think other than their knowledge of algorithms.</p>
<p>It was then that I decided I wanted to try and find out if the candidates really understood polymorphism and other concepts, rather than their knowledge of algorithms, since every other interviewer would be covering that. And that was when I stumbled upon this gem of a question, which also underlies a fundamental concept of object oriented programming.</p>
<p>The question is simple. <strong>&#8220;Given a mathematical expression, like 2 + 3 * 5, which can be represented as a binary tree, how would you design the classes and code the methods so that I can call <em>evaluate() </em>and <em>toString()</em> on any node of the tree and get the correct value.&#8221;</strong>. Of course, I would clarify that populating the tree was out of the scope of the problem, so they had a filled in tree to work with. It also gives me a chance to figure out how the candidate thinks, whether he asks whether filling in the tree is his problem or whether he just assumes stuff. You could preface this question with another about Tree&#8217;s and traversal to check the candidate&#8217;s knowledge and whether this one would be a waste of time or not.</p>
<p>Now, one of three things can happen at this point. One, the candidate has no clue about trees and traversals, in which case there is no point proceeding down this line. Second, which seems to happen more often than not, is the candidate gives a class and method like the following :</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> Node <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">char</span> operator<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> lhsValue, rhsValue<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Node left, right<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> leftVal <span style="color: #339933;">=</span> left <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lhsValue <span style="color: #339933;">:</span> left.<span style="color: #006633;">evaluate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> rightVal <span style="color: #339933;">=</span> right <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rhsValue <span style="color: #339933;">:</span> right.<span style="color: #006633;">evaluate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>operator <span style="color: #339933;">==</span> <span style="color: #0000ff;">'+'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> leftVal <span style="color: #339933;">+</span> rightVal<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>operator <span style="color: #339933;">==</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// So on and so forth.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Same for toString()</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Whenever I see code like the example above, it just screams that whoever is writing it has no clue about how to work with Polymorphism. While I agree that some conditionals are needed, like checks for boundary conditions, but when you keep working with similar variables, but apply different operations to them based on condition, that is the perfect place for polymorphism and reducing the code complexity.</p>
<p>In the above case, the biggest problem is that all the code and logic is enclosed in a single method. So when a candidate presents me with this solution, the first thing I ask is what happens when we need to add another operation, like division or something. When the prompt answer is that we add an if condition, that is when I prompt and ask if there is not a cleaner solution, which would keep code separate. Finally, often, you depend on third party libraries for functionality. Well, in those cases, you won&#8217;t be able to edit the original source code, leaving you cursing the developer who wrote it for not allowing an extensible design.</p>
<p>The <strong>ideal answer</strong> would, for this question, be that <strong>Node is an interface</strong> with evaluate() and toString(). Then, we have <strong>different implementations of Node</strong>, like a <strong>ValueNode</strong>, an <strong>AdditionOperationNode</strong>, and so on and so forth. The implementations would look as follows :</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">interface</span> Node <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">int</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ValueNode<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">implements</span> Node <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> value<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> value<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> value <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AdditionOperationNode<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">implements</span> Node <span style="color: #009900;">&#123;</span><br />
&nbsp; Node left, right<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> left.<span style="color: #006633;">evaluate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> right.<span style="color: #006633;">evaluate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> left.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; + &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> right.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>You could go one step further and have an abstract base class for all operations with a Node left and right, but I would be well satisfied with just the above solution. Now, adding another operation is as simple as just adding another class with the particular implementation. Testing-wise, each class can be tested separately and independently, and each class has one and only one responsibility.</p>
<p>Now there are usually two types of conditionals you can&#8217;t replace with Polymorphism. Those are comparatives (&gt;, &lt;) (or working with primitives, usually), and boundary cases, sometimes. And those two are language specific as well, as in Java only. Some other languages allow you to pass closures around, which obfuscate the need for conditionals.</p>
<p>Of course, one might say that this is overkill. The if conditions don&#8217;t really make it hard to read. Sure, with the example above, maybe. But when was the last time you had just one level of nesting? Most times, these conditionals are within conditionals which are within loops. And then, every bit of readability helps. Not to mention there is a combinatorial explosion of the amount of code paths through a method. In that case, wouldn&#8217;t it be easier to test that the correct method is called on a class, and just test those individually to do the right thing?</p>
<p>So next time you are adding a conditional to your code, stop and think about it for a second, before you go ahead and add it in.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/ggrSFGtE74qVVeEd8ilfPfkKkyE/0/da"><img src="http://feedads.g.doubleclick.net/~a/ggrSFGtE74qVVeEd8ilfPfkKkyE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ggrSFGtE74qVVeEd8ilfPfkKkyE/1/da"><img src="http://feedads.g.doubleclick.net/~a/ggrSFGtE74qVVeEd8ilfPfkKkyE/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/theshyam?a=1w9_zyInOwA:lKL4YgyARu0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=1w9_zyInOwA:lKL4YgyARu0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/theshyam?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=1w9_zyInOwA:lKL4YgyARu0:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/theshyam/~4/1w9_zyInOwA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://theshyam.com/2009/09/using-polymorphism-instead-of-conditionals/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://theshyam.com/2009/09/using-polymorphism-instead-of-conditionals/</feedburner:origLink></item>
		<item>
		<title>Testing function vs testing implementation</title>
		<link>http://feedproxy.google.com/~r/theshyam/~3/3c_lYQA8Nfw/</link>
		<comments>http://theshyam.com/2009/09/testing-function-vs-testing-implementation/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 17:18:19 +0000</pubDate>
		<dc:creator>Shyam</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://theshyam.com/?p=215</guid>
		<description><![CDATA[Often I have got complaints from developers that I work with that their unit tests are prone to breakages, or they don&#8217;t like writing unit tests because their code changes frequently, which causes them to change their tests as well. Its just extra overhead at that point, and starts being a chore. Atleast thats what [...]]]></description>
			<content:encoded><![CDATA[<p>Often I have got complaints from developers that I work with that their unit tests are prone to breakages, or they don&#8217;t like writing unit tests because their code changes frequently, which causes them to change their tests as well. Its just extra overhead at that point, and starts being a chore. Atleast thats what their claim is. Now of course, I don&#8217;t agree with this at all. Not. One. Bit.</p>
<p>You see, when I hear this, its always tells me that there is something wrong with the way tests are written. A unit test that requires changes every time someone changes the code implies that there is a extremely strong coupling between how the code is written to how its tested. Some useful indicators of such a thing could be having a getter methods or properties which are visible only for tests, but not to external code. Or Tests which check if a loop happened 6 times or a mock was called 17 times. Sure, these assert that the function is working as intended, but say you optimize and reduce the recursion or method calls, then you need to go and update your expectations.</p>
<p>Of course, some of this is unavoidable when you are working with classes that have mocks injected into them. But in such a case, unless it is plain delegation, there must be some logic that must be happening. That should be the target of your tests, not the mock delegations. Usually, when I work with mocks, I have a few tests to make sure the right methods are getting called, and only if there is logic, I test it further. Otherwise, 1 or 2 tests and then I go and test the implementation of the mocked class to make sure it works under all conditions.</p>
<p>So lets consider a run of the mill binary search method that would be tested with mocks (A little bit contrived, but bear with me on this) :</p>
<pre>public int binarySearch(List&lt;Integer&gt; items, int itemToFind, int low, int high) {
<span style="background-color: #ffffff;">    // Do the needful, in a recursive fashion 
}</span></pre>
<pre>// A Brittle test
<span style="background-color: #ffffff; ">public void testUsingMocks() {
  List&lt;Integer&gt; list = mockery.mock(List.class);
  mockery.checking(new Expectations() {{
    oneOf(list).size(); will(returnValue(3));
    oneOf(list).get(1); will(returnValue(6));
  }});
  assertEquals(1, binarySearch(list, 6, 0, 2));
}</span></pre>
<p>Now, while a bit contrived, this is a familiar sight when mocks are used to test. Or it might happen that to check the correctness of the algorithm, the indices at which the split happens is stored in a list, and verified in the test. These are the kind of whitebox tests that make unit tests brittle. And the more of them there are, the harder it is to maintain or refactor code. Rather than testing it with for some use cases and boundary conditions, this is testing whether the algorithm itself is correct. Useful for some particular cases, but normally not required unless you are developing algorithm.</p>
<p>I would argue that its rare to write these kinds of tests if you write your tests before you write the methods. With a TDD, you just write your expectations, what you expect to give the method and what you expect out. You then write your code to get it to pass, and you might use internal variables or logic which the test really doesn&#8217;t care about. These tests are durable and hold up to refactorings, and even give you a nice safety net. There are times when these end up becoming integration tests rather than unit tests, but I still believe that they deliver more bang for the buck.</p>
<p>Of course, when you start testing edge cases, you do end up getting mostly a code dependent white box test, and those still are fine since they are supposed to be edge cases, which shouldn&#8217;t change that often. Though the fact that there are conditionals usually signifies that there is a polymorphic object hiding in there. But thats a blog post for another day.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/vQDNnu9lMcqnkHVz1ssR86fZi1E/0/da"><img src="http://feedads.g.doubleclick.net/~a/vQDNnu9lMcqnkHVz1ssR86fZi1E/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/vQDNnu9lMcqnkHVz1ssR86fZi1E/1/da"><img src="http://feedads.g.doubleclick.net/~a/vQDNnu9lMcqnkHVz1ssR86fZi1E/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/theshyam?a=3c_lYQA8Nfw:e_g3OXHq-3I:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=3c_lYQA8Nfw:e_g3OXHq-3I:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/theshyam?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=3c_lYQA8Nfw:e_g3OXHq-3I:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/theshyam/~4/3c_lYQA8Nfw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://theshyam.com/2009/09/testing-function-vs-testing-implementation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://theshyam.com/2009/09/testing-function-vs-testing-implementation/</feedburner:origLink></item>
		<item>
		<title>Software Engineering vs Software Artistry</title>
		<link>http://feedproxy.google.com/~r/theshyam/~3/9-TEKlxfd7Y/</link>
		<comments>http://theshyam.com/2009/09/software-engineering-vs-software-artistry/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 20:24:00 +0000</pubDate>
		<dc:creator>Shyam</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[engineer]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[se]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://theshyam.com/?p=199</guid>
		<description><![CDATA[Why is that we consider ourselves engineers, but can never agree on principles, techniques, methodologies. Each individual has their own way of doing things, each with their own positives and negatives, but we aspire to be engineers who follow time tested, safe, reliant methodologies. Are we software engineers, or are we software artists? ]]></description>
			<content:encoded><![CDATA[<p>I never expected my last post about whether <a href="http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/">Inheritance was needed or could be done away</a> with to spark such a furore. But spark a furore it did, especially at the <a href="http://java.dzone.com/articles/inheritance-overrated-needed">Java DZone lobby</a>. Maybe it was the inflammatory nature of the title (which could have been a tad bit exaggerated <img src='http://theshyam.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ), but whatever it was, it sure didn&#8217;t stop the flames. From being called &#8220;<em>incredibly naive</em>&#8221; to &#8220;<em>nonsense</em>&#8221; to even losing Dzone some subscribers, no stone was left overturned.</p>
<p>But what did surprise me at the end was the fact that for every dismissal of the idea, there was a proponent who understood my reasoning behind it. And of course, there were the people in the middle who would only say, &#8220;<em>Depends on the situation.</em>&#8221; And surprisingly, I agreed with a lot of their point of views. But that in turn led me down a line of thinking which led to this post.</p>
<p>Who is an <strong>engineer</strong>? In every other field other than computers and software, and engineer is one who uses scientific methodologies and time proven concepts to design and implement constructs / processes which reliably and safely perform specific tasks. Look at electrical engineering, or aerospace engineering. These guys consistently develop hardware (planes!!) which work. Every! Single! Time! No bugs, no defects. I mean, can you imagine a plane in the middle of the flight, and suddenly there&#8217;s a bug in the landing gear? Shudder&#8230;.</p>
<p>These guys follow some tried and tested techniques. There&#8217;s probably lore that every engineer depends on to create his next system. Passed down from generation to generation of what works and what shouldn&#8217;t be done. Same with civil engineering, there are no two ways to construct, say a building. Sure, you might differ in how it looks and what materials you use, but the base work of, creating a frame, etc remains the same (Then again, I have no clue what does go into buildings). The probability of a bug, or building a system that the next person in finds it impossible to maintain, are far less from what I have heard (and I will admit that this is based on hearsay).</p>
<p>Now, an <strong>artist</strong>, on the other hand, is usually defined as someone who expresses themselves through a medium. Interestingly though, the oxford dictionary has one of the definitions for an artist as &#8220;<em>A follower of a pursuit in which skill comes by study or practice &#8211; the opposite of a theorist</em>&#8220;. Now what does that remind you of? Exactly, engineering. To an extent, artistry is engineering, except note that in artistry, while the basics might be the same, the end results are usually unique. There still is no defined methodology or &#8220;<em>steps you follow to perform ABC&#8221;</em>. You work with what you have in the best possible way you know and you churn out something that may or may not be what you desired.</p>
<p>Now where do we fit as software engineers? We have some lore, some history of tried and true practices. We have design patterns, we have team practices like Agile, XP, etc. And we almost have an algorithm for everything. Its almost like an Apple Iphone ad, &#8220;<em>You need to search a graph? There&#8217;s an algorithm for that</em>.&#8221; But when it comes to implementation and combining all these into a single product, there is so much divergence. <span style="background-color: #ffffff;">Two people, given the exact same set of requirements, will come up with two almost completely differing solutions. And I&#8217;m not talking about just names. The architecture, the design patterns used, the way services are split up. And both of these may completely satisfy the requirements. Or they may end up being epic disasters. </span></p>
<p><span style="background-color: #ffffff;">What I&#8217;m saying is, there is no guaranteed recipe for success like in other fields of engineering. It is completely feasible to dig yourselves into a hole even while applying commonly known solid techniques. You might argue that this happens in other fields of engineering as well, like say, Boeings new 787 which has been delayed so many times. But to that, I say that they were trying to stretch the boundaries and innovate, and create something new. That rule applies to any engineering discipline, when you try to go above and beyond what currently exists.</span></p>
<p><span style="background-color: #ffffff;">But when you are creating run of the mill apps, like a Configuration system or a database data displayer, those should, by now, be trivial. But they aren&#8217;t. I know groups which spend more time and effort developing these than should be required. And finally developed, these turn into nightmares when you want to update them or add new features. You might say, &#8220;<em>Well, I never do that.</em>&#8221; To that, I say, sure, but remember the last time you moved onto a project with a legacy code base? Remember how that felt? Well, someone who was well-meaning, just like you, developed that disaster.</span></p>
<p><span style="background-color: #ffffff;">So are we Software Engineers or Artists? At the end of the day, it doesn&#8217;t matter what we are as long as the job gets done, but you would think we would finally start narrowing down on some concepts that can be universally agreed upon. Most software solutions I see as the end product are usually works of art. I have no clue how they made it, no clue how it works, but its beautiful nonetheless (or ugly, if that is how your artistic tendencies lie). Maybe we will be closer to being engineers in another 100 years? After all, civil engineering has been here for quite some time now.</span></p>

<p><a href="http://feedads.g.doubleclick.net/~a/XCZmRxQ5PvlKkUNduV41uEsvTx0/0/da"><img src="http://feedads.g.doubleclick.net/~a/XCZmRxQ5PvlKkUNduV41uEsvTx0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/XCZmRxQ5PvlKkUNduV41uEsvTx0/1/da"><img src="http://feedads.g.doubleclick.net/~a/XCZmRxQ5PvlKkUNduV41uEsvTx0/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/theshyam?a=9-TEKlxfd7Y:GsrQ3e9iLz8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=9-TEKlxfd7Y:GsrQ3e9iLz8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/theshyam?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=9-TEKlxfd7Y:GsrQ3e9iLz8:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/theshyam/~4/9-TEKlxfd7Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://theshyam.com/2009/09/software-engineering-vs-software-artistry/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://theshyam.com/2009/09/software-engineering-vs-software-artistry/</feedburner:origLink></item>
		<item>
		<title>Using Tracker for Agile projects</title>
		<link>http://feedproxy.google.com/~r/theshyam/~3/CELbiy32rjs/</link>
		<comments>http://theshyam.com/2009/09/using-tracker-for-agile-projects/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 17:31:53 +0000</pubDate>
		<dc:creator>Shyam</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Tool]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[pivotal]]></category>
		<category><![CDATA[planning]]></category>
		<category><![CDATA[Stories]]></category>
		<category><![CDATA[tracker]]></category>

		<guid isPermaLink="false">http://theshyam.com/?p=203</guid>
		<description><![CDATA[I first got exposed to the Agile methodology when I took a &#8220;Thinking in Agile&#8221; course. It was a two day course, and they walked you through what it meant to be agile, the processes involved, etc. But thinking back, I fell into the same trap I did back in college. It was mostly talk, [...]]]></description>
			<content:encoded><![CDATA[<p>I first got exposed to the Agile methodology when I took a &#8220;Thinking in Agile&#8221; course. It was a two day course, and they walked you through what it meant to be agile, the processes involved, etc. But thinking back, I fell into the same trap I did back in college. It was mostly talk, and not enough action. I learn by doing, and ipso facto, nothing really stuck. One and half years later, still at google, I became part of an internal project, which needed a kick start. And lo and behold, we decided to subscribe to the agile philosophies and not half ass it as many do. And we decided to use <a href="http://www.pivotaltracker.com/" target="_blank">Tracker</a> to manage the project.</p>
<p>The basic ideologies of Agile (and Tracker) are as follows. You work in short iterations (preferably a week or two). Every iteration, the entire team gets together to talk about what got done, and what is up next. You interact directly with the customer or his proxy, who gives you things to do in the form of stories. For a company search app, a story might look something along the lines of &#8220;<em>As a product owner, I want to be able to search for a particular employee, so that I know what he works on.</em>&#8221; Notice that this story is very well defined, especially for you as a developer. It tells you the target audience, what functionality is needed and why. The why is important because sometimes (not always), you might be able to think of a better way to do something, in which case you can pipe up with said suggestion. The example project below ignores that suggestion and I didn&#8217;t spend time to change the demo to meet my suggestions.</p>
<div id="attachment_207" class="wp-caption aligncenter" style="width: 522px"><a href="http://theshyam.com/wp-content/uploads/2009/08/Tracker.jpg"><img class="size-large wp-image-207 " title="Tracker" src="http://theshyam.com/wp-content/uploads/2009/08/Tracker-1024x341.jpg" alt="Tracker screen" width="512" height="170" /></a><p class="wp-caption-text">Tracker screen</p></div>
<p>Now tracker allows you to add and move stories around. You can move a story from the <strong>Icebox</strong> (which is where stories end up by default) into the <strong>Backlog</strong>, which are the things you need to work on. You can arrange them to order them by priority (and it is all immediate, so someone else with tracker open can see those changes as they happen). Now finally, during your iteration meeting, you sit as a team, and estimate how much each story is worth.</p>
<p>The most important point here is that <strong><em>clients are the only ones allowed to request stories</em></strong> (though you can probably figure out exceptions if you really think that some chores should get points). Customers get to decide what stories need to happen, and what order they need to happen in. Nothing more, nothing else. Now as <strong><em>developers</em></strong>, your role is to <strong><em>estimate how long</em></strong> it will take for the items in order. You can start off with some estimates like, &#8220;A point is one days work.&#8221; initially, when you are new. You can play <a href="http://en.wikipedia.org/wiki/Planning_poker">planning poker</a> to estimate, which is a fun little activity in itself to make sure no one is influenced by anyone else&#8217;s estimates. Now what tracker will do is it will measure how many stories you end up actually delivering per week, and calculate what we call your <strong>Average Velocity</strong> (pointed out in the screenshot above). This basically denotes how much tracker thinks you can do in the next iteration, assuming that your estimate base remains constant.</p>
<p>Another important thing to note, that only things that the customer cares about, or is customer facing, should be stories. These are thing the customer can see when delivered and brings value to him. So that refactoring you need to do to come out of that hole you dug for yourself? Guess what, its a chore and does not contribute to your velocity. Want to move database schemas to make it easier for yourself? Fixing that bug you introduced in trying to rush through all the stories? The customer doesn&#8217;t care (well he probably cares about the bugs, but you are not delivering value, you are cleaning up after your own mistakes), so no cookies nor any points for you.</p>
<p>So a basic flow for an iteration (after estimations and planning poker) is as follows ;</p>
<ol>
<li>Customer / Product owner prioritizes stories / chores / bugs in the backlog</li>
<li>Tracker looks at average velocity and figures out how many it can squeeze into the next iteration</li>
<li>Developers click <strong>start</strong> on a story / task when they start to work on it.</li>
<li>They click <strong>finish</strong> when they are done implementing on it, but <strong>do not</strong> click on Deliver</li>
<li>Pushmaster / Release Engineer clicks <strong>Deliver</strong> when those changes are pushed to a customer visible place</li>
<li>Customer gets to try out each story, and then can decide whether it meets specifications, and decides if he wants to <strong>accept / reject</strong>.</li>
</ol>
<p>Rinse and repeat, and you have a great way of managing requirements, release plans and so much more. You can figure out who&#8217;s working on what, you also get a great host of charting, including burndown charts, charts which allow you to figure out where you are spending the majority of time (whether stories, bugs, chores, etc). Example chart below :</p>
<div id="attachment_208" class="wp-caption aligncenter" style="width: 708px"><a href="http://theshyam.com/wp-content/uploads/2009/08/BurndownChart-1.jpg"><img class="size-full wp-image-208" title="Burndown Chart" src="http://theshyam.com/wp-content/uploads/2009/08/BurndownChart-1.jpg" alt="An example burndown chart from Tracker" width="698" height="428" /></a><p class="wp-caption-text">An example burndown chart from Tracker</p></div>
<p>Did I mention Tracker is currently free to sign up and start using? Regardless of whether you are a product manager who wants to keep his project in line, a developer interested in using agile practices, or just plain curious about what this thing is all about, Tracker has something for everyone. So, what are you waiting for, a personal invitation? You don&#8217;t need to be an Agile team to try this out for yourself.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/_8xPudc6GdxF7OCCYAII5FEPVXo/0/da"><img src="http://feedads.g.doubleclick.net/~a/_8xPudc6GdxF7OCCYAII5FEPVXo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/_8xPudc6GdxF7OCCYAII5FEPVXo/1/da"><img src="http://feedads.g.doubleclick.net/~a/_8xPudc6GdxF7OCCYAII5FEPVXo/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/theshyam?a=CELbiy32rjs:BqLqCepm31Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=CELbiy32rjs:BqLqCepm31Y:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/theshyam?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=CELbiy32rjs:BqLqCepm31Y:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/theshyam/~4/CELbiy32rjs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://theshyam.com/2009/09/using-tracker-for-agile-projects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://theshyam.com/2009/09/using-tracker-for-agile-projects/</feedburner:origLink></item>
		<item>
		<title>Micro update</title>
		<link>http://feedproxy.google.com/~r/theshyam/~3/cA9G1zG8KXw/</link>
		<comments>http://theshyam.com/2009/08/micro-update/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 08:34:55 +0000</pubDate>
		<dc:creator>Shyam</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Fiction]]></category>
		<category><![CDATA[jstestdriver]]></category>
		<category><![CDATA[micro update]]></category>
		<category><![CDATA[story]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://theshyam.com/?p=194</guid>
		<description><![CDATA[Considering I am visiting and working from Poland this week, I didn&#8217;t have time to get out a well thought out (read : flameworthy) article. Instead, I leave you with the following two tidbits.
One, I added my second ficlet to the Fiction part of my site. Titled 5 minutes, its a short story (around 2000 [...]]]></description>
			<content:encoded><![CDATA[<p>Considering I am visiting and working from Poland this week, I didn&#8217;t have time to get out a well thought out (read : flameworthy) article. Instead, I leave you with the following two tidbits.</p>
<p>One, I added my second ficlet to the Fiction part of my site. Titled <a href="http://theshyam.com/fiction/5-minutes/">5 minutes</a>, its a short story (around 2000 words, if I remember correctly) set in a fantasy / action genre. Written to see if I could write a story in second person point of view. Check it out and let me know what you think.</p>
<p>Two, I recently <a href="http://theshyam.com/2009/08/super-fast-js-testing/">blogged about JS Test Driver</a> and how awesome it was. Well, pictures do not do it justice, and <a href="http://jakeherringbone.com/">Alex</a> recently recorded a video demonstrating JS Test Driver and how it could possibly be used for Test Driving your javascript code. Give it a look, its pretty awesome, and shows you how awesome the Eclipse integration (my plugin, that is <img src='http://theshyam.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) is and just how blazing fast the test runner is.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/D5dMukRYlJc&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/D5dMukRYlJc&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>

<p><a href="http://feedads.g.doubleclick.net/~a/wdQ1ZSBzkf8egycNQ4rv6x2hYOo/0/da"><img src="http://feedads.g.doubleclick.net/~a/wdQ1ZSBzkf8egycNQ4rv6x2hYOo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/wdQ1ZSBzkf8egycNQ4rv6x2hYOo/1/da"><img src="http://feedads.g.doubleclick.net/~a/wdQ1ZSBzkf8egycNQ4rv6x2hYOo/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/theshyam?a=cA9G1zG8KXw:LO5moPfFEFE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=cA9G1zG8KXw:LO5moPfFEFE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/theshyam?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=cA9G1zG8KXw:LO5moPfFEFE:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/theshyam/~4/cA9G1zG8KXw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://theshyam.com/2009/08/micro-update/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://theshyam.com/2009/08/micro-update/</feedburner:origLink></item>
		<item>
		<title>Is Inheritance overrated ? Needed even?</title>
		<link>http://feedproxy.google.com/~r/theshyam/~3/PulQQEbpmAw/</link>
		<comments>http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 20:51:27 +0000</pubDate>
		<dc:creator>Shyam</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[noop]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[oo]]></category>
		<category><![CDATA[polymorphism]]></category>

		<guid isPermaLink="false">http://theshyam.com/?p=172</guid>
		<description><![CDATA[To give some context to this topic, the idea was brought forward to me by Alex Eagle. I was happily coding away when Alex sprung his idea for Composition over Inheritance for Noop &#8211; a language we are developing with testability and dependency injection in mind. My gut reaction was that this was blasphemy, and [...]]]></description>
			<content:encoded><![CDATA[<p>To give some context to this topic, the idea was brought forward to me by <a href="http://jakeherringbone.com/" target="_blank">Alex Eagle</a>. I was happily coding away when Alex sprung his idea for <a href="http://code.google.com/p/noop/wiki/ProposalForComposition">Composition over Inheritance</a> for <a href="http://code.google.com/p/noop/">Noop</a> &#8211; a language we are developing with testability and dependency injection in mind. My gut reaction was that this was <strong>blasphemy</strong>, and it <strong>couldn&#8217;t be done</strong>. You can&#8217;t just do away with inheritance, its one of the building blocks of OO based programming languages. But now, after I have let the idea digest for a few days, it doesn&#8217;t seem so far fetched any more. And here&#8217;s why.</p>
<p>Let me first talk about the biggest problems with vanilla inheritance as we have it in Java. Joshua Bloch hits it on the nail in his <strong>Effective Java</strong> book item about &#8220;<strong><em>Favoring composition over inheritance</em></strong>.&#8221; But lets do a quick recap anyway.</p>
<p>The biggest problem is that inheritance often ends up <strong>breaking encapsulation</strong>. This is because the child class depends on the implementation of the parent class. But between releases, something in the parent class implementation can change and can break all child classes without even touching its code. Another common gotcha is in how protected fields and members are used. Often, the parent class changes the value of fields depending on how methods are called. Not understanding this behavior often leads to buggy or simply wrong behavior from the subclasses.</p>
<p>Another problem with a subclass &#8211; especially from the point of view of unit testing &#8211; is that there is <strong>no way to create an instance of the subclass in isolation</strong>. By this, I mean that everytime I create an instance of the subclass, I am forced to have the parent class as well. In most cases, this shouldn&#8217;t be a problem, but I have run into situations where the parent class is just a landmine waiting to explode, with the default constructor not being explicit in stating its dependencies. So instant Kablaam!!! Or the parent class will load things you don&#8217;t really care about and make things slow in a test. There was this insidious test I ran into once, which extended a base test case, which did the same thing. About 7 layers deep. And the test itself didn&#8217;t really care about 3 or 4 of those layers, but had to jump through all the hoops and get everything because it was a parent class.</p>
<p>There are a few more issues, which are well documented in Effective Java item 16, &#8220;Favor composition over inheritance.&#8221;. I won&#8217;t bore you further on this, assuming I have convinced the skeptics about the problems with inheritance. If not, go read that book, and you shall be convinced. But then, I wanted to postulate on whether it was at all possible to have a programming language which does away with inheritance (As <a href="http://code.google.com/p/noop/wiki/ProposalForComposition" target="_blank">Noop proposes</a>).</p>
<p>So when do we use inheritance ? To me, Polymorphism is about the only time when inheritance and subclassing is deemed appropriate. Be it having different subtypes or just plain old code reuse. So unless you want to have a base abstract class which has some methods defined (Like Shape with draw() method and Circles and Rectangles), inheritance is not really needed.</p>
<p>In Java, interfaces allow you to perform polymorphic operations with abandon, and convert between types. And interfaces don&#8217;t straddle you down with the requirement that you get the base class for every instance.</p>
<p>Also, if you use composition, then you can reuse code by using delegation. For example, you could define a Shape interface with a DefaultShape implementation. Now rather than subclassing a concrete type Shape, you could have a Rectangle which implements Shape. And if you wanted to reuse some code, let Rectangle take in a DefaultShape instance and just delegate to it when necessary. This offers multiple benefits. One, you are not tied down to getting things from the base class. In your test, you could pass in a mock, a null, whatever you want. The only problem is that this option is not viable if you don&#8217;t have an interface. If that is the case (or the thing you are subclassing is in a package outside of your control), then you are stuck doing inheritance the old fashioned way.</p>
<p>And this is (atleast the last time I heard the proposal) what Noop aims to solve. When you want to subclass, you tell the class what you want to compose. Regardless of whether it is an interface or not, it will create that class with an instance of your composition type. By default, all methods in the composition type will be available in the subclass, and it will delegate automatically, unless you override it. You get complete control over object creation, and this could potentially support multiple inheritance through this approach.</p>
<p>What do other people think ? It this feasible ? Am I missing something obvious when inheritance is the only approach and composition just doesn&#8217;t cut it (both right now and in the Noop proposal) ? Are you interested in Noop ? Drop me a line.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/WhW5EauTHNS8yc0p2iNCF8oKhew/0/da"><img src="http://feedads.g.doubleclick.net/~a/WhW5EauTHNS8yc0p2iNCF8oKhew/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/WhW5EauTHNS8yc0p2iNCF8oKhew/1/da"><img src="http://feedads.g.doubleclick.net/~a/WhW5EauTHNS8yc0p2iNCF8oKhew/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/theshyam?a=PulQQEbpmAw:nseUFVqzNaA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=PulQQEbpmAw:nseUFVqzNaA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/theshyam?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=PulQQEbpmAw:nseUFVqzNaA:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/theshyam/~4/PulQQEbpmAw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://theshyam.com/2009/08/is-inheritance-overrated-needed-even/</feedburner:origLink></item>
		<item>
		<title>Super fast JS Testing</title>
		<link>http://feedproxy.google.com/~r/theshyam/~3/J-GWGo9EhhY/</link>
		<comments>http://theshyam.com/2009/08/super-fast-js-testing/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 16:42:43 +0000</pubDate>
		<dc:creator>Shyam</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Tool]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[jstestdriver]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://theshyam.com/?p=164</guid>
		<description><![CDATA[Before I jump into how exactly you can perform super fast and easy JS testing, let me give you some background on the problem.
Javascript is a finicky language (Some people even hesitate to call it a language). And it can easily grow and become a horrible and complicated beast, incapable of being tamed once let [...]]]></description>
			<content:encoded><![CDATA[<p>Before I jump into how exactly you can perform super fast and easy JS testing, let me give you some background on the problem.</p>
<p>Javascript is a finicky language (Some people even hesitate to call it a language). And it can easily grow and become a horrible and complicated beast, incapable of being tamed once let loose. And testing it is a nightmare. Once you have decided on a framework (of which there are a dime a dozen), you then have to set it up to run just right. You need to set it up to actually run your tests. Then you have to figure out how to run it in a continuous integration environment. Maybe even run it in headless mode. And everyone solves it in their own ways.</p>
<p>But the biggest problem I have with most of these frameworks is that executing the tests usually requires a context switch. By that, I mean to run a JSUnit test, you end up usually having to open the browser, browse to a particular url or html page which then runs the test. Then you have to look at the results there, and then come back to your editor to either proceed further or fix your tests. Works, but really slows down development.</p>
<p>In java, all it takes is to click the run button in your IDE to run your tests. You get instant feedback, a green / red bar and details on which tests passed and failed and at what line. No context switch, you can get it to run at every save, and proceed on your merry way. Till now, this was not possible with Javascript.</p>
<p>But now, we have <a href="http://code.google.com/p/js-test-driver/" target="_blank">JS Test Driver</a>. My colleagues Jeremie and <a href="http://misko.hevery.com" target="_blank">Misko</a> ended up running into some of the issues I outlined above, and decided that going along with the flow was simply unacceptable. So they created a JS Testing framework which solves these very things. You can capture any browser on any machine, and when you tell it to run tests, it will go ahead and execute them on all these browsers and return you the results in your client. And its blazing fast. I am talking milliseconds to run 100 odd tests. And you can tell it to rerun your tests at each save. All within the comforts of your IDE. And over the last three weeks, I have been working on the eclipse plugin for JS Test Driver, and its now at the point where its in a decent working condition.</p>
<div id="attachment_165" class="wp-caption aligncenter" style="width: 438px"><a href="http://theshyam.com/wp-content/uploads/2009/08/JS-Test-Driver-Plugin.png"><img class="size-full wp-image-165" title="JS Test Driver Plugin" src="http://theshyam.com/wp-content/uploads/2009/08/JS-Test-Driver-Plugin.png" alt="The plugin in action" width="428" height="478" /></a><p class="wp-caption-text">The plugin in action</p></div>
<p>The plugin allows you to, from within Eclipse, start the JS Test Driver server, capture some browsers, and then run your tests. You get pretty icons telling you what browsers were captured, the state of the server, the state of the tests. It allows you to filter and show only failures, rerun your last launch configuration, even setup the paths to your browsers so you can launch it all from the safety of eclipse. And as you can see, its super fast. <strong><em>Some 100 odd tests in less than 10 ms</em></strong>. If thats not fast, I don&#8217;t know what is.</p>
<p>For more details on JS Test Driver, visit its <a href="http://code.google.com/p/js-test-driver/" target="_blank">Google Code</a> website and see how you can use it in your next project and even integrate it into a continuous integration. Misko talks a little bit more about the motivations behind writing it on his <a href="http://misko.hevery.com/2009/05/22/yet-another-javascript-testing-framework/" target="_blank">Yet Another JS Testing Framework</a> post. To try out the plugin for yourselves, go add the following update site to eclipse : <strong>http://js-test-driver.googlecode.com/svn/update/</strong>. For all you IntelliJ fanatics, there is something similar in the works.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/RtzzuiBqkWztt-VmWXHikVpkxKw/0/da"><img src="http://feedads.g.doubleclick.net/~a/RtzzuiBqkWztt-VmWXHikVpkxKw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/RtzzuiBqkWztt-VmWXHikVpkxKw/1/da"><img src="http://feedads.g.doubleclick.net/~a/RtzzuiBqkWztt-VmWXHikVpkxKw/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/theshyam?a=J-GWGo9EhhY:NSWYyclRD0k:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=J-GWGo9EhhY:NSWYyclRD0k:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/theshyam?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/theshyam?a=J-GWGo9EhhY:NSWYyclRD0k:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/theshyam?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/theshyam/~4/J-GWGo9EhhY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://theshyam.com/2009/08/super-fast-js-testing/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://theshyam.com/2009/08/super-fast-js-testing/</feedburner:origLink></item>
	</channel>
</rss>
