<?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>Code Buddy &#187; Coding Standards</title>
	<atom:link href="http://www.codebuddy.co.uk/category/coding-standards/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codebuddy.co.uk</link>
	<description>Ramblings from the Coding Trenches</description>
	<lastBuildDate>Wed, 23 Dec 2009 13:55:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DSCM &#8211; A Move Back to Big Bang Integration</title>
		<link>http://www.codebuddy.co.uk/dscm-a-move-back-to-big-bang-integration/</link>
		<comments>http://www.codebuddy.co.uk/dscm-a-move-back-to-big-bang-integration/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 07:33:36 +0000</pubDate>
		<dc:creator>codebuddy</dc:creator>
				<category><![CDATA[Coding Standards]]></category>

		<guid isPermaLink="false">http://www.codebuddy.co.uk/?p=382</guid>
		<description><![CDATA[Used sensibly the move away from centralised to distributed source control management offers more benefits than it does drawbacks. Used unwisely it could take us back to the days of Big Bang Integration
Branching Privately
Irrespective of the number of meetings attended or PowerPoint slides produced, developers communicate in one language, and one language only &#8211; the [...]]]></description>
			<content:encoded><![CDATA[<p>Used sensibly the move away from centralised to distributed source control management offers more benefits than it does drawbacks. Used unwisely it could take us back to the days of <a href="http://www.testinggeek.com/index.php/testing-types/life-cycle/55-bigbang-integration-testing">Big Bang Integration</a></p>
<p><strong>Branching Privately</strong></p>
<p>Irrespective of the number of meetings attended or PowerPoint slides produced, developers communicate in one language, and one language only &#8211; the language of  <em>code</em>. In many organisations trunk, or centrally hosted branches, give visibility of the work going on. This keeps everyone in the loop as to what is being developed, <em>how</em> its being done, and by <em>whom</em>.</p>
<p>Moving away from this work flow, towards teams working in local branches away from prying eyes, cuts this information flow. The development effort in these branches, now lacking the exposure to more than the team working on it, could miss out on vital feedback from other team members. Team member, that had the work been done centrally, allowing them to see what was happening, could have given feedback. This could have saved the team weeks or months of effort had they known that code already existed over here, or this team requires that module to do that as well, so don&#8217;t duplicate effort. These issues won&#8217;t be discovered until the big bang, the merge back into the mainline.</p>
<p><strong>Large Changesets</strong></p>
<p>Branches, by there very nature result in larger changesets being pushed back into the mainline. This can also be true when working on the main branch, but on a local repository. There can also be a temptation to complete a full feature before pushing the changes to the mainline. Developers will still be commiting their code in small changesets, but without giving it that push upstream to the mainline many benefits are lost.</p>
<p>Committing a feature little by little has many benefits. I&#8217;ve already mentioned peer review when talking about branching. In addition to this it allows detection of regressions to be detected as early as possible, making them easier to locate. Putting code into the mainline in feature size chunks certainly result in making it easier to track which changeset caused a regression, as there will be less of them. But finding which part of that feature sized changeset caused the regression will not be so easy.</p>
<p><strong>Enjoy responsibly</strong></p>
<p>Distributed soruce control management systems give us great power, but remember <a href="http://www.imdb.com/title/tt0145487/quotes">with great power comes great responsilbity</a>.<em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebuddy.co.uk/dscm-a-move-back-to-big-bang-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I Smell Duplication Can You?</title>
		<link>http://www.codebuddy.co.uk/i-smell-duplication-can-you/</link>
		<comments>http://www.codebuddy.co.uk/i-smell-duplication-can-you/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 09:19:44 +0000</pubDate>
		<dc:creator>codebuddy</dc:creator>
				<category><![CDATA[Coding Standards]]></category>

		<guid isPermaLink="false">http://www.codebuddy.co.uk/?p=224</guid>
		<description><![CDATA[Want to know how to find duplicate code in your code base quickly and easily? Want to be able to sniff out the most pungent of code smells in double quick time? You&#8217;ve come to the right place.
Smells 
If your not familiar with the idea of code smells, the be sure to check out Martin [...]]]></description>
			<content:encoded><![CDATA[<p>Want to know how to find duplicate code in your code base quickly and easily? Want to be able to sniff out the most pungent of code smells in double quick time? You&#8217;ve come to the right place.</p>
<p><strong>Smells </strong></p>
<p>If your not familiar with the idea of code smells, the be sure to check out Martin Fowlers excellent book <a title="Refactoring Book" href="http://www.amazon.co.uk/gp/product/0201485672?ie=UTF8&amp;tag=mycafe-21&amp;linkCode=as2&amp;camp=1634&amp;creative=6738&amp;creativeASIN=0201485672">Refactoring: Improving the Design of Existing Code</a>. <a title="Code Smells" href="http://en.wikipedia.org/wiki/Code_smell">Code smells </a>are symptoms in your source code that can indicate problems &#8211; arguably the worst being code duplication which violates the principles of  <a title="DRY" href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a>.</p>
<p>The code maintenance issues are well known,  so I won&#8217;t revisit them here. What I want to do is talk about a tool I found the other day that helps find duplicate code.</p>
<p><a title="CPD" href="http://pmd.sourceforge.net/cpd.html">Copy Paste Detection </a>(CPD) is a great little program that can detect duplicate code in a code base.  Its available under a BSD-style licence, shipped as part of the <a title="PMD" href="http://pmd.sourceforge.net/">PMD</a> static code analyzer for Java. Although PMD is targeted as java, as CPD works using string matching, it can be used on any language.  Java, JSP, C, C++, Fortran and PHP are supported out of the box. It is also possible to <a title="How to add languages to CPD" href="http://pmd.sourceforge.net/cpd-parser-howto.html">add further langugages</a>.</p>
<p><strong>How to use it</strong></p>
<p>Running CPD is very simple:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>cpd.sh ~<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>source<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>And thats it. By default the output is in text format, this can be changed to xml or csv. Example output of processing the JDK (reported to take only 4 seconds) can be seen <a title="JDK PMD output" href="http://pmd.sourceforge.net/cpdresults.txt">here</a>. The number of duplicate tokens require for code to be considered copy and pasted can also be configured, this defaults to 100.</p>
<p><strong>My findings</strong></p>
<p>I had to increase the heap size available to java to get the code based I&#8217;m working on parsed. Its about a million lines of C/C++ code. There results were fascinating.  Sure enough, copy and pasted code was found, comments and all. Worse still, code that had been copy and pasted but not quite kept in sync, in most cases straight bugs.</p>
<p>The only real false positives I found were with auto generated code. By default CPD recursively parses the directories (you can supply as many as you like) on the command line, without being able to ignore certain files (eg *_autogen.cpp). As these files are produced as part of the build process, I&#8217;m now running CPD on a clean checkout, without build any build artifacts lying about.</p>
<p><strong>What next?</strong></p>
<p>As always with these things, I&#8217;m left with a bunch of open questions:</p>
<p>I can see this tool can offer some real value, but how do I integrate it into my teams work flow? Its a command line tool only, so there is no administration interface to allow results of various runs to be compared and analysed.</p>
<p>There are plenty of other static code analyzers that do much more than just check for duplication, what are peoples experiences with these?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebuddy.co.uk/i-smell-duplication-can-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Are You Stuck In The Maintaince Programmer Mindset?</title>
		<link>http://www.codebuddy.co.uk/are-you-a-stuck-in-the-maintaince-programmer-mindset/</link>
		<comments>http://www.codebuddy.co.uk/are-you-a-stuck-in-the-maintaince-programmer-mindset/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 19:57:21 +0000</pubDate>
		<dc:creator>codebuddy</dc:creator>
				<category><![CDATA[Coding Standards]]></category>

		<guid isPermaLink="false">http://www.codebuddy.co.uk/?p=256</guid>
		<description><![CDATA[We&#8217;re all very good at pointing out whats wrong with code. There are even websites dedicated to exposing and ridiculing bad code and bad design, such as the daily wtf. We all encounter code that isn&#8217;t &#8220;right&#8221; on a daily basis, but how often do we do something about it and let our actions speak [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re all very good at pointing out whats wrong with code. There are even websites dedicated to exposing and ridiculing bad code and bad design, such as <a title="Daily wft" href="http://thedailywtf.com/">the daily wtf</a>. We all encounter code that isn&#8217;t &#8220;right&#8221; on a daily basis, but how often do we do something about it and let our actions speak louder than our words?</p>
<p>It&#8217;s very easy to point out whats wrong with code. Pointing out how the design and implementation of the code we&#8217;re working with is making our lives hard. Talking with fellow programmers about how our hands are tied and how we &#8220;did what we could&#8221; given that it &#8220;wasn&#8217;t our code&#8221;.</p>
<p>This all too familiar discussion demonstrates what I call the <em>maintenance programmer mindset</em>.</p>
<p>Are you too stuck in this mindset? Its very easy to fall into.</p>
<p>I have to remind myself regularly to break out of this mindset; to be bolder, to have the confidence to change the direction the code is heading. To make a clear statement about the problem domain by introducing a new class. To factor out that bit of repeated code into its own method. To break that monolithic module into two more focused modules to regain control over dependencies. To grab the wheel and make the kind of changes that steer the design down the correct path. The requirements on an active software project change constantly, so the design must also.</p>
<p>It&#8217;s quite easy to see if someone is stuck in this mindset. The following are a list of the actions that make a statement about the direction a code base is heading, in order of impact and are unlikely to be performed by sometime stuck in this mindset.</p>
<ul>
<li>Adding new new module/package</li>
<li>Adding a new class</li>
<li>Adding a new source file</li>
<li>Adding a new function</li>
</ul>
<p>If your not doing most of the above on a regular basis, irrespective of if your maintaining software or doing green field development &#8211; your programming with the maintainance programmers mindset.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebuddy.co.uk/are-you-a-stuck-in-the-maintaince-programmer-mindset/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Overloading, Is It really Worth It?</title>
		<link>http://www.codebuddy.co.uk/overloading-is-it-really-worth-it/</link>
		<comments>http://www.codebuddy.co.uk/overloading-is-it-really-worth-it/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 19:52:04 +0000</pubDate>
		<dc:creator>codebuddy</dc:creator>
				<category><![CDATA[Coding Standards]]></category>

		<guid isPermaLink="false">http://www.codebuddy.co.uk/?p=110</guid>
		<description><![CDATA[For a long time I&#8217;ve used overloading, but just recently I&#8217;ve been questioning its uses.
Readability
Looking at the call site when invoking an overloaded function its not immediately obvious which method is being called.

find&#40;&#34;code buddy&#34;&#41;;
find&#40;C_PLUS_PLUS&#41;;

After a quick look through the overloading options available I can always work out which one will be called &#8211; but why [...]]]></description>
			<content:encoded><![CDATA[<p>For a long time I&#8217;ve used overloading, but just recently I&#8217;ve been questioning its uses.</p>
<h3>Readability</h3>
<p>Looking at the call site when invoking an overloaded function its not immediately obvious which method is being called.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">find<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;code buddy&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
find<span style="color: #008000;">&#40;</span>C_PLUS_PLUS<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>After a quick look through the overloading options available I can always work out which one will be called &#8211; but why should I? If code is making me think more than is absolutely neccessary then for my money, there is an issue with it. Wouldn&#8217;t the previous code be clearer if it was written like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">findByName<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;code buddy&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
findByLanguage<span style="color: #008000;">&#40;</span>C_PLUS_PLUS<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<h3>Tags</h3>
<p>My poor tags get confused! I&#8217;m working in a C++ code base on a linux OS. Rightly or wrongly, I&#8217;m using <a href="http://www.gnu.org/software/emacs/">emacs </a>with <a href="http://cscope.sourceforge.net/">cscope </a> as my chosen editing/tagging solution.  For example, if I&#8217;m working with the <a href="http://en.wikipedia.org/wiki/Visitor_pattern">Visitor Pattern </a> that is using overloading for its visit method, as search for:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> visit<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> NodeA<span style="color: #000040;">&amp;</span> node<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>also finds me:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> visit<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> NodeB<span style="color: #000040;">&amp;</span> node<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">void</span> visit<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> NodeC<span style="color: #000040;">&amp;</span> node<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>This maybe a shortcoming of cscope, however I&#8217;ve seen other tagging solutions, notably the one used in <a href="http://www.slickedit.com/">Slick Edit </a>fall at the same hurdle.  I&#8217;d much rather see this visitor interface written like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> visitNodeA<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> NodeA<span style="color: #000040;">&amp;</span> node<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> visitNodeB<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> NodeB<span style="color: #000040;">&amp;</span> node<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> visitNodeC<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> NodeC<span style="color: #000040;">&amp;</span> node<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span></pre></div></div>

<h3>Templates</h3>
<p>It maybe nessary for templatised code that you use overloading, eg:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span>Node<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">void</span> doSomeStuffAndVisit<span style="color: #008000;">&#40;</span>IVisitor<span style="color: #000040;">&amp;</span> visitor,
                        <span style="color: #0000ff;">const</span> Node<span style="color: #000040;">&amp;</span> node<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// some code</span>
    visitor.<span style="color: #007788;">visit</span><span style="color: #008000;">&#40;</span>node<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">// some more code</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h3>Constructors</h3>
<p>Overloading of constuctors is unavoidable.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Creates a Foo from the xml in file file</span>
Foo<span style="color: #008080;">::</span><span style="color: #007788;">Foo</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000040;">&amp;</span> file<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// Creates a Foo from the xml node root</span>
Foo<span style="color: #008080;">::</span><span style="color: #007788;">Foo</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> xmlNode<span style="color: #000040;">&amp;</span> root<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Unless of course your using a factory method, in which case, there is no need to overload like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Creates a Foo from the xml in file file</span>
<span style="color: #000040;">*</span>Foo FooFactory<span style="color: #008080;">::</span><span style="color: #007788;">createFoo</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000040;">&amp;</span> file<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// Creates a Foo from the xml node root</span>
<span style="color: #000040;">*</span>Foo FooFactory<span style="color: #008080;">::</span><span style="color: #007788;">createFoo</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> xmlNode<span style="color: #000040;">&amp;</span> root<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The comments really are the give away here, taking the comments away things become so much more readable.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">FooFactory<span style="color: #008080;">::</span><span style="color: #007788;">createFooFromFile</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000040;">&amp;</span> file<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
FooFactory<span style="color: #008080;">::</span><span style="color: #007788;">createFooFromXMLNode</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> xmlNode<span style="color: #000040;">&amp;</span> root<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<h3>Conclusion</h3>
<p>These days, unless I&#8217;m working with any code thats using templates, i&#8217;m avoiding overloading, the pros are much outweighed by the cons.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codebuddy.co.uk/overloading-is-it-really-worth-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

