<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
    <title>Bonny Code</title>
    
    
    <link rel="alternate" type="text/html" href="http://www.bonnycode.com/guide/" />
    <id>tag:typepad.com,2003:weblog-1590434</id>
    <updated>2009-04-12T22:51:32-07:00</updated>
    <subtitle>Software best practices guide for professional software developers.</subtitle>
    <generator uri="http://www.typepad.com/">TypePad</generator>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/typepad/bonny_code" /><feedburner:info uri="typepad/bonny_code" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://hubbub.api.typepad.com/" /><entry>
        <title>Just Say 'No' To Boring Code</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/typepad/bonny_code/~3/ZE_MC83uJLQ/just-say-no-to-boring-code.html" />
        <link rel="replies" type="text/html" href="http://www.bonnycode.com/guide/2009/04/just-say-no-to-boring-code.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-65391893</id>
        <published>2009-04-12T22:51:32-07:00</published>
        <updated>2009-04-12T22:51:32-07:00</updated>
        <summary>Thanks to Casey for inspiring this entry and for fighting the good fight against boring code. I have extreme feelings of dissatisfaction with boring code. Boring code is monotonous and has a low signal to noise ratio. It takes a...</summary>
        <author>
            <name>Lucas Pierce</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Web/Tech" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://www.bonnycode.com/guide/">
<div xmlns="http://www.w3.org/1999/xhtml"><p><em>Thanks to <a href="http://www.cs.uchicago.edu/people/clklein">Casey</a> for inspiring this entry and for fighting the good fight against boring code.</em></p><p>I have extreme feelings of dissatisfaction with boring code. Boring code is monotonous and has a low signal to noise ratio. It takes a long time to communicate anything of value in boring code because most lines are dedicated to boilerplate. For example, according to a recent statistic I just made up, 95% of Java code consists of the following:</p><div style="margin-left: 40px;">int getBlah() {<br />   return blah;<br />}<br /><br />void setBlah(int blah) {<br />   this.blah = blah;<br />}<br /><br />String getSoBored() {<br />   return soBored;<br />}<br /><br />void setSoBored(String soBored) {<br />  this.soBored = soBored;<br />}<br /></div><p><br />In Ruby, this looks like:</p><div style="margin-left: 40px;">attr_accessor :blah, :soBored<br /></div><p><br />If you are using Java, a certain amount of this type of verbose code is just necessary. The far more insidious problem is that it trains developers into believing this type of pattern is a good thing. The best thing about Ruby and the functional programming communities is that the first point emphasized is that code should be concise and full of meat and if it isn't you aren't thinking hard enough. For instance, the Hello World program in Ruby:</p><div style="margin-left: 40px;">puts "Hello, World!"<br /></div><p><br />Straight to the point. In Java, you are already entering the world of boilerplate thinking (from http://java.sun.com/docs/books/tutorial/getStarted/application/index.html):</p><div style="margin-left: 40px;">/** <br /> * The HelloWorldApp class implements an application that<br /> * simply displays "Hello World!" to the standard output.<br /> */<br />class HelloWorldApp {<br />    public static void main(String[] args) {<br />        System.out.println("Hello World!"); //Display the string.<br />    }<br />}<br /></div><p><br />My knock here is not actually that Ruby or functional languages magically eliminate all boilerplate code, or that this extra overhead in these cases is really that painful. You can easily use a code generator for both of these situations and if this is the only boilerplate in your code you are doing pretty good. The problem is the Java community teaches its developers that all of their code should be at about this level of signal to noise.</p><p>This is not an argument about aesthetics. Boring code is bad for precisely three reasons:</p><ol>
<li>Boring code is boring to read. Code is read far more than it is written. This means programmers coming in to modify your code are more likely to miss something and then make the wrong code change.</li>
<li>Boring code is boring to review. A critical quality insurance practice in professional software development is code reviews. But boring code is boring to review. If you write boring code, it is far more likely the reviewer will just go 'yadda yadda yadda looks good to me' and gloss over mistakes.</li>
<li>Boring code is boring. Come on, do you really want to be boring?</li>
</ol>
<p>The only thing worse than boring code is <a href="http://www.bonnycode.com/guide/2008/11/in-defense-of-duplicated-code.html">magic code</a>. Stick to the exciting, elegant, simple code, believe me you'll sleep better at night if you do.</p></div>
</content>



    <feedburner:origLink>http://www.bonnycode.com/guide/2009/04/just-say-no-to-boring-code.html</feedburner:origLink></entry>
    <entry>
        <title>Software is not like Dirt</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/typepad/bonny_code/~3/h_9yZeEArTo/software-is-not-like-dirt.html" />
        <link rel="replies" type="text/html" href="http://www.bonnycode.com/guide/2009/03/software-is-not-like-dirt.html" thr:count="1" thr:updated="2009-03-04T12:44:46-08:00" />
        <id>tag:typepad.com,2003:post-63520487</id>
        <published>2009-03-01T22:37:49-08:00</published>
        <updated>2009-03-01T22:37:49-08:00</updated>
        <summary>Metaphors are way too overused when people talk about software development. The process of creating software has been compared to building a house, planning a city, growing a garden and creating new life (think Dr. Frankenstein, not boom chiki wow...</summary>
        <author>
            <name>Lucas Pierce</name>
        </author>
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://www.bonnycode.com/guide/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>Metaphors are way too overused when people talk about software development. The process of creating software has been compared to building a house, planning a city, growing a garden and creating new life (think Dr. Frankenstein, not boom chiki wow wow). Software can look like spaghetti (yum!) or it can be as elegant as Audrey Hepburn in My Fair Lady. I promise not to add to this mess anymore than I already have with<a href="http://www.bonnycode.com/guide/2008/11/in-defense-of-duplicated-code.html"> good King DRY</a> by throwing more metaphors in the mix.</p><p>Instead, I wish to cast away the most evil of metaphors: that software is like dirt and that software is like trying to make the biggest pile of dirt you possibly can. Now I can tell you as someone who has experience both in software development and who has created big piles of dirt on beaches, in backyards and in wooded areas that they are nothing alike.</p><p>The first difference is you can easily estimate with some precision how long it will take to make your pile of dirt. Imagine having 10 years experience making piles of dirt and you still have some dirt piling projects that you misestimate by a factor of 2. It just doesn't happen. Or imagine you are managing a team of dirt pilers and it looks like they are 90% done piling their dirt but then it turns out they are only half done. Or even worse, in your team of dirt pilers, there is this one guy that is unknowingly working against the rest of the team and accidently putting the dirt back in the hole without even knowing it. Or the more people you put piling up the dirt, the slower and slower everyone seems to go. These things don't happen when making piles of dirt, but they all happen when making software.</p><p>The second difference is that when you make a pile of dirt you have a clear understanding of your goal as you work, but when making software the entire process is about understanding what you are trying to build. I make piles of dirt mostly because it is fun, that is my goal. With software though, you only understand what you are trying to build when you have finished building it. When I make a pile of dirt I come up with a plan, I will take either a shovel, a spoon, or my hands and start digging out dirt and put it in a pile. If dirt were like software, the ground would be magically turning into marshmallows, dingoes and molten lava every time the shovel hit the ground, requiring you to come up with new plans of attack at every step.</p><p>Creating software isn't like piling dirt. It isn't like building a house, a bridge, a baby or any other physical thing. And that is because there is no construction phase to software development. All of software development is design. That is the fundamental problem with all of these metaphors and why they can lead to the wrong conclusions.</p></div>
</content>



    <feedburner:origLink>http://www.bonnycode.com/guide/2009/03/software-is-not-like-dirt.html</feedburner:origLink></entry>
    <entry>
        <title>A Timeless Way of Coding</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/typepad/bonny_code/~3/PeA9MbmyY5o/a-timeless-way-of-coding.html" />
        <link rel="replies" type="text/html" href="http://www.bonnycode.com/guide/2009/02/a-timeless-way-of-coding.html" thr:count="2" thr:updated="2009-02-28T23:48:07-08:00" />
        <id>tag:typepad.com,2003:post-63215839</id>
        <published>2009-02-22T22:51:50-08:00</published>
        <updated>2009-02-22T22:51:50-08:00</updated>
        <summary>What do the Macarena and the GoF's Design Patterns have in common? They all became wildly popular in 1995 but in the following years experienced a large backlash from overexposure. There have been many arguments against Design Patterns as practiced...</summary>
        <author>
            <name>Lucas Pierce</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Web/Tech" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://www.bonnycode.com/guide/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>What do the Macarena and the GoF's <a href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/">Design Patterns</a> have in common? They all became wildly popular in 1995 but in the following years experienced a large backlash from overexposure. There have been many arguments against Design Patterns as practiced in software development, chiefly that they promote over complicated code and that they really just paper over what should be seen as core deficiencies in mainstream object oriented languages.</p><p>The original inspiration for the design patterns movement in software was Christopher Alexander's <a href="http://www.amazon.com/Timeless-Way-Building-Christopher-Alexander/dp/0195024028/">The Timeless Way of Building</a>. Somewhere from Christopher Alexander's original text to the software industries adoption of design patterns, the very soul of his meaning was left behind. Envision for a moment the stereotype of a hard core believer in software design patterns. Their code is designed all up front using UML and every class is named after one design pattern or another. Often times even multiple of them, such as the FooBarStrategyAbstractFactorySingleton. They create big inorganic design, suitable to distinct job roles where one can be an architect that doesn't design, a designer who doesn't code and a coder who does as they are told.</p><p>The spirit of the timeless way of building is to evoke that quality without a name. Some buildings are just lifeless, cold and somehow wrong. Others have a cozy liveliness that just feels comfortable and right. To obtain the quality without a name, one has to look at how such designs organically arose and the micro principles and patterns they applied. The centrally planned cities, strip malls and cookie cutter suburban homes all lack this organically grown life.</p><p>This is the central problem with how design patterns are applied. They are used to dictate design as if it is something that can be rigorously planned rather than something that is adapted to. This is why so much enterprise code feels so bloated and lifeless, it lacks the natural flow and elegance of code that is designed to fit a specific problem rather than trying to fit into a wholly consistent uber architecture.</p><p>How does a developer achieve that quality without a name though? No one intends to write bad lifeless code and please don't tell me this is just a problem for <a href="http://www.bonnycode.com/guide/2008/12/the-bad-programmer.html">bad programmers</a>. I'd like to know what people think. Have you ever written code that was great and had that quality without a name, not only at initial conception, but actually got better and more elegant over time? How did you do it? What about code that you thought was great at first, but quickly showed its age as the requirements shifted? What went wrong?</p></div>
</content>



    <feedburner:origLink>http://www.bonnycode.com/guide/2009/02/a-timeless-way-of-coding.html</feedburner:origLink></entry>
    <entry>
        <title>Building Software Over Time</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/typepad/bonny_code/~3/GfcKTK-PAb0/building-software-over-time.html" />
        <link rel="replies" type="text/html" href="http://www.bonnycode.com/guide/2009/02/building-software-over-time.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-62577395</id>
        <published>2009-02-09T00:36:46-08:00</published>
        <updated>2009-02-09T00:36:46-08:00</updated>
        <summary>When choosing a sorting algorithm, we typically don't look at how fast it performs on collections of 10 items. What matters is how it scales with the size of the input data. It is very easy to get sidetracked by...</summary>
        <author>
            <name>Lucas Pierce</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Web/Tech" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://www.bonnycode.com/guide/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>When choosing a sorting algorithm, we typically don't look at how fast it performs on collections of 10 items. What matters is how it scales with the size of the input data. It is very easy to get sidetracked by success on toy problems or to concentrate on optimizing the wrong thing. Sure you can spend days optimizing the inner loop of your sort, but if you're using an n squared algorithm you're not using your time efficiently.</p><p>The same lessons apply in software design. Programmers most often optimize around initial construction time. If you have a fixed set of requirements for the lifetime of the software than that is indeed a suitable area to optimize and in that case you are probably working for a government contractor of some sort. For the rest of us, you are almost certainly working in an area with changing requirements and code that will be read and reworked many times through its life. Much more time will be spent on the maintenance side, an often cited number is greater than 90% of time is spent on maintenance. People's first response to this is that it is a code quality issue, but that is largely untrue from my experience. The reason maintenance absorbs so much time is that requirements are constantly in flux. The code must be changed to meet new demands as those demands stream in.</p><p>Sounds good so far, so this means build in lots of flexibility to your code right? Not quite as most software developers are amazingly bad at predicting where they will need the flexibility. Some use their own creative imaginations to dream up ways in which new requirements may come in, this leads to the really horribly bad architectures. The more experienced developers draw from previous experience from previous projects which is sometimes useful, more often misleading. This leads to the principle the agilistas refer to as YAGNI aka you aren't gonna need it. Basically they revoke your flexible architecture card on the premise that you are going to screw it up.</p><p>YAGNI is a good principle, better than the overbuilding it seeks to prevent, but it ultimately comes from too detached a place. Don't get me wrong, for most developers out there, following YAGNI will lead to better code and better design. Most developers are over confident in themselves and their knowledge of what their software is used for, and spend very little time thinking about why they are building their software. The place where YAGNI falls short of nirvana though is that it presumes the software developer as contractor, which means the software developer is fed requirements from some unknown source which are then turned into code. Much better is software developer as active requirements gatherer and problem solver. The mindset has to change away from "God knows what the requirements will be next" to "What is the trajectory for this software and how can I provide the most value over time." Is there value in you building something now vs. later? What is the opportunity cost to building it later? What is the risk of it changing? Is the best way to get more information to just build what we know so far and get further feedback? These are the questions that need to be asked and that you need to have deep requirements knowledge to answer. This is where as a developer you will provide real value to a business though, and where a single developer close to the business can easily outperform a fleet of programmers in some far off place.</p><p>Software design is about scalability. It is an organic process where you must constantly ask yourself not what something will cost at this point in time, but what will the cost vs. value be over time through the long, long, long lifetime of the software. Software developers are bad at this and so many just give up and resort to YAGNI like principles, but ultimately this is because software developers are too detached from the requirements and are poorly trained in risk management.</p></div>
</content>



    <feedburner:origLink>http://www.bonnycode.com/guide/2009/02/building-software-over-time.html</feedburner:origLink></entry>
    <entry>
        <title>The Bad Programmer</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/typepad/bonny_code/~3/s2zHx8s7O-w/the-bad-programmer.html" />
        <link rel="replies" type="text/html" href="http://www.bonnycode.com/guide/2008/12/the-bad-programmer.html" thr:count="1" thr:updated="2008-12-22T16:36:40-08:00" />
        <id>tag:typepad.com,2003:post-59989034</id>
        <published>2008-12-13T21:25:04-08:00</published>
        <updated>2008-12-13T21:25:04-08:00</updated>
        <summary>Nick makes a good argument for why go to should not be used. His closing argument is that zealous programmers will abuse go to. Pete makes a similar argument that go to has too much potential for abuse from programmers...</summary>
        <author>
            <name>Lucas Pierce</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Web/Tech" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://www.bonnycode.com/guide/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>Nick makes a <a href="http://www.bonnycode.com/guide/2008/12/in-defense-of-go-to.html#comment-142318906">good argument</a> for why go to should not be used. His closing argument is that zealous programmers will abuse go to. Pete makes a similar argument that go to has too much potential for abuse from programmers that we can't be bothered to explain the use of to and you are better off banning them.</p><p>It is a similar argument people make when arguing for gun restrictions. As the politicians will tell you, "Sure we trust you with a gun, but do you trust your neighbor or the guys from across town with them?"</p><p>The difference though is that you have a lot of choice over who you work with. If you are limiting your choice of language or features based on the fact that you work with bad programmers I think you are trading off against the wrong factor. Do you want to work with bad programmers? Removing dangerous features from a language will certainly remove possibilities from bad programmers shooting themselves in the foot. They still won't be good programmers though.</p><p>How many bad programmers will you even work with? Companies tend to have fairly regular hiring standards, at least at any departmental level and in my experience good programmers tend to work in the same place and bad programmers equally congregate. Indeed, in <a href="http://www.amazon.com/Peopleware-Productive-Projects-Teams-Second/dp/0932633439/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1229231876&amp;sr=1-1">PeopleWare</a> they demonstrated a strong correlation between programming ability and the layout of the office where they worked. If there is a strong correlation between office layout and ability then programmers in the same office will have a strong correlation in programming ability amongst themselves.</p><p>The boogeyman of bad programmers is a false threat to individual programmers. You are very likely only working with bad programmers if you are a bad programmer yourself. As a good programmer working with other good programmers, is go to still a bad idea?</p></div>
</content>



    <feedburner:origLink>http://www.bonnycode.com/guide/2008/12/the-bad-programmer.html</feedburner:origLink></entry>
    <entry>
        <title>In Defense of Go To</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/typepad/bonny_code/~3/Fr_b4e_Vv48/in-defense-of-go-to.html" />
        <link rel="replies" type="text/html" href="http://www.bonnycode.com/guide/2008/12/in-defense-of-go-to.html" thr:count="7" thr:updated="2009-02-04T00:16:54-08:00" />
        <id>tag:typepad.com,2003:post-59632366</id>
        <published>2008-12-07T13:36:48-08:00</published>
        <updated>2008-12-07T13:36:48-08:00</updated>
        <summary>I continue this entry from my defense of duplicated code. If programmers were politicians, writing an article like this would surely prevent me from ever running for Programmer President. Twenty years from now someone would dig it up and say...</summary>
        <author>
            <name>Lucas Pierce</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Web/Tech" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://www.bonnycode.com/guide/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>I continue this entry from my <a href="http://www.bonnycode.com/guide/2008/11/in-defense-of-duplicated-code.html">defense of duplicated code</a>. If programmers were politicians, writing an article like this would surely prevent me from ever running for Programmer President. Twenty years from now someone would dig it up and say "Lucas Pierce supports the use of go to! Heresy!".</p><p>That said, let's say we have been contracted to write a program to generate Fibonacci numbers. Believe me, Fibonacci generators are a hot commodity these days so this is a totally realistic example. In this case you run the program and then type in a number (n) and it gives the first n Fibonacci numbers and then exits.</p><p>main<br />  integer n = console.getInt()<br />  integer first = 0<br />  integer second = 1<br />  integer next</p><p>  fib_loop:<br />    print first<br />    next = first + second<br />    first = second<br />    second = next<br />    n = n - 1<br />  if (n &gt; 0) goto fib_loop<br />end</p><p>&lt;sarcasm_tags_for_the_clueless&gt;Egads! That program is totally obtuse! Here let me write a version without <strong>go to</strong> so that it makes more sense&lt;/sarcasm_tags_for_the_clueless&gt;:</p><p>main<br />  integer n = console.getInt()<br />  integer first = 0<br />  integer second = 1<br />  integer next</p><p>  do<br />    print first<br />    next = first + second<br />    first = second<br />    second = next<br />    n = n - 1<br />  while (n &gt; 0)<br />end</p><p>Now it makes sense! Although we could use a for loop to make it even better:</p><p>main<br />  integer first = 0<br />  integer second = 1<br />  integer next</p><p>  for (integer n = console.getInt(); n &gt; 0; n = n - 1)<br />    print first<br />    next = first + second<br />    first = second<br />    second = next<br />  end<br />end</p><p>Why is this version so much better than the <a href="http://xkcd.com/292/">go to</a> version though? We've all been taught <strong>go to</strong> is evil but I find all three equally readable. This is me throwing down the gauntlet, I challenge you to tell me why <strong>go to</strong> is wrong. </p></div>
</content>



    <feedburner:origLink>http://www.bonnycode.com/guide/2008/12/in-defense-of-go-to.html</feedburner:origLink></entry>
    <entry>
        <title>In Defense of Duplicated Code</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/typepad/bonny_code/~3/grFM6ex8EjY/in-defense-of-duplicated-code.html" />
        <link rel="replies" type="text/html" href="http://www.bonnycode.com/guide/2008/11/in-defense-of-duplicated-code.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-59280224</id>
        <published>2008-11-30T22:08:07-08:00</published>
        <updated>2008-11-30T22:08:07-08:00</updated>
        <summary>One of the first principles you will hear from anyone hoping to impart software development wisdom on young disciples is DRY. Don't Repeat Yourself. If software best practices all lived in a little nation, the Honourable Commonwealth of Softwaria, its...</summary>
        <author>
            <name>Lucas Pierce</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Web/Tech" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://www.bonnycode.com/guide/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>One of the first principles you will hear from anyone hoping to impart software development wisdom on young disciples is <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a>. Don't Repeat Yourself. If software best practices all lived in a little nation, the Honourable Commonwealth of Softwaria, its king would be DRY. A good king he was too.</p><p>Since ages long since past, DRY has helped to keep javascripters from copy and pasting themselves into another rathole. At first, King DRY used methods to remove duplicate code. Formatting integers to currency a bajillion different places? No problem make a method to do the formating. The code is better because it is more readable (formatAsCurrency) and if you ever need to change or extend the logic you can do so in one place. Huzzah!</p><p>Over the years, DRY took on further battles for the people of Softwaria. In the Thirty Year War against Visual Basic programmers, DRY brought forth the mighty powers of <a href="http://en.wikipedia.org/wiki/Object_composition">composition</a>. Now large segments of functionality and data, not just individual methods, could be transported and duplicated to be used anywhere. A method to format an integer into currency? How about a currency class instead that can not only format itself to a string but also do any other logic you want to on currency all bundled nicely in a little package. Besides removing duplicate code, composition also provided encapsulation, higher cohesion and lowered coupling (the bad kind not the good kind!).</p><p>As Lord Action once said though, power tends to corrupt, and absolute power corrupts absolutely. For in his zealous fervor to ban any duplicate code or logic he was tempted into delving into powerful and dark arts. DRY called upon his most powerful sorcerers who gave him the power of <a href="http://www.bonnycode.com/guide/2008/09/banned-implementation-inheritance.html">implementation inheritance</a>. Yes he did eke out yet more removal of duplicated code. But in the process he sacrificed most of the benefits that encapsulation had provided.</p><p>Yet more dissidents were found in the kingdom of Softwaria though and DRY delved into yet darker arts to combat them. This time he tapped into the power of <a href="http://en.wikipedia.org/wiki/Reflection_%28computer_science%29">reflection</a>. With this power he could make mountains move (even if they were declared private!). Giddy with power, the king annihilated the duplicated code. Yes he had to sacrifice readability, but it seemed a small price to pay to eliminate those treasonous and heretical duplicate code bastards.</p><p>Finally, in the dark recesses of the kingdom, DRY found the last remaining resistance movements of duplicated code. They didn't bother people much, they were largely just simple workers tilling away at their small plot of program. By this time the good king had become fanatical though. ALL DUPLICATED CODE MUST DIE! He called on his sorcerers one final time and asked for the power to remove the remaining resistance. He offered anything in his kingdom just for this one final grant of power. And the sorcerers delivered for they offered the power of <a href="http://en.wikipedia.org/wiki/Metaprogramming">metaprogramming</a>. Now the King was no longer bound by the traditional physics of the land, instead he could reshape it in whatever likeness he desired. In the land of Java the king created code generators that created wide areas of forbidden code, code never to be touched or even looked at. XML spread like a disease, soon used to store the most important program logic. In the land of Ruby, programs created other programs and whole new languages sprang forth from nowhere to solve the most trivial of problems. Ruby on Rails came riding high with <a href="http://www.rubyonrails.org/screencasts">instant magical scaffolds</a>. And the last of the duplicated code died...</p><p>The king was satisfied with himself for he had finally fulfilled his ultimate goal. Old King DRY stepped out to view his wondrous kingdom and no longer recognized what he saw. It was incomprehensible. Nothing made sense anymore, nothing was predictable and nothing worked as it seemed. Nobody, not even King DRY who created this world, understood it anymore. The sorcerers laughed knowing the land was now ruled by magic and the good king wept.</p></div>
</content>



    <feedburner:origLink>http://www.bonnycode.com/guide/2008/11/in-defense-of-duplicated-code.html</feedburner:origLink></entry>
    <entry>
        <title>Persistence: The long lost virtue of fixing a bug</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/typepad/bonny_code/~3/BLdApSA5glY/persistence-the-long-lost-virtue-of-fixing-a-bug.html" />
        <link rel="replies" type="text/html" href="http://www.bonnycode.com/guide/2008/11/persistence-the-long-lost-virtue-of-fixing-a-bug.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-58954322</id>
        <published>2008-11-23T18:12:12-08:00</published>
        <updated>2008-11-23T18:12:12-08:00</updated>
        <summary>The heights by great men reached and kept Were not attained by sudden flight, But they, while their companions slept, Were toiling upward in the night. -- Henry Wadsworth Longfellow You're working on a difficult bug. A strange log message...</summary>
        <author>
            <name>Lucas Pierce</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Web/Tech" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://www.bonnycode.com/guide/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>The heights by great men reached and kept<br />Were not attained by sudden flight, <br />But they, while their companions slept, <br />Were toiling upward in the night.<br /><em>-- Henry Wadsworth Longfellow</em></p><p>You're working on a difficult bug. A strange log message showing that your program fails every once in a while. Looking at your watch you see you've already been working on it for half an hour. You put the bug back on the router thinking to yourself maybe someone else will have better luck. And then a man from the future appears behind you... oh never mind I won't subject you to that torture <a href="http://www.bonnycode.com/guide/2008/11/do-not-fix-what-you-dont-understand.html">again</a>.</p><p><a href="http://www.bonnycode.com/.a/6a00e55074bd3e88330105361baf1b970c-pi" style="display: inline;"><img alt="Developer_bug_conversation" border="0" class="at-xid-6a00e55074bd3e88330105361baf1b970c image-full " src="http://www.bonnycode.com/.a/6a00e55074bd3e88330105361baf1b970c-800wi" title="Developer_bug_conversation" /></a>
 </p><p>If you are like most software developers you've been in the situation above. Maybe instead you mark the bug as "Cannot Reproduce" or you instead assign it to your resident expert. Regardless of the means you use to escape from fixing the bug, you are dodging an important opportunity. This is normally when I start hearing the excuses. The bug is too hard. Someone else could fix it sooo much faster. There are too many bugs to waste time on just one. Forget the excuses, it is worth it both to you and the product you are creating. Oh let me count the ways.</p><ol>
<li>You are actually learning something deep about the technology you work with. Sure the first time you are learning something you are slow. Really slow. But you are learning. You are dissecting the technology and learning how it really works. In the future with this deep knowledge you will be able to quickly solve problems. You are increasing your skill set as a developer which is good for the company you work for now and for your future marketability later. See Figure 1 below.</li>
<li>You are wasting the time you spent getting up to speed on the problem. You pick up the bug, spend 30 minutes and then put it back on the router. The next person picks it up, spends 30 minutes and then puts it back on the router. yadda yadda. This is a huge waste of everyone's time. The same if you mark it as cannot reproduce, but instead you are wasting the time of the customer or testers and then more developers later when they bring up the bug again in a new form.</li>
<li>Not only is the bug noise on the router, it is also noise in the logs (hopefully you do have some means of tracking errors from your system). It is a common tradition in too many software shops to have their set of ignorable errors that just seem to happen and nobody really knows why but they seem fairly harmless so nobody fixes them. Not to say people didn't try, I'm sure at least 5 people spent their 30 minutes on trying to fix it. Noise in the logs is not a good thing though. It could actually be a problem that will only manifest itself at an inopportune time. Even if it is genuinely harmless, it is still one more thing for humans to mentally parse and ignore and distracts away from seeing the real bugs.</li>
</ol>
<p><a href="http://www.bonnycode.com/.a/6a00e55074bd3e88330105361bafc5970c-pi" style="display: inline;"><img alt="Figure1" border="0" class="at-xid-6a00e55074bd3e88330105361bafc5970c " src="http://www.bonnycode.com/.a/6a00e55074bd3e88330105361bafc5970c-800wi" title="Figure1" /></a>
 <br />At this point you maybe be telling yourself "Great I'm going to fix all the bugs". Look a null pointer exception, all I need is a little if statement null check and I'm good. </p><p><strong>Hold On!</strong></p><p>Resist the urge to cut off the investigation early. Fixing the symptoms of a bug is NOT fixing the bug. Why is that variable null? Is it supposed to be nullable even? You must find the root cause even if it takes you 10 or 20 times longer. Treat the bug as if it was a memory corruption bug. You can try treating each of the various symptoms of the memory corruption and varied they will be. Or you can hit that one spot where it is actually occurring and fix it for good.</p><p>The trade off is really this, you can either spend 2 days going deep, really understanding how something works and understanding the core of the issue, or you can spend the next month making tiny one off fixes that treat just the symptoms. In the end sticking with it and finding the real problem is 95% of the time more cost effective than just treating the symptoms. And speaking from experience, it is much more gratifying as well. Figure 2 shows a comparison between fixing the root cause and just fixing the first symptom you can patch over.<br /><a href="http://www.bonnycode.com/.a/6a00e55074bd3e883301053613ae03970b-pi" style="display: inline;"><img alt="Figure2" border="0" class="at-xid-6a00e55074bd3e883301053613ae03970b image-full " src="http://www.bonnycode.com/.a/6a00e55074bd3e883301053613ae03970b-800wi" title="Figure2" /></a>
 </p><p>Persistence does not equal stupidity. Banging your head against a problem and making no progress is not persistence anymore than running on a treadmill is a form of transportation. Well... <a href="http://www.heavy.com/video/61095" target="_blank">not normally at least</a>. I see lack of persistence as the biggest thing that holds people back, but many people don't even know how to go about fixing the hard problems. It is a skill and I could go on about divide and conquer, how to actually use google and a million other tidbits. As an honest to goodness skill though, my best advice is to pair up with the best, most knowledgeable bug fixer you know. Who is the developer that ends up actually fixing the really hard problems when they come up? Tackle a really hard problem with them. When you get stuck on a really hard bug, don't give up, but do ask for advice explaining your progress so far. Don't ask them to do the work for you, but do ask for pointers on where to look next. Often times you'll find the act of just explaining what you've discovered will lead you to the solution on your own.</p><p>Remember this. Any script kiddie can copy and paste some code, tweak some values and get a system they barely understand to kinda work. If you want to distinguish yourself as a software developer, work to truly understand the system you are building, don't shy away from the difficult problems and don't stop until you really know what is going on.</p></div>
</content>



    <feedburner:origLink>http://www.bonnycode.com/guide/2008/11/persistence-the-long-lost-virtue-of-fixing-a-bug.html</feedburner:origLink></entry>
    <entry>
        <title>Do not fix what you don't understand</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/typepad/bonny_code/~3/mLqQtsAS8PI/do-not-fix-what-you-dont-understand.html" />
        <link rel="replies" type="text/html" href="http://www.bonnycode.com/guide/2008/11/do-not-fix-what-you-dont-understand.html" thr:count="2" thr:updated="2008-11-24T22:52:29-08:00" />
        <id>tag:typepad.com,2003:post-58596812</id>
        <published>2008-11-16T23:31:44-08:00</published>
        <updated>2008-11-16T23:31:44-08:00</updated>
        <summary>It's monday at 2pm and you are working on another bug report. It is a null pointer exception in a class you aren't familiar with. class Nose ... void upYourNoseWithARubberHose(RubberHose hose) { if (hose.diameter() &lt; 1 inch) noseHose = hose;...</summary>
        <author>
            <name>Lucas Pierce</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Web/Tech" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://www.bonnycode.com/guide/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>It's monday at 2pm and you are working on another bug report. It is a null pointer exception in a class you aren't familiar with.</p><p>class Nose<br />...<br />void upYourNoseWithARubberHose(RubberHose hose) {<br />   if (hose.diameter() &lt; 1 inch)<br />      noseHose = hose;<br />   else<br />      throw HoseTooBigForNoseException();<br />}<br />....<br />}</p><p>*yawn*</p><p>hose is null and a null pointer exception is thrown when accessing its diameter. At least this is an easy fix you think to yourself.</p><p>if (hose == null || hose.diameter() &lt; 1 inch)</p><p>Awesome... bug fixed... just need to commit. "Fixed NPE in upYourNoseWithARubberHose" you type into the comment box.</p><p>Just before clicking the commit button a whooshing sound comes from behind you. Whirling around you see a huge man with a large gun.</p><p><a href="http://www.bonnycode.com/.a/6a00e55074bd3e8833010535f40b7d970b-pi" style="display: inline;"><img alt="Arnold-schwarzenegger-the-terminator" border="0" class="at-xid-6a00e55074bd3e8833010535f40b7d970b " src="http://www.bonnycode.com/.a/6a00e55074bd3e8833010535f40b7d970b-800wi" title="Arnold-schwarzenegger-the-terminator" /></a>
 </p><p>"I've come from the future and I must stop your bug fix. You have no idea what will happen when you make this change. You didn't reproduce the problem. You didn't find the <a href="http://en.wikipedia.org/wiki/Root_cause_analysis">root cause</a>. You didn't talk to someone knowledgeable in this part of the code. You didn't find the person who caused the bug and ask them about the fix. You didn't even test your fix. I'm sorry but for the sake of the future I can't let you commit that change."</p><p>The man lowers the gun and fires. </p><p>Your monitor disintegrates into a thousand shards of glass and plastic. Next he shoots your keyboard, the letter q smacks you in the forehead as it flies away from the carnage. Your brand new laser mouse is next. You begin to move your hand to shield it from the oversized rounds this future man is shooting but thinking again you pull it back just before he fires. Finally, he takes aim at your computer. At this point you've resigned yourself. This man has travelled back in time to stop you from checking in this horribly stupid bug fix and he means to finish the job. He fires and the hard drives spins for its last time.</p><p>He turns and starts to walk away. Just as he exits the door though he turns and he shoots one of the wheels off your chair. Your chair slumps towards where the now missing wheel was throwing your body to one side. Future man smiles with a satisfaction that only comes from knowing one has done a thorough job. Future man wonders why you couldn't have been as thorough in your own bug fixing in finding the root cause of the problem before carelessly throwing around fixes.</p><p>As you sit in the carnage of your computer equipment, slanted to one side in your broken chair, smelling the still fresh smoke you think over what you learned today. The future man's words echo in your brain...<br />"You have no idea what will happen when you make this change. You didn't reproduce the problem. You didn't find the root cause. You didn't talk to someone knowledgeable in this part of the code. You didn't find the person who caused the bug and ask them about the fix. You didn't even test your fix."</p><p>Your left to ponder what future your simple bug fix had unintentionally caused that it would induce man to invent time travel to send someone back to stop you. Truly horrible it must have been and with that you promise in the name of the future man with the big gun to never make another bug fix on a problem that you don't understand.</p></div>
</content>



    <feedburner:origLink>http://www.bonnycode.com/guide/2008/11/do-not-fix-what-you-dont-understand.html</feedburner:origLink></entry>
    <entry>
        <title>The Syllabus</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/typepad/bonny_code/~3/eUFRkwqArx8/the-syllabus.html" />
        <link rel="replies" type="text/html" href="http://www.bonnycode.com/guide/2008/11/the-syllabus.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-57930371</id>
        <published>2008-11-02T22:42:11-08:00</published>
        <updated>2008-11-02T22:42:11-08:00</updated>
        <summary>I explained before why I thought "programology" should be taught, but I didn't go into detail on what I would teach. To start, there would need to be at least a cursory mention of Literate Programming. Just like many English...</summary>
        <author>
            <name>Lucas Pierce</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Web/Tech" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://www.bonnycode.com/guide/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>I explained before why I thought "programology" should be taught, but I didn't go into detail on what I would teach.</p><p>To start, there would need to be at least a cursory mention of <a href="http://en.wikipedia.org/wiki/Literate_Programming">Literate Programming</a>. Just like many English Literature classes start with Beowulf, we could start with a reading of <a href="ftp://tug.ctan.org/pub/tex-archive/systems/knuth/dist/tex/tex.web">TeX</a>. Donald Knuth has a little sensor implanted in his brain that tells him every time someone reads his code; make the professor happy and at least try to read some of it.</p><p>I wouldn't dwell very long on Literate Programming. To do so would, sadly, lead to a place where we focus on finding the best source code and studying that. Instead the point is to find the best programs and study their source code. Now given, there should be some correlation between quality of source code and quality of program, but I want that correlation to be discovered in its true form and not the usual manifestation of neophytes arguing over number of comments or spaces vs. tabs.</p><p>So, at this point I believe we are at about day 3 of the class. The first true source code reading I would do would be of the Java JDK compared and contrasted with Apache Commons. For instance, take a gander at <a href="http://www.docjar.com/html/api/java/lang/String.java.html">java.lang.String</a> vs. <a href="http://svn.apache.org/repos/asf/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java">org.apache.commons.lang.StringUtils</a>. Library code like this is a good place to start because it is easy to read, self contained, and well commented. I find the java.lang classes especially to be friendly late night reading while sipping on hot cocoa next to a roaring fire.</p><p>Comparing the latest and greatest snapshots of programs is interesting in and of itself, but to truly understand a program you need to see its evolution. What were the choices the programmers made originally. What design decisions stuck around and which were abandoned. To this end I would now turn to the Ruby programming languages source code. This is a good candidate for such study because it was written mostly by one person, it is fairly small overall, and it was written over the course of many years with at least 10 years of subversion history to dig through. The reason I think it is important that it was largely the work of one person is that there will be less noise where code is rewritten simply because it is not understood which is very common in large programming teams. My inherent love of string code showing, take a look at the subversion history for <a href="http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_9_1/string.c?view=log">string.c</a>. Look at some of the methods in his version 2 and see how they evolve over time. In what ways does the code get more and more complex? In what ways does it actually become easier to understand?</p><p>So far, we've only had to deal with largely isolated components which is nice when trying to study source code, but eventually one has to grasp with understanding large systems. The big guns in this case would be studying the Eclipse IDE code base. It is large, modular and built by a large disjointed set of people. I wouldn't concentrate on reading code at this stage as I would on scanning it. The takeaway skill would be the ability to conceptualize the architecture of a large program and then be able to answer questions such as: if there was a bug in the string differencing, where would you go to fix it and if you were to add a feature that let you tear off subviews into their own windows where would you start.</p><p>This is of course just a taste of what the class would look like. There would have to be quizzes that prove you comprehended the code, midterms that involved reading new code on the spot as well as recalling code previously read and a major project where students would pick the source code to read and write their observations on.  </p><p>Please let me know if there is publicly viewable source code that you have read in the past that you think is of particular note.</p></div>
</content>



    <feedburner:origLink>http://www.bonnycode.com/guide/2008/11/the-syllabus.html</feedburner:origLink></entry>
 
</feed><!-- ph=1 -->

