<?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>Bugfree.dk - Ronnie Holm&#039;s blog &#187; Refactoring</title>
	<atom:link href="http://www.bugfree.dk/blog/tag/refactoring/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bugfree.dk/blog</link>
	<description>Not anti-anything, just pro-quality</description>
	<lastBuildDate>Wed, 08 Sep 2010 13:57:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Why not to comment code</title>
		<link>http://www.bugfree.dk/blog/2009/08/15/why-not-to-comment-code/</link>
		<comments>http://www.bugfree.dk/blog/2009/08/15/why-not-to-comment-code/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 19:55:24 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quality]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/?p=535</guid>
		<description><![CDATA[Update, Aug 18, 2009: I&#8217;m amazed at how much attention this post has received. More than 200 comments on Reddit. I was just listening to the Why comments are evil episode of Deep Fried Bytes. The views put forward by the guest, Corey Haines, deeply resonate with me because I believe they&#8217;re what every developer [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update, Aug 18, 2009</strong>: I&#8217;m amazed at how much <a href="http://www.reddit.com/r/programming/comments/9b4ct/why_not_to_comment_code">attention</a> this post has received. More than 200 comments on Reddit.
</p>
<p>I was just listening to the <a href="http://deepfriedbytes.com/podcast/episode-35-why-comments-are-evil-and-pair-programming-with-corey-haines">Why comments are evil</a> episode of <a href="http://deepfriedbytes.com">Deep Fried Bytes</a>. The views put forward by the guest, <a href="http://www.coreyhaines.com/">Corey Haines</a>, deeply resonate with me because I believe they&#8217;re what every developer should strive for. I&#8217;m not advocating that code should be entirely free of comments, but that most comments do more harm than good.
</p>
<p>Below I&#8217;ve listed what I consider the main points of view &#8212; or pearls of wisdom &#8212; from the episode and included my own commentary.
</p>
<ul>
<li>It&#8217;s important to differentiate between code comments and API documentation. For API documentation, don&#8217;t auto-generate. Especially don&#8217;t go with tools like <a href="http://submain.com/products/ghostdoc.aspx">GhostDoc</a>. Take the time to document properly. Otherwise, you&#8217;re more likely to confuse the developer trying to make sense of your code.
</li>
<li>Stop focusing on having the computer understand you and start focusing on the person that comes after you, e.g., while there&#8217;s some overhead to method calls, unless the profiler tells you otherwise, don&#8217;t hesitate to break down a method into as many smaller methods as it takes to make it more approachable.
</li>
<li>Every time you&#8217;re tempted at writing a comment, take the time to think if you can make the code tell its own story, e.g., instead of some branching condition, extract the condition into a method to emphasize the story of why over how.
</li>
<li>Developers comment to explain a confusing part of their code, rather than take the time to <a href="http://en.wikipedia.org/wiki/Refactoring">refactor</a> it by extracting a method or naming a variable properly. Inevitably the code gets modified and the comment rots.
</li>
<li>Parts of a method may be complicated so a comment is added. Saying part of a method is complicated is in itself a sign that it&#8217;s doing too much.
</li>
<li>The prevailing culture among developers is to focus on what it takes to get code working. It&#8217;s a battle of short-term vs. long-term maintainability, and short-term almost always comes out as the winner. Writing code, ask yourself if you&#8217;re able to immediately understand the code a month from now.
</li>
</ul>
<p>The opinions put forward in the episode aren&#8217;t new. Still, I find them well worth iterating because as developers we tend to not pay enough attention to them.
</p>
<p>While refactoring is probably as old as programming, <a href="http://martinfowler.com/">Martin Fowler</a>&#8216;s 1999 <a href="http://www.amazon.com/Refactoring-Improving-Existing-Addison-Wesley-Technology/dp/0201485672">Refactoring: Improving the Design of Existing Code</a> turned it mainstream. Others have followed it his footsteps advocating for the larger concept of <a href="http://manifesto.softwarecraftsmanship.org/">software craftsmanship</a>. Most notably <a href="http://www.objectmentor.com/omTeam/martin_r.html">Uncle Bob</a>, who delivered an excellent <a href="http://www.viddler.com/explore/oredev/videos/15/">talk</a> on the subject at Øredev 2008.
</p>
<p>On a personal note, I once worked at a consulting company where every new employee was handed three books on the first day of employment. One of these was the Refactoring book. The others were the seminal <a href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612">Design Patterns: Elements of Reusable Object-Oriented Software</a> and <a href="http://www.amazon.com/Writing-Effective-Cases-Software-Development/dp/0201702258/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1250364803&amp;sr=1-1">Writing Effective Use Cases</a>. I think that reveals something important about that company&#8217;s culture. Sadly, most companies aren&#8217;t that specific on issues of code quality.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2009/08/15/why-not-to-comment-code/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
