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

<channel>
	<title>//TODO: Create Blog Title &#187; Unmaintainable Code</title>
	<atom:link href="http://DontForgetYourTODOs.com/category/unmaintainable-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://DontForgetYourTODOs.com</link>
	<description></description>
	<lastBuildDate>Mon, 26 Jul 2010 03:20:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Five Steps to Making Fellow Developers Miserable</title>
		<link>http://DontForgetYourTODOs.com/2009/08/miserable-developers-2/</link>
		<comments>http://DontForgetYourTODOs.com/2009/08/miserable-developers-2/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 12:00:46 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Series]]></category>
		<category><![CDATA[Unmaintainable Code]]></category>

		<guid isPermaLink="false">http://DontForgetYourTODOs.com/?p=320</guid>
		<description><![CDATA[1. Setters that do more than SET All property setters should validate their input and set the value of other properties. This will remove the burden of validation from other developers. private string _id; public string Id { &#160; get &#160; { &#160;&#160;&#160; return _id; &#160; } &#160; set &#160; { &#160;&#160;&#160; _id = value.ToString(); [...]]]></description>
			<content:encoded><![CDATA[<h4>1. Setters that do more than SET</h4>
<p>All property setters should validate their input and set the value of other properties. This will remove the burden of validation from other developers.</p>
<div style="border-bottom: black thin dashed; border-left: black thin dashed; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; font-family: courier new; background: white; color: black; font-size: 11pt; border-top: black thin dashed; border-right: black thin dashed; padding-top: 10px">
<p style="margin: 0px"><span style="color: blue">private</span> <span style="color: blue">string</span> _id;</p>
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: #2b91af">string</span> Id</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: blue">&#160; get</span></p>
<p style="margin: 0px">&#160; {</p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; return</span> _id;</p>
<p style="margin: 0px">&#160; }</p>
<p style="margin: 0px"><span style="color: blue">&#160; set</span></p>
<p style="margin: 0px">&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160; _id = <span style="color: blue">value</span>.ToString();</p>
<p style="margin: 0px">&#160;&#160;&#160; _AnotherPropertyValue = <span style="color: blue">value</span>.ToString();</p>
<p style="margin: 0px">&#160; }</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: blue">private</span> <span style="color: blue">string</span> _AnotherPropertyValue;</p>
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">string</span> PropertyValue</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: blue">&#160; get</span></p>
<p style="margin: 0px">&#160; {</p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; return</span> _AnotherPropertyValue;</p>
<p style="margin: 0px">&#160; }</p>
<p style="margin: 0px"><span style="color: blue">&#160; set</span></p>
<p style="margin: 0px">&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160; _AnotherPropertyValue = <span style="color: blue">value</span>;</p>
<p style="margin: 0px">&#160; }</p>
<p style="margin: 0px">}</p>
</p></div>
<p><strong>Workaround: </strong>Property getters and setters should only save and return values. Getters and setters should not validate against null, perform regular expression checks, or typecast. Additional logic can take place in business logic classes. Setters that do more than set also cause issues during unit testing. What goes in, must come out.</p>
<h4>2. The Golden Hammer</h4>
<p>Whenever implementing something new, remember the last successful (or similar) experience and reuse.&#160; There is no doubt about it. What worked for you in the past, will continue to work for you now.</p>
<p><strong>Workaround: </strong>With the <a href="http://sourcemaking.com/antipatterns/golden-hammer">Golden Hammer</a> approach, your solution is the hammer and every project you come up against is a nail. If you find yourself trying to implement an exact replica of a solution that you built in the past, chances are that you will miss some requirements or pigeonhole yourself into somewhere you do not want to be. Instead, step back, learn what the functionality of the system must be, and compare/contrast the differences between past experiences.</p>
<h4>3. Swiss Army Class</h4>
<p>Just as in <a href="http://dontforgetyourtodos.com/2009/07/five-steps-to-unmaintainable-code/">bloated class</a>, minimize how many separate classes your code must deal with. If you know all of the different functional areas your application needs to cover, extract them to an interface. Using interfaces will allow you to switch out the implementation types without changing your code. Just make sure that you keep your number of implementation classes low so that it is more maintainable. If necessary, make the lone class implement every interface in the project.</p>
<p><a href="http://dontforgetyourtodos.com/wp-content/uploads/2009/07/SwissArmyClass.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="SwissArmyClass" border="0" alt="SwissArmyClass" src="http://dontforgetyourtodos.com/wp-content/uploads/2009/07/SwissArmyClass_thumb.png" width="163" height="191" /></a></p>
<p><strong>Workaround: </strong>Focus on keeping the implementation of your classes very specific to single units. If you feel the need to implement multiple interfaces to create a hybrid of a few simple interfaces, this is perfectly acceptable.</p>
<h4>4. Yet Another Damn Layer</h4>
<p>Encapsulation is one of the greatest features of object oriented programming. If you can find a way to make existing code more generic so as to make it easier for implementation efforts (and less code writing!) you should do so. Create a generic interface that will take care of defining all of the different functionality in one call.</p>
<p><strong>Workaround: </strong>Encapsulation should be used to hide any of the internal mechanisms of a separate software component. Good examples of this are code that is used to perform common tasks such as logging, serialization, or instrumentation metrics.</p>
<h4>5. Unit Testing and Stale Data</h4>
<p>Since testing is usually a hassle to go through, try and spend as little time doing it as possible. It already takes long enough to set up the tests and the test data. Try not to worry about clearing out the test data since it is only in the development environment.</p>
<p><strong>Workaround: </strong>Unit tests should take care of setting themselves up and tearing themselves down. Unit testing should and can be a full-time job position as it should account for every possible variation of data input and output that can occur. If you can not write your unit tests to clean their test data up, then they should use in-memory data providers so as not to impact any other users in the same environment.</p>
<p><strong>* DISCLAIMER *</strong> Please note that my views are that of the <strong>Workaround</strong> type method and this article is meant to prove humor at what can go wrong when unsafe practices are used. Also keep in mind, I’ve probably done each and one of these plenty of times in my career.</p>
]]></content:encoded>
			<wfw:commentRss>http://DontForgetYourTODOs.com/2009/08/miserable-developers-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code-smell: Whack-a-Mole</title>
		<link>http://DontForgetYourTODOs.com/2009/08/code-smell-whack-a-mole/</link>
		<comments>http://DontForgetYourTODOs.com/2009/08/code-smell-whack-a-mole/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:00:52 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Unmaintainable Code]]></category>

		<guid isPermaLink="false">http://DontForgetYourTODOs.com/?p=395</guid>
		<description><![CDATA[It&#8217;s 4:00 on Friday afternoon. Do you know where you want to be? Definitely not at work. About fifteen minutes before you decide to log off and bolt out early, a critical defect is logged with your application. Your data import isn&#8217;t working correctly and it is losing content during execution. The client, and project [...]]]></description>
			<content:encoded><![CDATA[<h4>It&#8217;s 4:00 on Friday afternoon. Do you know where you want to be?</h4>
<p>Definitely not at work. About fifteen minutes before you decide to log off and bolt out early, a <em>critical</em> defect is logged with your application. Your data import isn&#8217;t working correctly and it is losing content during execution. The client, and project managers stress to you that this is a must fix issue as the testers cannot continue until your content is valid.</p>
<p>You grumble, sit back down, and pull up the code to inspect the issue. Ten to fifteen minutes later the fix looks relatively easy. Excited that a resolution was identified so fast, you settle in and begin the fix. Shortly after the fix is in place, you test to make sure everything continues to work as is&#8230;. then you gasp as you realize what happens next: it is the <em>Whack-a-Mole </em>bug.</p>
<p><a href="http://www.flickr.com/photos/smcgee/1317231016/"><img class="aligncenter" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://dontforgetyourtodos.com/wp-content/uploads/2009/07/whack_a_mole.jpg" border="0" alt="The Whack-a-Mole bug" width="244" height="164" /></a></p>
<blockquote><p><strong>whack-a-mole bug </strong><em>n </em><strong>1. </strong>a defect that reappears throughout your application in multiple locations and is difficult to get rid of no how many times you attempt to get rid of it</p>
<p><strong>Related Code-smells: </strong>DUPLICATE CODE, SHOTGUN SURGERY</p></blockquote>
<p>Most often this <a href="http://www.codinghorror.com/blog/archives/000589.html">code smell</a> is a by-product of <a href="http://en.wikipedia.org/wiki/Shotgun_surgery">Shotgun Surgery</a>. While it may seem easy to copy the same validation code used during data-in to data-out, you know it is not the right choice. Now later on, that specific code had particular issues and it must be fixed in more than one place.</p>
]]></content:encoded>
			<wfw:commentRss>http://DontForgetYourTODOs.com/2009/08/code-smell-whack-a-mole/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Five Steps to Making Fellow Developers Miserable</title>
		<link>http://DontForgetYourTODOs.com/2009/07/miserable-developers-1/</link>
		<comments>http://DontForgetYourTODOs.com/2009/07/miserable-developers-1/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 12:00:59 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Series]]></category>
		<category><![CDATA[Unmaintainable Code]]></category>

		<guid isPermaLink="false">http://DontForgetYourTODOs.com/?p=289</guid>
		<description><![CDATA[For all of the new developers and the seasoned veterans, today I am going to shed some light on things (not) to do when writing unmaintainable code. I am hoping this to make this into a series post, so any feedback or your own personal tricks are a great contribution to make.]]></description>
			<content:encoded><![CDATA[<h4>1. Long Method</h4>
<p>Short methods specific to single units are <strong>bad</strong>. Try to limit the number of methods in each class. This will ensure that each method is as long as possible.</p>
<p><strong>Workaround: </strong>In order to prevent <em>long method</em> from happening, I recommend limiting the length of your functions to 30 lines or less (40 including exceptions).  Focus on keeping your functions less then one screen&#8217;s length.  Try <a href="http://www.secretgeek.net/6min_program.asp">bumping up the font-size of your IDE</a> so that a lot less code fits on the screen.</p>
<h4>2. Out of Sync Comments</h4>
<p>Just like you learned in college, comments are the best form of documentation. Comment blocks are better. Provide details about every line of code and include <strong>pre-conditions, </strong><strong>post-conditions</strong>, and <strong>expected exceptions</strong>. Comments are important because they help other developers calling the code understand how it works.</p>
<div style="border-right: black thin dashed; padding-right: 10px; border-top: black thin dashed; padding-left: 10px; font-size: 10pt; background: white; padding-bottom: 10px; border-left: black thin dashed; color: black; line-height: 10px; padding-top: 10px; border-bottom: black thin dashed; font-family: courier new">
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> Saves data into database</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;remarks&gt;</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> Save Data opens up a SqlCommand object and calls the </span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> sp_SaveUsers stored procedure to save a user object.</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/remarks&gt;</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;preconditions&gt;</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> User object must be created. sp_SaveUsers must exist in SQL server</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/preconditions&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">void</span> SaveData()</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: green">//Get Connection String</span></p>
<p style="margin: 0px"><span style="color: blue">string</span> connectionString;</p>
<p style="margin: 0px"><span style="color: #2b91af">SqlConnection</span> connection = <span style="color: blue">new</span> <span style="color: #2b91af">SqlConnection</span>(connectionString);</p>
<p style="margin: 0px"><span style="color: green">//Open Connection</span></p>
<p style="margin: 0px">connection.Open();</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: green">//Create Sql Command call &#8220;sp_SaveUsers&#8221;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">SqlCommand</span> cmd = <span style="color: blue">new</span> <span style="color: #2b91af">SqlCommand</span>();</p>
<p style="margin: 0px">cmd.Connection = connection;</p>
<p style="margin: 0px">cmd.CommandText = <span style="color: #a31515">&#8220;INSERT INTO USERS (userId, userName) VALUES (?,?)&#8221;</span>;</p>
<p style="margin: 0px">cmd.CommandType = System.Data.<span style="color: #2b91af">CommandType</span>.TableDirect;</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: green">//Add Parameters for Stored Proc</span></p>
<p style="margin: 0px">cmd.Parameters.Add(u.ID);</p>
<p style="margin: 0px">cmd.Parameters.Add(u.Name);</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: green">//Execute Command</span></p>
<p style="margin: 0px">cmd.ExecuteNonQuery();</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: green">//Close connection</span></p>
<p style="margin: 0px">connection.Close();</p>
<p style="margin: 0px">}</p>
</div>
<p><strong> </strong></p>
<p><strong>Workaround: </strong>If you are going to write comments, specify the problem that your code solves, not how it solves it. Think of the last time you picked up a book at the store and read the back. Would you have wanted it to tell you what the story is about, or how the plot is laid out? <strong>If you change the implementation (bug, refactor, etc.), the comments can remain the same.</strong> Try and get away from code commenting all together by writing self-documenting code. For examples read Jeff Atwood&#8217;s <a href="http://www.codinghorror.com/blog/archives/001150.html">Coding Without Comments</a>.</p>
<h4>3. Bloated Class</h4>
<p>Enforce a limit to the number of classes allowed in the codebase. To reinforce this, place all logic into one big <a href="http://sourcemaking.com/antipatterns/the-blob">blob class</a>.  With this class you are the ultimate tool that can do anything. The more classes you have, the more source files you maintain. More source files increase the compile time of your project.</p>
<p><a href="http://dontforgetyourtodos.com/wp-content/uploads/2009/07/blobclass.jpg"><img class="aligncenter" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://dontforgetyourtodos.com/wp-content/uploads/2009/07/blobclass-thumb.jpg" border="0" alt="Blob Class" width="163" height="318" /></a></p>
<p><strong>Workaround: </strong>Follow the <a href="http://mmiika.wordpress.com/oo-design-principles/">Single Responsibility Principle (SRP)</a> to keep the implementation of your class specific to its&#8217; purpose. Classes should only have one reason to change, and no other components of that class should be affected during that change.</p>
<h4>4. Classes that are &#8220;involved&#8221;</h4>
<p>The more that each class knows and relies on another class, the better your code is as a single unit. New developers will need to understand every class in your solution because one change creates a ripple effect throughout the system. <a href="http://en.wikipedia.org/wiki/Dependency_hell">Dependency hell</a> is much nicer than it sounds.</p>
<p><a href="http://www.flickr.com/photos/rattodisabina/1422826582/"><img class="aligncenter" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://dontforgetyourtodos.com/wp-content/uploads/2009/07/dominos1.jpg" border="0" alt="dominos" width="244" height="184" /></a></p>
<p><strong>Workaround: </strong>Develop code that is loosely coupled. Loosely coupled code is attained by making each class units that do not have knowledge of how other classes work. This creates more flexible design. <a href="http://weblogs.asp.net/sfeldman/archive/2008/06/09/too-loosely-coupled-code.aspx">Do not overkill</a> as too much can lead to unneeded code complexity.</p>
<h4>5. Developer Ego</h4>
<p>The smarter a developer and the better coder that they believe they are, the better the code output. The only one capable of creating awesome code is one who looks at the world as one complex problem. Try to avoid breaking it down into simple smaller problems, otherwise any regular programmer is capable of doing your job.</p>
<p><strong>Workaround: </strong>Give the developer the smack-down.</p>
<p><strong>* DISCLAIMER *</strong> Please note that my views are that of the <strong>Workaround</strong> type method and this article is meant to prove humor at what can go wrong when unsafe practices are used. Also keep in mind, I&#8217;ve probably done each and one of these plenty of times in my career.</p>
]]></content:encoded>
			<wfw:commentRss>http://DontForgetYourTODOs.com/2009/07/miserable-developers-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

