<?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>Learning by Experience &#187; Java</title> <atom:link href="http://www.inze.be/andries/category/java/feed/" rel="self" type="application/rss+xml" /><link>http://www.inze.be/andries</link> <description>Java, Project Management, Life and anything else.</description> <lastBuildDate>Mon, 09 Jan 2012 21:38:00 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>BruJug: Sébastien Stormacq, Build a RESTful Client-Server RIA with JavaFX Technology and Jersey</title><link>http://www.inze.be/andries/2010/09/07/brujug-sebastien-stormacq-build-a-restful-client-server-ria-with-javafx-technology-and-jersey/</link> <comments>http://www.inze.be/andries/2010/09/07/brujug-sebastien-stormacq-build-a-restful-client-server-ria-with-javafx-technology-and-jersey/#comments</comments> <pubDate>Tue, 07 Sep 2010 18:55:17 +0000</pubDate> <dc:creator>Andries Inzé</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[jbug]]></category> <guid
isPermaLink="false">http://www.inze.be/andries/?p=235</guid> <description><![CDATA[Copy paste : Speakers and Talks Sébastien Stormacq Sébastien Stormacq is a Senior Software Architect at Oracle (Sun Microsystems). He uses his 15 years of professional experience to design large scale, secured and highly transactional architectures based on Sun’s middleware solutions. He also speaks at various high level Java conferences, like JavaOne 2009 and 2010, [...]]]></description> <content:encoded><![CDATA[<p>Copy paste <img
src='http://www.inze.be/andries/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> :</p><p><em>Speakers and Talks </em></p><h5><em><a
id="sebastien_stormacq" name="sebastien_stormacq">Sébastien Stormacq</a></em></h5><div><p><em><a
title="events:sebastien_stormacq.jpg" href="http://www.brussels-jug.be/wiki/lib/exe/detail.php?id=events%3A2010_09_session1&amp;media=events:sebastien_stormacq.jpg"><img
title="Sébastien Stormacq" src="http://www.brussels-jug.be/wiki/lib/exe/fetch.php?w=100&amp;media=events:sebastien_stormacq.jpg" alt="Sébastien Stormacq" width="100" align="left" /></a></em></p><p><em>Sébastien Stormacq is a Senior Software Architect at Oracle (Sun  Microsystems). He uses his 15 years of professional experience to design  large scale, secured and highly transactional architectures based on  Sun’s middleware solutions. He also speaks at various high level Java  conferences, like JavaOne 2009 and 2010, and he is one of the JUG  Leaders of the Luxembourg JUG.</em></p><p><em><a
title="http://www.yajug.org" rel="nofollow" href="http://www.yajug.org/">http://www.yajug.org</a></em></p><p><em><a
title="http://www.stormacq.com/" rel="nofollow" href="http://www.stormacq.com/">http://www.stormacq.com/</a></em></p></div><h5><em><a
id="section" name="section">.</a></em></h5><div><p><em><em> Build a RESTful Client-Server Rich Internet Application with JavaFX Technology and Jersey (JSR 310) </em></em></p><p><em><a
title="events:javafxcup100x110.png" href="http://www.brussels-jug.be/wiki/lib/exe/detail.php?id=events%3A2010_09_session1&amp;media=events:javafxcup100x110.png"><img
src="http://www.brussels-jug.be/wiki/lib/exe/fetch.php?media=events:javafxcup100x110.png" alt="" align="left" /></a>Rich  Internet Applications (RIA) do require a strong service access and data  access layer located on the back-end, just as traditional or web based  applications. It is therefore essential to combine desktop technologies  and server technologies in order to provide fast, efficient and secure  access to your data. This talk will teach how to combine desktop  technologies, such as JavaFX technologies, and back-end technologies,  like web services and REST based services to build state of the art  desktop applications. We will use the following technologies: RESTful  web service and JSR 310 (Jersey) <acronym
title="Application Programming Interface">API</acronym> on the server side, JavaFX on the client side. The JavaFX application  will asynchronously poll RESTful web services to collect data that will  be used to dynamically update the client rich UI.</em></p><p><em><em> Hands-On Training </em></em></p><p><em>After the 1st halftime, Sébastien proposes a hands-on training. Everyone is invited to bring long their <em>laptop with Netbeans 6.91, Glassfish and JavaFX installed</em>.  If wished, we can make teams of 2-3 persons. Every team will develop  simple application doing JavaFX – REST – Java EE. Sébastien will walk  around, help and discuss.</em></p><p><em>So please don&#8217;t forget your laptop, and if you have a  multi-outlet power strip at hand, we don&#8217;t mind neither <img
src='http://www.inze.be/andries/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p><p><em>Let&#8217;s do JavaFX from the zero to hero in one evening <img
src='http://www.inze.be/andries/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p></div><p>I&#8217;ll be there!</p><p>More information at http://www.brussels-jug.be/wiki/doku.php?id=events:2010_09_session1</p> ]]></content:encoded> <wfw:commentRss>http://www.inze.be/andries/2010/09/07/brujug-sebastien-stormacq-build-a-restful-client-server-ria-with-javafx-technology-and-jersey/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>The BusinessException pattern</title><link>http://www.inze.be/andries/2008/08/18/the-businessexception-pattern/</link> <comments>http://www.inze.be/andries/2008/08/18/the-businessexception-pattern/#comments</comments> <pubDate>Mon, 18 Aug 2008 21:08:58 +0000</pubDate> <dc:creator>Andries Inzé</dc:creator> <category><![CDATA[architecture]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[patterns]]></category> <guid
isPermaLink="false">http://www.inze.be/andries/?p=41</guid> <description><![CDATA[This exception is probably one of the most common home-made exceptions, one that pops up in almost every project. I'll try and show you how it works and what the advantages are.]]></description> <content:encoded><![CDATA[<p>This exception is probably one of the most common<em> home-made</em> exceptions, one that pops up in almost every project. I&#8217;ll try and show you how it works and what the advantages are.</p><p>One of the &#8220;problems&#8221; of doing all the business logic in the Service (or UseCase, Business) Layer is getting the right exception message back onto the screen. Lot&#8217;s of times people invent all kinds of home-brewed exceptions: e.g. <em>ResultNotFoundException</em>, <em>InsufficientFundsException</em>, <em>DateTooFarIntoFutureException</em>, &#8230;<br
/> Another approach, which is far worse, is to let specialized exceptions like a <em>ConstraintViolation </em>(hibernate), <em>UserException </em>(axis) and many others. It couples the front-end to back end.</p><p>When defining custom exceptions for every problem, you force the controller to catch all the exceptions that could be thrown separately. Adding a new exception can be cumbersome, and it does not really matter if you define them as checked or unchecked, unless you plan to catch the remaining exceptions with a generic info message like: something went wrong&#8230;</p><h2>What&#8217;s the correct solution?</h2><p>Here comes the BusinessException</p><pre>public class BusinessException
    extends RuntimeException {
	/** A code indicating the cause of
            the exception. */
	private String code;
	/** The exception that is wrapped by
            the business component. */
	private Exception wrappedException;
	/**
	 * Constructor.
	 *
	 * @param code The code indicating the
         * cause of the exception.
	 * @param wrappedException The exception
         * that is wrapped by the business
         * component.
	 */
	public BusinessException(String code,
          Exception wrappedException) {
		this.code = code;
		this.wrappedException =
                  wrappedException;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public Exception getWrappedException() {
		return wrappedException;
	}
	public void setWrappedException(
           Exception wrappedException) {
		this.wrappedException = wrappedException;
	}
}</pre><p>When a business rule validation has been detected, a new BusinessException should be throw.</p><p>When an exception is thrown from any layer beneath the Controller layer, it should be wrapped by the BusinessException.</p><p>The <em>code</em> is the key for translation by the view renderer.</p><h2>Placing this in the architecture</h2><p>When we place the BusinessException into a widely use architectural stack we come up with something like this:</p><p
style="text-align: center;"><a
title="BusinessException architecture" href="http://www.inze.be/andries/wp-content/architecture.jpg" target="_blank"><img
class="aligncenter size-medium wp-image-56" title="architecture" src="http://www.inze.be/andries/wp-content/architecture-300x160.jpg" alt="" width="300" height="160" /></a></p><h2>Advantages</h2><p>The advantages are clear:</p><ul><li>The controller and other layers are loosely coupled (e.g. no DAO dependency in Controller)</li><li>The transaction can be rolled back, since the exception is thrown.</li><li>The controllers aren&#8217;t forced to catch many exceptions.</li><li>No need for those custom made exceptions. One exception to rule them all!</li></ul><h2>BusinessException versus other exceptions</h2><p>The businessException should wrap a recoverable violation or exception, that can be displayed in the screen. Transaction is rolled back, and the user can change the input and/or try again.</p><p>Normal exceptions are unrecoverable. The transaction is rolled back, and the user is directed to an error page.</p><p>It&#8217;s not the point to wrap every exception, but only the expected ones. Don&#8217;t wrap a It&#8217;s a really simple pattern, but a very powerful one.</p><p>In essence 4 scenario&#8217;s can happen:</p><ol><li>The first level fails. Typically this is something like a missing required field. The user is redirected to the same page to fix the problem.</li><li>The second validation fails: a business exception is thrown.  Typically this is a business rule that failed, for instance a balance is too low to complete a purchase. It also could be an exception wrapped by the BusinessException. For instance when the database row has changed after you loaded it.</li><li>Everything succeeded, the business layer returned normally.</li><li>The business layer threw an exception (not a BusinessException), the page is redirected to the error page. Unrecoverable, should only be on programming bug.</li></ol><h2>Conclusion</h2><p>A lot has to be said for straight and simple win-win patterns. This one is definately one of those.</p> ]]></content:encoded> <wfw:commentRss>http://www.inze.be/andries/2008/08/18/the-businessexception-pattern/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>Should we discard Interfaces?</title><link>http://www.inze.be/andries/2008/05/17/should-we-discard-interfaces/</link> <comments>http://www.inze.be/andries/2008/05/17/should-we-discard-interfaces/#comments</comments> <pubDate>Sat, 17 May 2008 19:23:35 +0000</pubDate> <dc:creator>Andries Inzé</dc:creator> <category><![CDATA[general]]></category> <category><![CDATA[Java]]></category> <guid
isPermaLink="false">http://www.inze.be/andries/?p=29</guid> <description><![CDATA[Whether we are writing DAO&#8217;s, services or use case, most of the time we create interfaces for these implementations. It allows us to program against interfaces, a common best practice for all of us. Using interfaces gives us following advantages: Enables loose coupling between interacting classes Makes it easier to test Allows us to easily [...]]]></description> <content:encoded><![CDATA[<p>Whether we are writing DAO&#8217;s, services or use case, most of the time we create interfaces for these implementations. It allows us to <em>program against interfaces</em>, a common best practice for all of us. Using interfaces gives us following advantages:</p><ul><li>Enables loose coupling between interacting classes</li><li>Makes it easier to test</li><li>Allows us to easily switch between implementations.</li></ul><p>Lately, I&#8217;ve been openly questioning if we should always use interfaces. Are they always required by default and is the extra cost of keeping the interface and the implementation in sync worth the trouble? Lets discuss.</p><p>When we are using dependency injection, the coupling between one class and another is very low. It&#8217;s of course true that by injecting implementation instead of interfaces we are making the coupling a little tighter.  The classes are still in isolation, since neither creates a new instance. This is still done by the DI container, which deals with instantiation and configuration.</p><p>Is a class that only has interfaces as dependencies easier to test then classes that have implementations as dependencies? Most of us are eager to say yes, but in fact, frameworks like <a
href="http://www.easymock.org/">EasyMock </a>enable us to mock (non final) classes. We can add behavior just like any other interface.</p><p>When writing an application, it&#8217;s very rare to change the implementation of an interface. Almost all my interfaces have exactly one implementation. Sometimes this is not the case naturally, but I find it pretty easy to spot those implementation that might or will change in the near <em>foreseeable </em>future.</p><p>If we should reduce the amount of interfaces in our code, the advantages could be:</p><ul><li>Less classes which (should) equal to less configuration and maintenance</li><li>Less synchronization during development so results in a little faster velocity</li></ul><p>Anyway, this is purely speculative.</p><p>Let me state that I&#8217;m not thinking about actually dumping the interfaces. It&#8217;s a proven practice, but I&#8217;m think out loud and for myself. What I&#8217;m looking for is an insight or story that will convince me either way. So if you have any, I&#8217;m more then eager the hear!</p><p>Andries</p> ]]></content:encoded> <wfw:commentRss>http://www.inze.be/andries/2008/05/17/should-we-discard-interfaces/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Optimize your development</title><link>http://www.inze.be/andries/2008/01/07/optimize-your-development/</link> <comments>http://www.inze.be/andries/2008/01/07/optimize-your-development/#comments</comments> <pubDate>Sun, 06 Jan 2008 22:35:30 +0000</pubDate> <dc:creator>Andries Inzé</dc:creator> <category><![CDATA[eclipse]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[management]]></category> <guid
isPermaLink="false">http://www.inze.be/andries/?p=7</guid> <description><![CDATA[When you are not careful about how you develop your software, it&#8217;s easy to do this in an inefficient way. The last couple of weeks I&#8217;ve been streamlining the developers their workstation, to become as efficient as possible. I&#8217;ll talk about some of the measures I took, how it was done and what the final [...]]]></description> <content:encoded><![CDATA[<p>When you are not careful about how you develop your software, it&#8217;s easy to do this in an inefficient way. The last couple of weeks I&#8217;ve been streamlining the developers their workstation, to become as efficient as possible. I&#8217;ll talk about some of the measures I took, how it was done and what the final benefits were. Also, I&#8217;d like to talk about some of the possible drawbacks.</p><h1>Shorten the build cycle for developers</h1><p>The length of the build-cycle is critical for developers.</p><h2>Exploded development</h2><p>With the release of JBoss Tools for eclipse, I finally managed to get a very good exploded development going on. I tested the beta 3 as well as the beta 4. In both cases, exploded wars didn&#8217;t function as I wanted. Didn&#8217;t remember quite what didn&#8217;t work, but with the the GA release, everything worked out fine.</p><p>The main benefit of exploded development is the powerful option to edit JSP files live! This is a serious advantage. Our team started out without this, but as the project <em>exploded</em> in size, the start-up time was increasing drastically. Would not ever want to do another project without this ability!</p><p>Another great benefit is the possibility for incremental publishing (standard behavior with the plug-in). Packing a war is something that can take half a minute or longer using eclipse, with incremental publishing only the changed files are submitted, resulting in mere seconds.</p><p>The last benefit is a faster start-up, since the server doesn&#8217;t have to unpack the war. Our war is about 45Mb large, which took 10-15 seconds to unpack.</p><p>There is one setback! When using this, there is a bug when you have breakpoints in eclipse. The breakpoints sometimes (and this is rather frequent, say 1 in 5) cause the server to start up really slow. And slow is like 1h to start&#8230; The workaround here is to restart the server and disable the breakpoints on start-up, enabling them once the server is started. It&#8217;s a common bug when you Google for it, so I&#8217;m confident this will get resolved soon.</p><h2>Hot-code replacement</h2><p>Learning how to use hot-code replacement can save some restarts of the server. With hot code replacement, you can alter any Java code, as long as you stay within the method where your breakpoint currently <em>hangs</em>. This is perfect for adjusting 1 line of code, since most bugs are exactly one small thing that was wrong.</p><p>There is a little more to it. Sometimes eclipse complains about the failure of the hot code replace. What we do is following: we let the thread run until it&#8217;s finished. Then we start the code again (refresh the page, submit a form&#8230;) and let it stop on the same breakpoint. Then we add 1 space and save it. This never fails!</p><h2>No Hibernate Cache</h2><p>Another great way to speedup the start time during development, is to disable the Hibernate cache (second level cache, query cache) during development. With a maven profile, this is done very easy.</p><p>We have about 25 classes that are non-strict read/write cached. This takes about 12 seconds to start-up, every class that is cached has it&#8217;s own thread started by Hibernate (I think this is for timeout of the cache).</p><h2>No premature loading of cached items</h2><p>Many applications start by eager fetching some data this is cached then. I believe this is completely useless in a development environment. Again with Maven this ain&#8217;t hard to set up.</p><h2>A word about Spring configuration</h2><p>One could argue that the Spring configuration could also be completely lazy. Indeed, this would be a tremendous start-up gain, in our 100 beans large project, it takes 20 seconds to set up the beans. It&#8217;s the single most time consuming event in our application start-up.</p><p>We don&#8217;t do this, since it posses a real danger. With lazily initiated beans you lose the dependency checks at start-up</p><h1>Shorten the setup time</h1><p>Setting up eclipse is something we needed to do quite a lot of times. When switching branches, when added dependencies etc.</p><p>We used to use the maven eclipse plug-in. Lately I found out that this plug-in is absolutely unnecessary. With the proper maven setup, the simple command <em>mvn eclipse:eclipse</em> does the trick. Actually you need two things:</p><pre>            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
                &lt;configuration&gt;
                    &lt;wtpversion&gt;1.5&lt;/wtpversion&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;</pre><p>Above is a plugin in the web module (pom.xml).</p><pre>&lt;jboss-web&gt;
    &lt;context-root&gt;mistral&lt;/context-root&gt;
&lt;/jboss-web&gt;</pre><p>Above is the content of the file webapp/WEB-INF/jboss-web.xml , which sets the context-root with jboss. If you don&#8217;t do this, it&#8217;ll default to the war filename.</p><h1>Other optimizations</h1><p>In order to have the best possible environment, other optimizations are in order. But I&#8217;ll keep those for my follow-up. Things that can be improved:</p><ul><li>Use of the continuous integration.</li><li>A (good) project wiki</li><li>How to manage multiple databases <span
style="text-decoration: underline;">efficiently</span>(database independence per developer)</li><li>Office instant messaging</li></ul><h1>Conclusion</h1><p>Pretty long post. There is a lot to say about development optimizations. My experience in it is that there is a lot to gain. There are some key concerns however:</p><ul><li>KISS, Keep It Simple Stupid.  An optimization should never be something that has to be explained. Optimizations are only good optimizations when they feel natural, they should also make things simpler almost never more complex.</li><li>A very important one: a team should work all in the same manner. It&#8217;s too hard when multiple ways of developing have to be supported.</li><li>Don&#8217;t be afraid to change your development manners. Sometimes a change can be a little investment, but large gains on longer terms.</li></ul><p>As always, I&#8217;m open for debate and questions.</p><p>Regards,<br
/> Andries</p> ]]></content:encoded> <wfw:commentRss>http://www.inze.be/andries/2008/01/07/optimize-your-development/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Extract Method: an in-depth motivation</title><link>http://www.inze.be/andries/2007/10/18/extract-method-an-in-depth-motivation/</link> <comments>http://www.inze.be/andries/2007/10/18/extract-method-an-in-depth-motivation/#comments</comments> <pubDate>Thu, 18 Oct 2007 21:11:02 +0000</pubDate> <dc:creator>Andries Inzé</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[refactoring]]></category> <guid
isPermaLink="false">http://www.inze.be/andries/?p=16</guid> <description><![CDATA[Extract method is one of the easiest refactorings within the GoF patterns. Developers tend to look at large methods and use Extract Method only then. Well, there is a lot more to this simple refactoring then just splitting up large methods. Let&#8217;s digg in! Separation of responsibility Methods should have 1 concern (responsibility, purpose, &#8230; [...]]]></description> <content:encoded><![CDATA[<p>Extract method is one of the easiest refactorings within the <a
href="http://en.wikipedia.org/wiki/Design_Patterns" title="GoF" target="_blank">GoF </a>patterns. Developers tend to look at large methods and use <em>Extract Method</em> only then. Well, there is a lot more to this simple refactoring then just splitting up large methods. Let&#8217;s digg in!</p><h3>Separation of responsibility</h3><p>Methods should have 1 concern (responsibility, purpose, &#8230; ). Let&#8217;s look into the matter with an example. Consider following code:</p><pre>public void createCustomer(Map requestParameters) {
	Customer customer = new Customer();
	customer.setName = requestParameters.get("name");</pre><pre>	//Check if a customer was already registered with that name
	if (customerService.getCustomerByName(customer.getName()) != null) {
		System.out.println("Customer already exists");
		return;
	}
	customer.setShoppingCart(new ShoppingCart());</pre><pre>	customerService.save(customer);</pre><pre>}</pre><p>The above code is something I scraped together, it&#8217;s not real code. But it illustrates something I see regular. The method name is <em>save</em>. So I expect that the code only does some saving. Instead it creates a new customer, checks if it&#8217;s valid (no double names) and then saves it. So the method is actually performing 3 things.</p><p>This method should be refactored into 4 methods. The first method, which I would call <em>bindValidateAndSave</em> is the <em>algorithm </em>method. It tells what to do, not how it&#8217;s done. Its responsibility is to provide the algorithm. The 3 other methods would be called <em>bindCustomer </em>(bind and add new shoppingCart), <em>validateCustomer</em> and <em>saveCustomer</em>.</p><p>With the last method (<em>saveCustomer</em>) I get the <em>WHY?</em> question a lot, since the extracted method is actually only 1 line of code long. Although it might not improve readability for programmers, it&#8217;s a paradigm shift in how the method is addressed. In our example, if the <em>saveNewCustomer</em> calls customerService.save() it&#8217;s responsible that the save method is actually called right. Instead if we let it delegate to a newly extracted method (<em>saveCustomer) </em>it isn&#8217;t responsible for the explicit saving. Instead now it defines the algorithm. In this case bind, validate, save. The implementation is just the save method.</p><p>Working in this fashion takes some getting used to, but in the end I truly believe this produces stabler and more maintainable code.</p><h3>Self-describing methods</h3><p>The second insight I have about the <em>Extract Method</em> refactoring, is removing comments from my code. A lot of fresh developers believe writing comments is the key to great software. As Martin Fowler stated in his excellent book Refactoring, comments are really a bad smell that something is wrong. Either your code is too complex or too long winded. Extracting code just to give it a nice method name helps readability. Take for instance the following example:</p><pre>public void eat(Food food)  {
	//Other eat actions...</pre><pre>	//Need to blow on the food cause it might be hot
	while (food.getTemp() &gt; 50) {
		mouth.blow();
	}
}</pre><p>Although the example is completely stupid, it would be slightly less stupid if written like this:</p><pre>public void eat(Food food)  {
	//Other eat actions...
	blowWhileHot(food);
	mouth.eat(food);</pre><pre>}
private void blowWhileHot(Food food) {
	while (food.getTemp() &gt; 50) {
		mouth.blow();
	}
}</pre><p>Et voila, our code just became A LOT more readable.</p><p>I agree, both examples are intertwined  in most cases, but there is a difference between the two.</p><p>Both insights are developed by reading <a
href="http://www.refactoring.com" title="Refactoring" target="_blank">Refactoring</a>, a book that definitely made it into my top 10 list!</p><p>Got any comments, let&#8217;s hear them!</p><p>Andries</p> ]]></content:encoded> <wfw:commentRss>http://www.inze.be/andries/2007/10/18/extract-method-an-in-depth-motivation/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Garry Kasparov translated into Java Development.</title><link>http://www.inze.be/andries/2007/07/31/garry-kasporov-translated-into-java-development/</link> <comments>http://www.inze.be/andries/2007/07/31/garry-kasporov-translated-into-java-development/#comments</comments> <pubDate>Tue, 31 Jul 2007 21:28:49 +0000</pubDate> <dc:creator>Andries Inzé</dc:creator> <category><![CDATA[breadth]]></category> <category><![CDATA[chess]]></category> <category><![CDATA[Java]]></category> <guid
isPermaLink="false">http://www.inze.be/andries/?p=13</guid> <description><![CDATA[About 2 weeks ago, I finished the book &#8220;How life imitates chess&#8221; by Garry Kasparov. For those who don&#8217;t know him, here is his Wikipedia entry. Anyway, the books has absolutely nothing to do with Java Development. But when I was reading it, most things could be reflected back to good development practices. I&#8217;ll share [...]]]></description> <content:encoded><![CDATA[<p>About 2 weeks ago, I finished the book <em>&#8220;How life imitates chess&#8221; </em>by Garry Kasparov. For those who don&#8217;t know him, here is his <a
href="http://nl.wikipedia.org/wiki/Garry_Kasparov" target="_blank">Wikipedia entry</a>. Anyway, the books has absolutely nothing to do with Java Development. But when I was reading it, most things could be reflected back to good development practices. I&#8217;ll share what I&#8217;ve learned.</p><p>First off, a small apology. I&#8217;ve read the book in Dutch, and he uses terms that I can only translate so and so.</p><p><strong>MTQ</strong></p><p>MTQ stands for Material, Time and Quality. Every thing you do can be mapped into these 3 parts. The material you are making, the time it took for making it and the quality of the finished product. It&#8217;s important that there is a great dynamic between the three. If you change 1 of them, at least another one needs to compensate. The sum is constant. Think about it. If you are nearing a deadline and have a unit of work to do, you can do three things. First is to produce less, second is to take longer and last is finishing with less quality then you would deliver normally.</p><p>His most important point on this subject was that the relation between the three exists. Always. There is no such thing as work faster during a period of time. Working faster generally means less quality. Period.</p><p>I see MTQ as a measure of efficiency. A good senior developer will produce the same material as a junior developer, but in less time and better quality.</p><p>Translating this into best practices, is to realise deadlines are not flexible without taking into consideration of the MTQ theory. Quality is probably the most abstract term, which reflects into less bugs, more maintainable code and better documentation.</p><p><strong>Strategy and Tactics</strong></p><p>A strategy is a road-map with certain goals. Goals could be learning a technology, get promoted into a certain function, learn a new skill&#8230; The goals are generally a long time further into the future.</p><p>A tactic is a certain action you will take, that gets you closer to a certain goal. The tactic fits in your strategy.</p><p>Translating this into java development is setting milestones into your release plan. Milestones are important strategies, and taking the hardest part first (if possible) is generally a good starting point for choosing the milestones. See the milestones as your strategy, as where specific implementation details are your tactics. Examples of such tactics could be choosing the right technology, using frameworks, and so on.</p><p>Side-notes he made are following:</p><ul><li>Strategies that change a lot, aren&#8217;t strategies at all: Change can be important but requires are decisive reason and good reasoning.</li><li>Asking why a lot, make good strategics from tacticians.  Asking why to yourself forces you to think things through, see bigger pictures and learn more understanding.</li></ul><p><strong>Decision Making</strong></p><p>Even as developer, we need to make choices every day. We have to determine which the best approach is to resolve a certain problem, which implementation would be best, how we can refactor something and so on. Not to mention higher level decision making, like overseeing development, finding wrong implementation before they become problematic.</p><p>To make our decision making efficient, we need to direct the process. Kasparov states that you need to learn to make decisions and give pointers on how you should. Let&#8217;s solve a simple problem: decide the best bugfix.<br
/> Start off by giving yourself some time to spin up some possible solutions, brainstorm in your mind to provide even the most idiot solution. Search for at least 3 alternatives, let the imagination thrive! Now, depending on the amount of alternatives you&#8217;ve found, pick the 2-3 most promising and examining them. Think steps ahead. Ask yourself following questions for each alternative:</p><ul><li>If I change my code like this, where will my behavior change in other code? And if I change other code that was affected, will these changes affect even more code? (See the steps ahead coming?).</li><li>Is my proposed fix easy to maintain, will I need to document a lot?</li><li>Can I do better? How?</li></ul><p>After questioning yourself, pick the best choice. Now, this may seem to take long, but you will be awarded following:</p><ul><li>Receive confidence in your code. Writing code in confidence makes you a better programmer (and makes it more fun).</li><li>Be able to see bugs BEFORE they are written. No explanation needed here, does it.</li><li>Write cleaner, better and more maintainable code. Your code will be smart, just like you.</li></ul><p><strong>See habits and deal with them</strong></p><p>This one is something I do a lot as well. Coders tend to have certain habits, good and bad. A habit I tend to have is to dive into code straight away (Bad Bad Bad&#8230;). Other habits could be forgetting to write tests, commenting code and forget to remove it, writing idiot comments or none at all, choosing dubious names and so on. The point is, we should self-evaluate and see these bad habits. Knowing yourself is being a better person.</p><p>Everyone has a bad habit, when identified you should deal with it. Force yourself to write tests, hang a big post-it on the screen to never forget it. Personally I&#8217;ve make myself write halve the code in my mind before actually starting to write.</p><p>One of my favourites was that I knew about 5 shortcuts in Eclipse until 6 months. Identified this as a bad habit, printed the cheat sheet and forced myself to use them. When I didn&#8217;t , I deleted my piece of code I had generated and did it again by the shortcut. 6 months later I know like 50 shortcuts in eclipse, which owns. The downside is now with Eclipse Europe, they changed some of them (alt+enter for one), which is frustrating&#8230;</p><p><strong>Game Stages</strong></p><ul><li>Opening Game: In opening games you use a repertoire to setup the board. Openings are predetermined setups of the board. You can reflect this to use what you know, when starting a new project. Or better yet: use what works. Don&#8217;t reinvent the wheel. There are a lot of common best practices to be used when starting up a new project.</li><li>The middle game: Here is where developing matters. Building up the application up to the next release. Nice play where one should overcome possible dangers and problems. No predetermined path can be found, as every chess game is unique (and so is every application), one will have to deal with the problems as they arrive.</li><li>The endgame: Here the amount creativity drops to a bare minimum. See this as the final days before a release. Only a very limited path to success is available. Here we need to focus on what needs to be done.</li></ul><p><strong>The advantage of the attacker.</strong></p><p>Attacking problems before they are too big is better then to wait until a problem is blocking. Attackers are in advantage because less code is dependent on the problem, making the solution simpler.</p><p><strong>Final thoughts</strong></p><p>I do admit, this is a limited snapshot of the book. I&#8217;ve filtered the stuff out that actually could be mapped into java development. Some topics he wrote about were a big stretch to get into the Java world <img
src='http://www.inze.be/andries/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Anyway, I&#8217;ve tried on the best parts and I hope you enjoyed it.</p><p><strong>More about the book</strong></p><p>Do I recommend this book? Yes! Although it&#8217;s not the best book I&#8217;ve read in it&#8217;s branch, it&#8217;s definitely worth reading. I enjoyed mapping my mind to his, seeing how stuff he encountered could and did reflect on me. In the end, I became a wiser person, something I strive for at the moment.</p><p>It changed my perspective on certain topic, I especially liked the part about the MTQ and the decision making progress. Also the end of the book, which deals less about chess and more about dealing with yourself, was an eye opener on a lot of topics.</p> ]]></content:encoded> <wfw:commentRss>http://www.inze.be/andries/2007/07/31/garry-kasporov-translated-into-java-development/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
