<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-28376608</id><updated>2008-11-11T10:18:54.330-08:00</updated><title type='text'>Valuable Code</title><subtitle type='html'>What &lt;i&gt;is&lt;/i&gt; it about code that makes it valuable?</subtitle><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default'/><link rel='alternate' type='text/html' href='http://www.valuablecode.com/'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://valuablecode.com/atom.xml'/><author><name>Alistair McKinnell</name><uri>http://www.blogger.com/profile/16041326715656647934</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-28376608.post-2867971898667415006</id><published>2008-11-11T09:33:00.000-08:00</published><updated>2008-11-11T10:18:54.359-08:00</updated><title type='text'>Simplicity is Hard</title><content type='html'>&lt;em&gt;Simplicity&lt;/em&gt; is one the &lt;a href="http://en.wikipedia.org/wiki/Extreme_programming#XP_values"&gt;values&lt;/a&gt; of Extreme Programming. Simplicity is hard.&lt;br /&gt;&lt;br /&gt;To achieve simplicity you need to be able recognize the presence or absence of simplicity.&lt;br /&gt;&lt;br /&gt;Perhaps more than anything you need a strong desire for simplicity.&lt;br /&gt;&lt;br /&gt;Once you have achieved simplicity don't be surprised when you show your code to your colleagues and they react with a &lt;em&gt;Looks right. Why would you do it any other way&lt;/em&gt;?&lt;br /&gt;&lt;br /&gt;While I find this kind of reaction personally disappointing, it means that I've achieved simplicity.&lt;br /&gt;&lt;h3 style="margin-bottom:0px;"&gt;Refactoring to Simpler Code&lt;/h3&gt;&lt;br /&gt;Here is some code from my current project:&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public boolean isAllowedToAddAdministrators() {&lt;br /&gt;   boolean retVal = false;&lt;br /&gt;   SecurityRole currentUsersSecurityRole = getUiContext().getUser().getSecurityRole();&lt;br /&gt;   if (currentUsersSecurityRole.equals(SecurityRole.SYSADMIN)) {&lt;br /&gt;       retVal = true;&lt;br /&gt;   }&lt;br /&gt;   return retVal;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I'm going to refactor it to this:&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public boolean isAllowedToAddAdministrators() {&lt;br /&gt;   return loggedInUser().isSysAdmin();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Did you just think to yourself &lt;em&gt;Looks right. Why would you do it any other way&lt;/em&gt;?&lt;br /&gt;&lt;h3 style="margin-bottom:0px;"&gt;Refactoring Steps&lt;/h3&gt;&lt;br /&gt;Here is that same code from my current project:&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public boolean isAllowedToAddAdministrators() {&lt;br /&gt;   boolean retVal = false;&lt;br /&gt;   SecurityRole currentUsersSecurityRole = getUiContext().getUser().getSecurityRole();&lt;br /&gt;   if (currentUsersSecurityRole.equals(SecurityRole.SYSADMIN)) {&lt;br /&gt;       retVal = true;&lt;br /&gt;   }&lt;br /&gt;   return retVal;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="refactoringStep"&gt;The first thing I notice is that the code seems unnecessarily complicated. It's written using a &lt;em&gt;structured code&lt;/em&gt; style that is not warranted in this case. Essentially, &lt;code&gt;isAllowedToAddAdministrators()&lt;/code&gt; uses a condition to assign to a boolean return value. Instead, I can just return the condition.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.valuablecode.com/images/bullet_go.png" class="refactoringStep" /&gt;Apply &lt;em&gt;Simplify Boolean Logic&lt;/em&gt;.&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public boolean isAllowedToAddAdministrators() {&lt;br /&gt;   SecurityRole currentUsersSecurityRole = getUiContext().getUser().getSecurityRole();&lt;br /&gt;   return currentUsersSecurityRole.equals(SecurityRole.SYSADMIN);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="refactoringStep"&gt;The code doesn't feel right. I often use inlining to gain a fresh perspective.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.valuablecode.com/images/bullet_go.png" class="refactoringStep" /&gt;Apply &lt;a href="http://www.refactoring.com/catalog/inlineTemp.html"&gt;Inline Temp&lt;/a&gt; to &lt;code&gt;currentUsersSecurityRole&lt;/code&gt;.&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public boolean isAllowedToAddAdministrators() {&lt;br /&gt;   return getUiContext().getUser().getSecurityRole().equals(SecurityRole.SYSADMIN);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;The code still doesn't feel right, although, you could argue that it is as simple as it could be.&lt;br /&gt;&lt;br /&gt;Whenever I have to read code like this I find it hard to tease out the intention: I'm thrashing about in nothing but implementation details. I think I can make it simpler by extracting some little methods.&lt;br /&gt;&lt;br /&gt;&lt;div class="refactoringStep"&gt;&lt;img src="http://www.valuablecode.com/images/bullet_go.png" class="refactoringStep" /&gt;Apply &lt;a href="http://www.refactoring.com/catalog/extractMethod.html"&gt;Extract Method&lt;/a&gt; to &lt;code&gt;getUiContext().getUser()&lt;/code&gt; to create &lt;code&gt;loggedInUser()&lt;/code&gt;.&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public boolean isAllowedToAddAdministrators() {&lt;br /&gt;   return loggedInUser().getSecurityRole().equals(SecurityRole.SYSADMIN);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private IUser loggedInUser() {&lt;br /&gt;   return getUiContext().getUser();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="refactoringStep"&gt;&lt;img src="http://www.valuablecode.com/images/bullet_go.png" class="refactoringStep" /&gt;Apply &lt;a href="http://www.refactoring.com/catalog/extractMethod.html"&gt;Extract Method&lt;/a&gt; to &lt;code&gt;loggedInUser().getSecurityRole().equals(SecurityRole.SYSADMIN)&lt;/code&gt; to create &lt;code&gt;isSysAdmin()&lt;/code&gt;.&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public boolean isAllowedToAddAdministrators() {&lt;br /&gt;   return isSysAdmin(loggedInUser());&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private boolean isSysAdmin(IUser loggedInUser) {&lt;br /&gt;   return loggedInUser.getSecurityRole().equals(SecurityRole.SYSADMIN);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private IUser loggedInUser() {&lt;br /&gt;   return getUiContext().getUser();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="refactoringStep"&gt;Often when I see code of the form &lt;code&gt;someFunction(anObject)&lt;/code&gt; I want to transform it to the form &lt;code&gt;anObject.someFunction()&lt;/code&gt;. This procedural-style to object-style heuristic is telling me that I should move the &lt;code&gt;isSysAdmin()&lt;/code&gt; method to the &lt;code&gt;User&lt;/code&gt; class.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.valuablecode.com/images/bullet_go.png" class="refactoringStep" /&gt;Apply &lt;a href="http://www.refactoring.com/catalog/moveMethod.html"&gt;Move Method&lt;/a&gt; to &lt;code&gt;isSysAdmin()&lt;/code&gt;.&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public class SecurityPolicy {&lt;br /&gt;  &lt;br /&gt;   public boolean isAllowedToAddAdministrators() {&lt;br /&gt;       return loggedInUser().isSysAdmin();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private IUser loggedInUser() {&lt;br /&gt;       return getUiContext().getUser();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class User implements IUser {&lt;br /&gt;  &lt;br /&gt;   public boolean isSysAdmin() {&lt;br /&gt;       return securityRole.equals(SecurityRole.SYSADMIN);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h3 style="margin-bottom:0px;"&gt;Where did I end up?&lt;/h3&gt;&lt;br /&gt;I refactored the &lt;code&gt;isAllowedToAddAdministrators()&lt;/code&gt; method&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public class SecurityPolicy {&lt;br /&gt;  &lt;br /&gt;   public boolean isAllowedToAddAdministrators() {&lt;br /&gt;       boolean retVal = false;&lt;br /&gt;       SecurityRole currentUsersSecurityRole = getUiContext().getUser().getSecurityRole();&lt;br /&gt;       if (currentUsersSecurityRole.equals(SecurityRole.SYSADMIN)) {&lt;br /&gt;           retVal = true;&lt;br /&gt;       }&lt;br /&gt;       return retVal;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;first to&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public class SecurityPolicy {&lt;br /&gt;  &lt;br /&gt;   public boolean isAllowedToAddAdministrators() {&lt;br /&gt;       return getUiContext().getUser().getSecurityRole().equals(SecurityRole.SYSADMIN);&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and then to&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public class SecurityPolicy {&lt;br /&gt;  &lt;br /&gt;   public boolean isAllowedToAddAdministrators() {&lt;br /&gt;       return loggedInUser().isSysAdmin();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private IUser loggedInUser() {&lt;br /&gt;       return getUiContext().getUser();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class User implements IUser {&lt;br /&gt;  &lt;br /&gt;   public boolean isSysAdmin() {&lt;br /&gt;       return securityRole.equals(SecurityRole.SYSADMIN);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So, how exactly is where I ended up simpler? Why didn't I stop the refactoring after the first step?&lt;br /&gt;&lt;br /&gt;&lt;h3 style="margin-bottom:0px;"&gt;Two Simplicity Heuristics&lt;/h3&gt;&lt;br /&gt;Two simplicity heuristics that I use are the &lt;em&gt;Telephone Test&lt;/em&gt; and a preference for &lt;em&gt;Little Methods&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;To perform the &lt;a href="http://www.amazon.com/Elements-Programming-Style-Brian-Kernighan/dp/0070342075"&gt;Telephone Test&lt;/a&gt; you attempt to read your code to someone over the telephone. If the person on the other end does not understand what you are talking about, then you need to rewrite your code.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.amazon.com/Smalltalk-Best-Practice-Patterns-Kent/dp/013476904X/"&gt;Little Methods&lt;/a&gt; are short methods, named by what they are intended to do, not how they do it.&lt;br /&gt;&lt;br /&gt;The final version of &lt;code&gt;isAllowedToAddAdministrators()&lt;/code&gt; is a Little Method that passes the Telephone Test.&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public boolean isAllowedToAddAdministrators() {&lt;br /&gt; return loggedInUser().isSysAdmin();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I can imagine this exchange:&lt;br /&gt;&lt;br /&gt;Q: When does the application allow administrators to be added?&lt;br /&gt;A: When the logged in user is a SysAdmin.&lt;br /&gt;&lt;br /&gt;How does the Telephone Test work for this code?&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;   public boolean isAllowedToAddAdministrators() {&lt;br /&gt;       return getUiContext().getUser().getSecurityRole().equals(SecurityRole.SYSADMIN);&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Q: When does the application allow administrators to be added?&lt;br /&gt;A: When the UI Context user's security role is equal to SysAdmin.&lt;br /&gt;&lt;br /&gt;Code readability is so important: my programming speed is way more limited by my ability to read and comprehend code than it is by my ability to type code.&lt;br /&gt;&lt;br /&gt;When I created &lt;code&gt;isSysAdmin()&lt;/code&gt; on the User class I created a Little Method:&lt;br /&gt;&lt;pre name="code" class="Java:nocontrols"&gt;&lt;br /&gt;public boolean isSysAdmin() {&lt;br /&gt; return securityRole.equals(SecurityRole.SYSADMIN);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Notice how when I had finished refactoring I'd created 3 single line methods. This style of coding requires well chosen names that reveal intent. Poor names will force the reader to mentally inline each of the Little Methods.&lt;br /&gt;&lt;br /&gt;So why do I like to code with lots of well-named little methods? Because in code, as in life: &lt;em&gt;If you do something and you do it well, you will be asked to do it over and over.&lt;/em&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/2867971898667415006/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=28376608&amp;postID=2867971898667415006' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/2867971898667415006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/2867971898667415006'/><link rel='alternate' type='text/html' href='http://www.valuablecode.com/2008/11/simplicity-is-hard.html' title='Simplicity is Hard'/><author><name>Alistair McKinnell</name><uri>http://www.blogger.com/profile/16041326715656647934</uri><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28376608.post-762661870770509009</id><published>2008-09-19T21:44:00.000-07:00</published><updated>2008-09-20T10:43:29.296-07:00</updated><title type='text'>Focus Your Resume's Message</title><content type='html'>I don't think of my resume as a historical document that chronicles my career. My resume is a marketing device that describes my career from the point of view of the work that I want to have now and in the future.&lt;br /&gt;&lt;br /&gt;My blog is also a marketing device that should present a point of view that will help me to get the work that I want. My blog's marketing message should agree with my resume's marketing message.&lt;br /&gt;&lt;br /&gt;As a way of comparing my resume's and my blog's marketing message, I created a &lt;a href="http://wordle.net/"&gt;Wordle&lt;/a&gt; for my resume and a &lt;a href="http://wordle.net/"&gt;Wordle&lt;/a&gt; for my blog. To focus on the essential message I restricted each &lt;a href="http://wordle.net/"&gt;Wordle&lt;/a&gt; to 25 words.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;My Resume's Wordle&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.valuablecode.com/images/wordle_resume.png" alt="Resume Wordle" style="padding: 10px;" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;My Blog's Wordle&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.valuablecode.com/images/wordle_blog.png" alt="Blog Wordle" style="padding: 10px;" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;My Take Away&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Since I've compared the essential message of my resume to my blog, I'm thinking that my blog should present more posts about &lt;em&gt;design&lt;/em&gt; and &lt;em&gt;testing&lt;/em&gt;. I'm also thinking that my resume should relate my recent experience with &lt;em&gt;Java&lt;/em&gt; and &lt;em&gt;refactoring&lt;/em&gt; to &lt;em&gt;application development&lt;/em&gt; and &lt;em&gt;architecture&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;I find it interesting that &lt;em&gt;C++&lt;/em&gt; showed up for my resume while &lt;em&gt;Java&lt;/em&gt; showed up for my blog—perhaps it &lt;em&gt;is&lt;/em&gt; time to update my resume.</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/762661870770509009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=28376608&amp;postID=762661870770509009' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/762661870770509009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/762661870770509009'/><link rel='alternate' type='text/html' href='http://www.valuablecode.com/2008/09/focus-your-resumes-message.html' title='Focus Your Resume&apos;s Message'/><author><name>Alistair McKinnell</name><uri>http://www.blogger.com/profile/16041326715656647934</uri><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28376608.post-2097770056046796956</id><published>2008-01-28T03:36:00.000-08:00</published><updated>2008-01-28T05:30:30.955-08:00</updated><title type='text'>The Mysterious Case of the Missing BigDecimal Constructor</title><content type='html'>My current project has recently been experiencing runtime exceptions of the form:&lt;br /&gt;&lt;code&gt;&lt;pre&gt;&lt;br /&gt;NoSuchMethodError: java.math.BigDecimal.&amp;lt;init&amp;gt;(I)V&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;These exceptions only showed up when we started creating a codebase that mixes code written for Java 1.4 and code written for Java 1.5 (we wanted our design to use generics and annotations).&lt;br /&gt;&lt;br /&gt;Looking at the stack trace it was clear that the source of the runtime exception was construction of a &lt;code&gt;BigDecimal&lt;/code&gt; using an &lt;code&gt;int&lt;/code&gt; argument, for example, &lt;code&gt;new BigDecimal(5)&lt;/code&gt;. Looking over the Java API reveals that in Java 1.5 &lt;code&gt;BigDecimal&lt;/code&gt; has a &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html#constructor_summary"&gt;constructor&lt;/a&gt; that takes a &lt;code&gt;double&lt;/code&gt; or an &lt;code&gt;int&lt;/code&gt; argument while in Java 1.4 &lt;code&gt;BigDecimal&lt;/code&gt; has &lt;a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html#constructor_summary"&gt;no constructor&lt;/a&gt; that takes an &lt;code&gt;int&lt;/code&gt; argument.&lt;br /&gt;&lt;br /&gt;Working through all the permutations with a colleague we were able to create the runtime exception when we built our code using a Java 1.5 build path, compiling for Java 1.4, and running the code on a Java 1.4 JVM. It turned out that the key mistake was to use the Java 1.5 build path. This only happened on certain misconfigured developer machines. Once we reconfigured the developer machines the runtime exception was gone.&lt;br /&gt;&lt;br /&gt;Still, I was curious and I wanted to really understand the runtime exception. I installed the &lt;a href="http://andrei.gmxhome.de/bytecode/index.html"&gt;Bytecode Outline&lt;/a&gt; plugin for Eclipse so that I could see the bytecodes generated for &lt;code&gt;new BigDecimal(5)&lt;/code&gt;. You could also use the &lt;a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javap.html"&gt;javap&lt;/a&gt; command line tool. Below are the interesting fragments of bytecode.&lt;br /&gt;&lt;br /&gt;Build Path: 1.4.2&lt;br /&gt;&lt;code&gt;&lt;pre&gt;&lt;br /&gt;NEW java/math/BigDecimal&lt;br /&gt;DUP&lt;br /&gt;LDC 5.0&lt;br /&gt;INVOKESPECIAL java/math/BigDecimal.&amp;lt;init&amp;gt;(D)V&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Build Path: 1.5.0&lt;br /&gt;&lt;code&gt;&lt;pre&gt;&lt;br /&gt;NEW java/math/BigDecimal&lt;br /&gt;DUP&lt;br /&gt;ICONST_5&lt;br /&gt;INVOKESPECIAL java/math/BigDecimal.&amp;lt;init&amp;gt;(I)V&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;Now it is easy to see what is going on. When the build path is for Java 1.4 the compiler converts the &lt;code&gt;int&lt;/code&gt; literal &lt;code&gt;5&lt;/code&gt; to a &lt;code&gt;double&lt;/code&gt;. When the build path is for Java 1.5 the compiler generates a call to a constructor that takes an &lt;code&gt;int&lt;/code&gt; argument&amp;mdash;a method that does not exist in the 1.4 runtime libraries.&lt;br /&gt;&lt;br /&gt;Case closed.&lt;br /&gt;&lt;br /&gt;If you want to know the meaning of operands such as &lt;code&gt;DUP&lt;/code&gt; and &lt;code&gt;LDC&lt;/code&gt;, you can read &lt;a href="http://java.sun.com/docs/books/jvms/second_edition/html/Instructions.doc.html"&gt;Chapter 6&lt;/a&gt; of &lt;a href="http://java.sun.com/docs/books/jvms/"&gt;The Java Virtual Machine Specification&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/2097770056046796956/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=28376608&amp;postID=2097770056046796956' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/2097770056046796956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/2097770056046796956'/><link rel='alternate' type='text/html' href='http://www.valuablecode.com/2008/01/mysterious-case-of-missing-bigdecimal.html' title='The Mysterious Case of the Missing BigDecimal Constructor'/><author><name>Alistair McKinnell</name><uri>http://www.blogger.com/profile/16041326715656647934</uri><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28376608.post-7013732124076910937</id><published>2007-11-19T21:15:00.000-08:00</published><updated>2007-11-19T21:16:57.219-08:00</updated><title type='text'>How To End Incessant Arguing</title><content type='html'>I have a rule of thumb: when there is truly nothing at stake an argument can go on and on and on and on...&lt;br /&gt;&lt;br /&gt;There is a way out. Get everyone involved to recognize that there is nothing at stake and lead the group to make a choice. Or, take the lead and choose to give way (because you have recognized that there is truly nothing at stake.)&lt;br /&gt;&lt;br /&gt;When positions remain entrenched, work hard to surface the missing information because there may be something essential at stake.&lt;br /&gt;&lt;br /&gt;Try this example: what colour should we paint the garden shed?&lt;br /&gt;&lt;br /&gt;Black. Red. Blue. Yellow. Black. Red. White. Orange. Black...&lt;br /&gt;&lt;br /&gt;Suppose that you recognize that we will be using the shed mostly in the summertime. Now you can make the argument that the shed will get too hot if we paint it black. Instead we should use a lighter colour. Congratulations. You have surfaced new information. Now lead the group to make a choice between yellow and white.&lt;br /&gt;&lt;br /&gt;Whenever you find yourself arguing the same point over and over again, stop and be sure that there really is something at stake before you pitch in to keep the argument going.</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/7013732124076910937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=28376608&amp;postID=7013732124076910937' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/7013732124076910937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/7013732124076910937'/><link rel='alternate' type='text/html' href='http://www.valuablecode.com/2007/11/how-to-end-incessant-arguing.html' title='How To End Incessant Arguing'/><author><name>Alistair McKinnell</name><uri>http://www.blogger.com/profile/16041326715656647934</uri><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28376608.post-151985928680378707</id><published>2007-10-11T09:17:00.000-07:00</published><updated>2007-10-15T22:17:55.619-07:00</updated><title type='text'>Learn to Use a High-Level Filter</title><content type='html'>When you’re asked for a “high-level” plan do you panic? I don’t.&lt;br /&gt;&lt;br /&gt;Whenever I hear “high-level”, I apply a High-Level Filter: I simply replace “high-level” with “vague”. Let me give you some examples of how the filter works.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Filtering a High-Level Plan&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Imagine that you’re in a meeting with me, we’re drinking crappy office coffee, and someone sitting across the table says, “Let’s make a high-level plan.”&lt;br /&gt;&lt;br /&gt;You might think, “How the heck are we going to do that? There is only half an hour until lunch.”&lt;br /&gt;&lt;br /&gt;I apply a High-Level Filter and what I hear is, “Let’s make a vague plan.” We can certainly do &lt;span style="font-style: italic;"&gt;that&lt;/span&gt; before lunch.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Filtering High-Level Requirements&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Imagine that you and I are asked to provide high-level requirements for the next phase of a complex project and we have to be done by end of day tomorrow.&lt;br /&gt;&lt;br /&gt;You might panic and mutter, “Crap. More unpaid overtime.”&lt;br /&gt;&lt;br /&gt;I apply a High-Level Filter and smile knowing that we have been asked to provide vague requirements. We can certainly do &lt;span style="font-style: italic;"&gt;that&lt;/span&gt; by end of day tomorrow.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Use a High-Level Filter&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You will panic less often and work less overtime. More importantly, you will understand where people are coming from when they ask you for high-level plans or high-level requirements.</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/151985928680378707/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=28376608&amp;postID=151985928680378707' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/151985928680378707'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/151985928680378707'/><link rel='alternate' type='text/html' href='http://www.valuablecode.com/2007/10/learn-to-use-high-level-filter.html' title='Learn to Use a High-Level Filter'/><author><name>Alistair McKinnell</name><uri>http://www.blogger.com/profile/16041326715656647934</uri><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28376608.post-1097246936964373784</id><published>2007-07-05T21:49:00.000-07:00</published><updated>2007-07-05T22:19:27.370-07:00</updated><title type='text'>Refactoring in the Small</title><content type='html'>When I started writing programs I was given small problems to solve. I was learning by programming in the small. How could it be any other way? &lt;br /&gt;&lt;br /&gt;Programming in the large requires skills that you can’t learn from programming in the small. For example, there is no need for me to come up with an error handling strategy when I’m writing a command line utility implemented by one or two classes. But I don’t want to use any kind of framework that doesn’t have an error handling strategy.&lt;br /&gt;&lt;br /&gt;What I’ve noticed is that the skills that I learn while programming in the small are still valuable when programming in the large.&lt;br /&gt;&lt;br /&gt;Try something similar with refactoring. Begin by learning how to effortlessly refactor in the small. Learn how to create a &lt;a href="http://industriallogic.com/xp/refactoring/composeMethod.html"&gt;Composed Method&lt;/a&gt; by applying &lt;a href="http://www.refactoring.com/catalog/extractMethod.html"&gt;Extract Method&lt;/a&gt; a few times. If things go wrong, just apply &lt;a href="http://www.refactoring.com/catalog/inlineMethod.html"&gt;Inline Method&lt;/a&gt; and try an alternate breakdown. Maybe you need to apply &lt;a href="http://www.refactoring.com/catalog/encapsulateField.html"&gt;Encapsulate Field&lt;/a&gt;    prior to &lt;a href="http://www.refactoring.com/catalog/extractMethod.html"&gt;Extract Method&lt;/a&gt;. Perhaps your newly extracted method is not sufficiently general so go ahead&amp;mdash;apply &lt;a href="http://www.refactoring.com/catalog/parameterizeMethod.html"&gt;Parameterize Method&lt;/a&gt;. Nice.&lt;br /&gt;&lt;br /&gt;Learn the names of the &lt;a href="http://www.refactoring.com/catalog/index.html"&gt;refactorings&lt;/a&gt;. Use your programmer honed abstraction abilities. Start to think of a refactoring task as a sequence of refactorings rather than arbitrary text manipulation. The skills you learn while refactoring in the small are skills that you will need to refactor in the large. &lt;br /&gt;&lt;br /&gt;Suppose you need to restructure some complex procedural code, full of intertwined conditional logic, and plan to use object composition to manage variation. Are you thinking of the &lt;a href="http://en.wikipedia.org/wiki/Strategy_pattern"&gt;Strategy&lt;/a&gt; design pattern? Now you’re refactoring in the large. Thinking about the overall restructuring task dominates the refactorings. So you must learn to effortlessly apply refactorings or you’ll mess up your restructuring.&lt;br /&gt;&lt;br /&gt;So what is refactoring in the small? Is it making changes in only a single class? Nah&amp;mdash;too simplistic. What if the class is one of your central classes? What if it has that &lt;a href="http://en.wikipedia.org/wiki/Code_smell"&gt;Large Class&lt;/a&gt; smell? Besides, once you get good at it, a straightforward refactoring may affect many classes.&lt;br /&gt;&lt;br /&gt;For me, I’m refactoring in the small when the refactorings take place in a single programmer episode. If things go wrong it’s easy for me to back out. I can’t try anything too ambitious. Programming episodes are where I learn to apply refactorings.&lt;br /&gt;&lt;br /&gt;So c’mon folks. Start with baby steps. Practice. Learn. I want you to become a refactoring in the small &lt;a href="http://www.ninjai.com/"&gt;ninja&lt;/a&gt; before I catch any of you restructuring your code.</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/1097246936964373784/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=28376608&amp;postID=1097246936964373784' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/1097246936964373784'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/1097246936964373784'/><link rel='alternate' type='text/html' href='http://www.valuablecode.com/2007/07/refactoring-in-small.html' title='Refactoring in the Small'/><author><name>Alistair McKinnell</name><uri>http://www.blogger.com/profile/16041326715656647934</uri><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28376608.post-6436577087207920790</id><published>2007-06-13T05:00:00.000-07:00</published><updated>2007-06-13T16:26:54.563-07:00</updated><title type='text'>Why Do Teams Discourage Refactoring?</title><content type='html'>I’m frustrated by my inability to convince members of my team to learn and practice refactoring. I’m frustrated by how often I see refactoring actively discouraged.&lt;br /&gt;&lt;br /&gt;Martin Fowler defines a &lt;a href="http://www.martinfowler.com/bliki/RefactoringBoundary.html"&gt;refactoring &lt;/a&gt;as a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior. Refactoring as an activity means to restructure software by applying a series of refactorings without changing its observable behavior. Notice that Fowler distinguishes between the activities of &lt;a href="http://www.martinfowler.com/bliki/RefactoringMalapropism.html"&gt;refactoring and restructuring&lt;/a&gt;: refactoring is a very specific technique to perform the more general activity of restructuring.&lt;br /&gt;&lt;br /&gt;Michael Feathers defines &lt;a href="http://www.objectmentor.com/resources/articles/WorkingEffectivelyWithLegacyCode.pdf"&gt;legacy code&lt;/a&gt; as code without tests. If you work with such code you have to be very careful to avoid breaking working code whenever you change code. You might choose to adopt a rule of thumb like “whenever I make a change I will try to perturb the existing code as little as possible.” Anyone who has internalized this rule of thumb is going to be very wary of refactoring.&lt;br /&gt; &lt;br /&gt;As developers we are constantly under pressure to deliver features. You may knowingly choose to take shortcuts while imagining some future where you can go back and instead do things right. You might choose to adopt a rule of thumb like “I know what I’m doing isn’t quite right but given a chance to go back I would know how to make things right.” Anyone who has internalized this rule of thumb is going to view refactoring as a sanction to unleash their pent up desire to go back and restructure code to make things right.&lt;br /&gt;&lt;br /&gt;The combination of these two rules of thumb often produces a strange set of team behaviours. Developers are reluctant to refactor as they develop features. Instead they lobby their team for permission to explicitly refactor afterwards. By not refactoring at a smaller scale the team usually doesn’t have the experience nor the skills to perform refactoring as a sequence of small behavior-preserving changes. If those same developers are able to negotiate for explicit refactoring time, they often botch it up and now project leaders also become wary of refactoring.&lt;br /&gt;&lt;br /&gt;It doesn’t have to be this way.</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/6436577087207920790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=28376608&amp;postID=6436577087207920790' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/6436577087207920790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/6436577087207920790'/><link rel='alternate' type='text/html' href='http://www.valuablecode.com/2007/06/why-do-teams-discourage-refactoring.html' title='Why Do Teams Discourage Refactoring?'/><author><name>Alistair McKinnell</name><uri>http://www.blogger.com/profile/16041326715656647934</uri><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28376608.post-115693873332007863</id><published>2006-08-30T04:39:00.000-07:00</published><updated>2006-08-30T05:07:08.306-07:00</updated><title type='text'>Break Your Coding Habits</title><content type='html'>I'm re-reading &lt;em&gt;Mastery: The Keys to Success and Long-Term Fulfillment&lt;/em&gt; by George Leonard and I'm learning to love the plateau. If I were to chart my ability to create valuable code against time I would not see a gradually rising curve. Instead, the curve would be flat most of the time punctuated by occasional jumps to a higher level.&lt;br /&gt;&lt;br /&gt;For Leonard one of the 5 keys to mastery is &lt;em&gt;intentionality&lt;/em&gt;. I find it easy to slip into coding habits that keep me on the plateau. Whenever I create a new class I'm applying these habit-breaking rules:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;No implementation inheritance.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Do not use the &lt;code&gt;new&lt;/code&gt; keyword to create any objects.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;No getter and no setter methods.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;No &lt;code&gt;boolean&lt;/code&gt; arguments.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;Of course, it often makes sense to create classes that intentionally violate these rules. However, just for now, if you find yourself wanting to violate one of these rules: &lt;strong&gt;Stop. Are you violating the rule out of habit or do you have a good reason to violate the rule?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Code that follows these rules is more valuable than code that does not. I'll be explaining my reasons in subsequent postings.</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/115693873332007863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=28376608&amp;postID=115693873332007863' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/115693873332007863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/115693873332007863'/><link rel='alternate' type='text/html' href='http://www.valuablecode.com/2006/08/break-your-coding-habits.html' title='Break Your Coding Habits'/><author><name>Alistair McKinnell</name><uri>http://www.blogger.com/profile/16041326715656647934</uri><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28376608.post-115428252376975861</id><published>2006-07-30T10:59:00.000-07:00</published><updated>2007-06-13T16:18:28.479-07:00</updated><title type='text'>What Is It About Code That Makes It Valuable?</title><content type='html'>I believe that code is valuable when it &lt;em&gt;works&lt;/em&gt; and it can be &lt;em&gt;changed&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;I find this way of thinking to be useful in two ways: (1) it reflects my latest understanding of what it means to be valuable code and (2) it helps me to coach people to create valuable code.&lt;br /&gt;&lt;br /&gt;When I first started writing code all that mattered to me was that the code worked. I started coding in high school using &lt;a src="http://en.wikipedia.org/wiki/Mark_sense"&gt;mark sense cards&lt;/a&gt;. They were like &lt;a src="http://en.wikipedia.org/wiki/Punch_cards"&gt;punch cards&lt;/a&gt; but you could use a pencil to mark the cards with your program rather than using a card punch machine. At the end of every day a long cardboard box of cards was transported from my high school to the Ottawa School Board's mainframe. Some three or four days later, the box of cards would reappear along with any printouts. As turn around time for fixing a syntax error was three or four days, I learnt to always be very careful to check my code for syntax errors &lt;em&gt;before&lt;/em&gt; submitting to the mainframe.&lt;br /&gt;&lt;br /&gt;Even so, I would still make syntax errors. Once I had fixed the syntax errors and my program would compile and run, I usually found that I had made both goofy and subtle logic errors. Since each run of the program was so valuable, I included lots of print statements to instrument the dynamic behaviour of my simple programs. Eventually I would get my program to work. Once my program was working there was no reason to change it. I would strip out all my diagnostic print statements and hand in my program listings for marking confident that I wouldn't have to ever change the code.&lt;br /&gt;&lt;br /&gt;I think that when most people start to write code their overwhelming goal is to &lt;em&gt;make their code work&lt;/em&gt;. My early experiences with coding affected my attitudes towards code in that once my code worked I was done with it. Now when I coach people about coding my most hated response to my hints is "sure, but why do anything since the code works." As long as I cannot convince programmers that &lt;em&gt;it works&lt;/em&gt; is a necessary but not sufficient condition for valuable code I'm finding that I'm not making very good progress with my coaching.&lt;br /&gt;&lt;br /&gt;Once I add "and it can be &lt;em&gt;changed&lt;/em&gt;" on to the end of my definition of valuable code I have some leverage against programmer indifference. I can say "you're right it does work but is it easy to change?"</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/115428252376975861/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=28376608&amp;postID=115428252376975861' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/115428252376975861'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28376608/posts/default/115428252376975861'/><link rel='alternate' type='text/html' href='http://www.valuablecode.com/2006/07/what-is-it-about-code-that-makes-it.html' title='What Is It About Code That Makes It Valuable?'/><author><name>Alistair McKinnell</name><uri>http://www.blogger.com/profile/16041326715656647934</uri><email>noreply@blogger.com</email></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>