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

<channel>
	<title>Hitesh Sarda &#187; @work</title>
	<atom:link href="http://hitesh.in/tag/work/feed/" rel="self" type="application/rss+xml" />
	<link>http://hitesh.in</link>
	<description>Thoughts on life, technology, education and entrepreneurship</description>
	<lastBuildDate>Fri, 30 Dec 2011 06:00:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Evaluating in-house frameworks</title>
		<link>http://hitesh.in/2011/evaluating-in-house-frameworks/</link>
		<comments>http://hitesh.in/2011/evaluating-in-house-frameworks/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 08:14:39 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[@work]]></category>

		<guid isPermaLink="false">http://hitesh.in/2011/evaluating-in-house-frameworks/</guid>
		<description><![CDATA[In-house frameworks The very mention of this word brings out different memories and emotions for different people. More so if is a framework for be used within a large company, by a completely different team than the one writing it. &#8230; <a href="http://hitesh.in/2011/evaluating-in-house-frameworks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>In-house frameworks</h3>
<p>The very mention of this word brings out different memories and emotions for different people. More so if is a framework for be used within a large company, by a completely different team than the one writing it.</p>
<p>To make sure that the next time you hear this word, you have positive memories; use the evaluation sheet below, before adopting the framework. If you are the one writing the framework, make sure you have good answers to these.</p>
<h2>Why in-house frameworks?</h2>
<p>Before we begin, let&#8217;s recap why we need in-house frameworks in the first place.</p>
<p><span id="more-631"></span>Each company, more so is it is an &#8216;enterprise&#8217; has a certain set of internal standards and a &#8216;way to do things&#8217;. Be those be related to security, encryption, authentication, authorisation or be it about data retention, traceability, logging or monitoring. The foremost benefit of an in-house framework is out-of-the-box support for these standards and hence any solution built on them is preapproved by the standards committee, while saving the developers from reinventing the wheel for these.</p>
<p>These frameworks also know the company&#8217;s domain and can provide a lot of helper functions at the least to a full blown DSL on the other extreme. Thus an in-house framework is a <em>good thing to have</em> if it can pass the evaluation criteria.</p>
<h2>How to evaluate an in-house framework?</h2>
<p>Well, it is no different from evaluating a external framework, be it commercial or an open-source one.</p>
<ul>
<li>What is the origin of the framework?
<ul>
<li>Was it created from a blank slate, based on past project learning? If so, has it been battle-tested? You don&#8217;t want to be the guinea pig.</li>
<li>Was it extracted out of software delivered? Is it still tightly coupled to the environment the original software ran in?</li>
</ul>
</li>
<li>What is the team&#8217;s motivation to maintain this framework?
<ul>
<li>Is the framework their primary task or is it a distraction? This is especially the case when the framework is either extracted from a project or was primarily written for a specific project.</li>
</ul>
</li>
<li>What is the development model?
<ul>
<li>Does it mimic a commercial vendor? What is the governance model around support and enhancement request?</li>
<li>Or does it mimic open-source model? What is the governance model around roadmap, vision and acceptance of patches?</li>
<li>Does the framework team have a consistent vision to avoid the framework from acquiring feature-bloat, and at the same time is it extensible enough for a team using it?</li>
</ul>
</li>
<li>What is the learning curve? How well documented it the framework?
<ul>
<li>This is the single most important question to ask. For external frameworks, you have the internet to help you out, but for internal ones, the documentation is normally the only hope. In addition, you can hire people with skills in external framework, but will need to train every new hire on the internal framework, so it better have a short learning curve.</li>
</ul>
</li>
<li>What is the release and support model?
<ul>
<li>You don&#8217;t want to be using a framework which does not have a specific release cadence and a know support model for older versions. Neither should the support model allow proliferation of versions in <em>the</em><br />
<em>wild</em>, nor should it force and upgrade every 3 months.</li>
</ul>
</li>
<li>Finally, will it last?
<ul>
<li>Is there organisational and budget support for the framework team?</li>
<li>Will the framework continue to live after the lead developers have left?</li>
</ul>
</li>
</ul>
<div>If you have other criterion, please leave a comment below.</div>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2011/evaluating-in-house-frameworks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dumping thread stack trace in Java &amp; .NET</title>
		<link>http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/</link>
		<comments>http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 06:26:35 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[@work]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=609</guid>
		<description><![CDATA[Multi-threaded Java practitioners know about the indispensible ways to taking thread dumps to see a snapshot of what&#8217;s happening in the JVM, and resolve &#8216;hang&#8217; issues. There are plethora of options, ranging from simple command line tools and utilities to &#8230; <a href="http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Multi-threaded Java practitioners know about the indispensible ways to taking thread dumps to see a snapshot of what&#8217;s happening in the JVM, and resolve &#8216;hang&#8217; issues. There are plethora of options, ranging from simple command line tools and utilities to nice GUI applications to writing some code in your application. A sampling of such options:</p>
<h3>Stack trace in Java</h3>
<h4>Command Line</h4>
<p>If the application is running as a console application, you can try one of these:</p>
<p><strong>Sending a signal to the Java Virtual Machine</strong></p>
<p>On UNIX platforms you can send a signal to a program by using the kill command. This is the quit signal, which is handled by the JVM. For example, on Solaris you can use the command <code>kill -QUIT process_id</code>, where process_id is the process number of your Java program.</p>
<p><span id="more-609"></span>Alternatively you can enter the key sequence <code>&lt;ctrl&gt;\</code> in the window where the Java program was started. Sending this signal instructs a signal handler in the JVM, to recursively print out all the information on the threads and monitors inside the JVM.</p>
<p>To generate a stack trace on Windows, enter the key sequence <code>&lt;ctrl&gt;&lt;break&gt;</code> in the window where the Java program is running, or click the Close button on the window.<br />
(Excerpt from <a href="http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/">http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/</a>)</p>
<p>If the application is not running in a console, you can use the <a href="http://download.oracle.com/javase/1.5.0/docs/tooldocs/share/jstack.html">jstack</a> tool that ships with J2EE since 1.5</p>
<pre><strong>jstack</strong> [ option ] pid
<strong>jstack</strong> [ option ] executable core
<strong>jstack</strong> [ option ] [server-id@]remote-hostname-or-IP</pre>
<h4>GUI Tools</h4>
<p>Since the JVM provides APIs to hook in and get the thread state and other information, there are several tools in the market that allows you to see the state of the running application including the thread stack trace. One such freely available option is <a href="http://download-llnw.oracle.com/javase/6/docs/technotes/guides/visualvm/index.html">VisualVM</a>. In fact it ships with JDK these days. Although VisualVM is pretty self explanatory, here are some instructions to get you started. <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/threads.html">http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/threads.html</a></p>
<p><img title="screenshot of thread dump (stack trace) in thread dump sub-tab" src="http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/images/thread-dump-screen.png" alt="screenshot of timeline in Threads tab" /></p>
<p>You could also use jConsole for similar purpose, but I prefer VisualVM. Check this for more information: <a href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html#DeadlockDetection">http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html#DeadlockDetection</a></p>
<p><img src="http://java.sun.com/developer/technicalArticles/J2SE/jconsole/FindDeadlock-IDs.jpg" alt="Figure 11: Find Deadlocked Threads" width="675" height="530" border="0" /></p>
<h4>Programmatically capturing the stack trace</h4>
<p>from within an appilcation, you can call : <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#getStackTrace()" target="_blank">Thread.getAllStackTraces()</a>. But if you want to do the same from a different application, <a href="http://download.oracle.com/javase/6/docs/api/java/lang/management/ThreadMXBean.html" target="_blank">ThreadMXBean</a> exposes the needed data, which can be retrieved by using the <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/management/ManagementFactory.html" target="_blank">JMX interface</a>.</p>
<h3>Dumping thread Stack trace in .NET</h3>
<p>.NET does not seem to have the variety of options like Java. The only reasonable option I have seen so far is the <a href="http://www.codeplex.com/wikipage?ProjectName=MSE" target="_blank">Managed Stack Explorer</a>. This can be run from the command line as</p>
<pre>mse /s /p &lt;pid&gt;</pre>
<p>or as a GUI application:</p>
<p><a href="http://hitesh.in/wp-content/uploads/2010/DumpingthreadstacktraceinJava.NET_76CB/image.png"><img style="display: inline; border: 0px;" title="image" src="http://hitesh.in/wp-content/uploads/2010/DumpingthreadstacktraceinJava.NET_76CB/image_thumb.png" alt="image" width="586" height="454" border="0" /></a></p>
<p>Since it is an open source (MSPL) project, I took a peek into its source to check the API used. It depends on some sample code released by the CLR Team called <a href="http://www.microsoft.com/downloads/details.aspx?familyid=38449a42-6b7a-4e28-80ce-c55645ab1310&amp;displaylang=en" target="_blank">mdbg</a>. This in turn is a managed layer on the unmanaged <a href="http://msdn.microsoft.com/en-us/library/bb397953.aspx" target="_blank">CLR Debugging Services API</a>.</p>
<p>From what I see there seems to be no direct way to get a stack trace in .NET, apart from either using the debugger API, or rolling your own on top of the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.aspx" target="_blank">StackTrace</a> class. Check <a href="http://stackoverflow.com/questions/51768/print-stack-trace-information-from-c" target="_blank">this question on StackOverflow</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beware of the clone</title>
		<link>http://hitesh.in/2010/beware-of-the-clone/</link>
		<comments>http://hitesh.in/2010/beware-of-the-clone/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 07:12:02 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[@work]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=605</guid>
		<description><![CDATA[Why Clone In this world of concurrent, multi-threaded programming, functional style of programming makes more sense. And one of the key tenets of functional programming is immutability. Even in OO languages, a few benefits of FP can be derived if &#8230; <a href="http://hitesh.in/2010/beware-of-the-clone/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Why Clone</h2>
<p>In this world of concurrent, multi-threaded programming, functional style of programming makes more sense. And one of the key tenets of functional programming is immutability. Even in OO languages, a few benefits of FP can be derived if the objects are made immutable.</p>
<h2>Clone gone wrong</h2>
<p>We follow a similar approach in our application. But this is not always possible, especially the mutable by default approach of Java. To overcome this, we pass around clones of instances, instead of the instance itself. This works in most cases, but we experienced a very subtle bug last week, where one thread was changing the values on a clone held by another thread, in spite of having no reference to it.</p>
<h2><span id="more-605"></span>The cause</h2>
<p>After lot of disbelief and head scratching, the reason was there, right in front. We were calling the instance.clone() to create a clone. The clone function defined in the Object class (more or less) takes each variable and makes a copy if it and assigns it to the variable of the new instance. This works great for stack variable, but the for the ones on the heap, only the reference is copied, in effect both the clones have reference to the same instance of the member variable. In other words, it does a shallow copy and you might actually need a deep copy sometimes.</p>
<p><strong>Before Clone</strong></p>
<p><img src="http://hitesh.in/wp-content/uploads/2010/07/072410_0712_Bewareofthe1.png" alt="" /></p>
<p><strong>After Clone</strong></p>
<p><img src="http://hitesh.in/wp-content/uploads/2010/07/072410_0712_Bewareofthe2.png" alt="" /></p>
<h2>The effect</h2>
<p>Thus any change made to MyClassInstance.OtherClass after MyClassClone was created also changes the MyClassClone.OtherClass, leading to confusing side effects.</p>
<h2>The solution</h2>
<p>Once the problem is understood, the solution is obvious. Just override the clone method and clone any reference classes in it.</p>
<p>Check <a href="http://stackoverflow.com/questions/2890340/question-about-cloning-in-java">http://stackoverflow.com/questions/2890340/question-about-cloning-in-java</a> for more.</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2010/beware-of-the-clone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rock SOLID software construction</title>
		<link>http://hitesh.in/2009/rock-solid-software-construction/</link>
		<comments>http://hitesh.in/2009/rock-solid-software-construction/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 07:32:15 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[@work]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[solid]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=179</guid>
		<description><![CDATA[I spent last two weeks deep diving into code written by our contractors and writing some test against the same. This was a pleasant break from my regular duties of an architect. As an architect I am always trying to &#8230; <a href="http://hitesh.in/2009/rock-solid-software-construction/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignright" style="width: 307px"><a href="http://www.lostechies.com/blogs/derickbailey/archive/2009/02/11/solid-development-principles-in-motivational-pictures.aspx" target="_blank"><img title="SOLID" src="http://hitesh.in/wp-content/uploads/2009/08/080809_0732_RockSOLIDso1.jpg" alt="SOLID - Software Developement is not a game of Janga" width="297" height="244" /></a><p class="wp-caption-text">Software Developement is not a game of Janga</p></div>
<p>I spent last two weeks deep diving into code written by our contractors and writing some test against the same. This was a pleasant break from my regular duties of an architect. As an architect I am always trying to ensure the code follows pragmatic design principle and I really dig SOLID and TDD.</p>
<p>&lt;aside&gt;</p>
<h2>S.O.L.I.D. (a.k.a. S.O.L.D.I.)</h2>
<p>The charm of <a href="http://blog.objectmentor.com/articles/category/uncle-bobs-blatherings">Uncle Bob</a> is, he can give a concrete shape to abstract ideas. I have been following the principles laid out by SOLID for some time, but he makes them fit together and remove ambiguity.</p>
<p>So, what is SOLID principle?<br />
<span id="more-179"></span>SOLID stands for:</p>
<p><a href="http://www.objectmentor.com/resources/articles/srp.pdf">The Single Responsibility Principle</a> &#8211; <em>A class should have one, and only one, reason to change.</em></p>
<blockquote><p>Do one thing and do it well. Haven&#8217;t we heard this before?</p></blockquote>
<p><a href="http://www.objectmentor.com/resources/articles/ocp.pdf">The Open Closed Principle</a> &#8211; <em>You should be able to extend a classes behaviour, without modifying it.</em></p>
<blockquote><p><span style="font-size:12pt">You achieve this mostly by following the other principles.<br />
</span></p></blockquote>
<p><a href="http://www.objectmentor.com/resources/articles/lsp.pdf">The Liskov Substitution Principle</a> &#8211; <em>Derived classes must be substitutable for their base classes.</em></p>
<blockquote><p>The class performing actions on the base class or any of its subclasses need not know the difference.</p></blockquote>
<p><a href="http://www.objectmentor.com/resources/articles/dip.pdf">The Dependency Inversion Principle</a> &#8211; <em>Depend on abstractions, not on concretions.</em></p>
<blockquote><p>DI is the new &#8211; new <img src='http://hitesh.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Seriously, DI makes a big difference in testability and abstraction. You could fail at DI if you violate Liskov substitution principle. And if you do follow DI, you are mostly guaranteed to adhere to Open Close principle.</p></blockquote>
<p><a href="http://www.objectmentor.com/resources/articles/isp.pdf">The Interface Segregation Principle</a> &#8211; <em>Make fine grained interfaces that are client specific.</em></p>
<blockquote><p>This one is a bit difficult to grasp, but think about it and it is simple. All it says is to &#8220;Keep is Simple&#8221;. Why create an interface which has 10 methods, when the client only needs 3 of those. If you think you need 10 methods, because somewhere down the road you will need them, well, &#8220;You Ain&#8217;t Gonna Need It&#8221;.</p></blockquote>
<p>&lt;/aside&gt;</p>
<p>Coming back to the subject at hand, here&#8217;s a summary of the two weeks.</p>
<h2>Week 1</h2>
<p>I spent week one reviewing, writing test cases and refactoring a new application. This application is written on Spring Framework with a bit of secret sauce. It adheres mostly to the SOLID principles but has the tests all wrong. They violated most unit testing &#8216;laws&#8217;. Long story short, they were integration test and not unit tests.</p>
<p>Created mocks and stubs, injected these into the container and then wrote unit tests using the mocks. After the exercise, I was happy with the removal of all test dependencies and that the tests ran blazing fast. As an added benefit, I could now see the code coverage and compare them build on build.</p>
<p>Following this, I trained the contractors. Gave them a brief overview on unit testing the right way, and then showed how it could be done. Did a pair programming session and helped them write some tests.</p>
<h2>Week 2</h2>
<p>Buoyed by success of week one, I decided to attack the big hairy monster. This is a J2EE application with myriad dependences. DB, JMS, RMI, Tibco Rendezvous; you name it, you got it. The application has grown organically for 10 years and developed by multiple teams. The unit tests take 2 hours to complete! Mostly since they aren&#8217;t unit tests at all.</p>
<p>As advised by <a href="http://www.objectmentor.com/omTeam/feathers_m.html">Michael Feathers</a> in the book &#8220;Working Effectively with Legacy Code&#8221;, I started by writing tests and breaking dependencies.</p>
<p>I was successful in breaking dependencies, but I had to perform some nasty hacks. Since the classes were not open to modification and depended directly on the J2EE container I had to mock the container. On the bright side, since EJB 1.1 and 2.0 required certain interfaces, I could easily mock the Home classes and write dummy implementations where needed.</p>
<p>Then I hit a million line tall code wall. This <a href="http://en.wikipedia.org/wiki/God_object">God object</a> knows everything and does everything, and I mean <em>everything</em>.  This is an ugly artefact in an otherwise well written application. It violates every single design principle and has a directory of who&#8217;s who of anti-patterns. And the methods in the class are to be called in a particular order, else you will invite God&#8217;s wrath. The methods do more than they advertised, do not throw or return errors, least cohesion, and what not.</p>
<p>Due to this, the tests I wrote can only validate a complete workflow and not individual steps. At least the tests are not dependent on external factors and run fast. The next task on my plate is to refactor the god object into smaller classes that follow the SOLID principles.</p>
<p>To do so, I am following the advice in the book &#8220;Working Effectively with Legacy Code&#8221;.</p>
<p>Please share your advice, tips and experiences on the same.</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2009/rock-solid-software-construction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

