<?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>Warren Seen &#187; c++</title>
	<atom:link href="http://warrenseen.com/blog/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://warrenseen.com/blog</link>
	<description>freelance software developer</description>
	<lastBuildDate>Wed, 03 Jun 2009 23:54:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The committer model in practice</title>
		<link>http://warrenseen.com/blog/2006/03/28/the-committer-model-in-practice/</link>
		<comments>http://warrenseen.com/blog/2006/03/28/the-committer-model-in-practice/#comments</comments>
		<pubDate>Tue, 28 Mar 2006 04:25:36 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2006/03/28/the-committer-model-in-practice/</guid>
		<description><![CDATA[Interesting article about the use of the &#8220;Committer Model&#8221; in commercial software development, borrowed from the open source community.
The committer model solves a few problems of open source distributed development, but the primary one is that of trust: in a developers intent and in their competence. There are other issues that push different buttons depending [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.artima.com/forums/flat.jsp?forum=270&#038;thread=153785">Interesting article</a> about the use of the &#8220;Committer Model&#8221; in commercial software development, borrowed from the open source community.</p>
<p>The committer model solves a few problems of open source distributed development, but the primary one is that of trust: in a developers intent and in their competence. There are other issues that push different buttons depending on the project, but in the end, these are just indicators of intent or competence.</p>
<p>Personally, I think this is a bit of an extreme approach in the average commercial development project &#8211; certainly for teams under 10 developers I would call it excessive &#8211; as the same issues don&#8217;t apply in a commercial project.</p>
<p>Firstly, you must implicitly trust the intent of the developers which you are paying to write the software &#8211; and if you don&#8217;t, why are they working for you to begin with? Secondly, if you&#8217;ve hired them, then you already have made a decision based on their competence.</p>
<p><span id="more-32"></span>Fair enough, you don&#8217;t leave the keys to the castle with them on the first day, but not allowing them to check into a revision control system AT ALL is just asking for trouble in my opinion.</p>
<p>Still, the fact remains that to ensure quality, you can&#8217;t have code that was just checked in being rolled straight into a release and expect it to work. There needs to be some sort of gating to ensure that code has been relatively well exercised before it makes it into a release build. So how to compromise?</p>
<p>The way we approach this issue is to maintain a &#8220;trunk&#8221;, the latest code in development, and release branches, eg 1.0-release, 1.1-release, etc. We have a team of anywhere up to six developers working on various facets of the code at any time. The rules are simple: </p>
<ol>
<li>don&#8217;t check into the trunk if your code won&#8217;t compile and pass our test suite.</li>
<li>if you have done significant work which has caused breakage, create a private branch until you can fulfill 1.</li>
<li>only one person is in charge of release &#8220;gating&#8221;, eg merging code from the trunk into a release branch.</li>
</ol>
<p>This approach provides the ability for all developers to grab the bleeding edge code, whilst ensuring that code that gets merged into release branches is vetted accordingly. Fixes are applied within the trunk, and backported to release branches if necessary (eg for patch distribution)</p>
<p>In the case of simple changes, this probably takes all of 5 minutes to confirm that the fix does what it needs to do. Bigger changes usually require consultation or a walkthrough with the developer responsible.</p>
<p>In essence, this still implements the same safeguards as the committer model, however you also capture more change history as developers are able to commit small changes as they are made, reducing the risk of introducing widespread errors, or losing large amounts of work through equipment failure.</p>
<p>Personally, it&#8217;s rare for me to do a day&#8217;s work without committing it all &#8211; I&#8217;ve seen a hard drive die overnight enough times to be paranoid.</p>
<p><!--81f6bdb2cdc4da127916df39e3166cfd-->
</p>
<p><!--043ce18299249aae52aa0ff27698ed4b-->
</p>
<p><!--81f6bdb2cdc4da127916df39e3166cfd--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2006/03/28/the-committer-model-in-practice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>If you&#8217;re a programmer, you should know this&#8230;</title>
		<link>http://warrenseen.com/blog/2006/03/27/if-youre-a-programmer-you-should-know-this/</link>
		<comments>http://warrenseen.com/blog/2006/03/27/if-youre-a-programmer-you-should-know-this/#comments</comments>
		<pubDate>Mon, 27 Mar 2006 06:09:37 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2006/03/27/if-youre-a-programmer-you-should-know-this/</guid>
		<description><![CDATA[My initial post was going to be a snark-filled venting of all that ails me with my &#8220;day job&#8221; at the moment. Specifically, the woes of maintenance programming when dealing with a codebase from 2000 and ported from Windows to Linux.
If JP Sartre was a coder, he would have actually said: 
&#8220;hell is other people&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>My initial post was going to be a snark-filled venting of all that ails me with my &#8220;day job&#8221; at the moment. Specifically, the woes of maintenance programming when dealing with a codebase from 2000 and ported from Windows to Linux.</p>
<p>If JP Sartre was a coder, he would have actually said: </p>
<blockquote><p>&#8220;hell is other people&#8217;s (undocumented) code.&#8221;</p>
</blockquote>
<p>So for your amusement, here is the list of simple mistakes I&#8217;ve seen of late. Consider these some simple C++ programming sins you may use to torment those that will follow you for eternity.<span id="more-31"></span></p>
<p><strong>Inappropriate use of delete when you really mean delete[].</strong><br />
Performing a scalar delete on a pointer to an array deletes the first element only and leaves the rest of the array hanging around in memory. What a nice mess that leaves behind.</p>
<p><strong>Inconsistently implementing basic idioms</strong><br />
eg reference counting, across multiple classes. Decide on the &#8220;one true way&#8221; and then put it in a base class, template class, whatever. Just Don&#8217;t Repeat Yourself (DRY).</p>
<p><strong>Using naked pointers.</strong><br />
If you must insist on using pointers, adopt one idiom and stick with it. Don&#8217;t leave dangling pointers, whenever you delete a pointer, set it to NULL and use this as a guard condition, so you don&#8217;t try to delete it twice. eg<br />
<code>if (pFoo) {<br />
delete pFoo;<br />
pFoo=NULL;<br />
}</code><br />
This is mostly useful in the case where you have pointers as member variables of a class, which may or may not have been allocated and/or cleaned up before the destructor is called.</p>
<p><strong>Not commenting code.</strong><br />
At all. What more can I say really? Maybe it was obvious to you when you wrote it, but it beats the life out of me whether the code does what you meant it to do. I&#8217;m not a mind reader or a savant. You&#8217;re not a savant either, but chances are I think you&#8217;re an idiot now I&#8217;m knee deep in your code and it&#8217;s a mess that I can&#8217;t decode.</p>
<p><strong>Smart programmers recognise their own fallibility</strong><br />
&#8230; as well as seeing that trait in others. We&#8217;re imperfect, we all forget things now and then, there&#8217;s no point in being macho about the way we program. Better to be defensive, when you revisit the code 6 months later, you&#8217;ll thank yourself.<br />
<strong><br />
Here are some simple remedies:</strong></p>
<ul>
<li>Use STL containers wherever possible (and sensible), rather than dynamic arrays. The benefits outweigh the performance hit in most non-trivial cases. If you must use arrays, pay close attention to how you delete them, or you&#8217;re eventually gonna get bitten</li>
<li>Pay attention to patterns &#8211; extract common code wherever you can to save repetition. Make this code testable, so when it&#8217;s right, it&#8217;s right through your entire project.</li>
<li>Instead of naked pointers, consider smart pointers, such as STL&#8217;s auto_ptr. Boost also features some more flexible smart pointers, including shared_ptr. Sure auto_ptrs don&#8217;t work so good for arrays, and you can&#8217;t store them in STL containers, but if you find yourself in either of these situations, you should probably rethink what you&#8217;re trying to achieve anyhow. If you program inside of this constraint you&#8217;ll save yourself in the long term</li>
<li>Document your code. It doesn&#8217;t have to be verbose, but leave a few clues to jog your own memory. At the very least, try to document expected functionality and keep it in synch with the code itself. If you say in the comments that a function does &#8220;A&#8221;, it better do &#8220;A&#8221; exactly as advertised. </li>
</ul>
<p>Seriously, this is all stuff I learnt in first year software engineering? Why are so called professionals still not capable of doing this?
</p>
<p><!--dfd1cb834368c26d75b59d7d977d2579-->
</p>
<p><!--d132a14fcf99b4bae7f9bf55536be120-->
</p>
<p><!--dfd1cb834368c26d75b59d7d977d2579--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2006/03/27/if-youre-a-programmer-you-should-know-this/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coming up for air</title>
		<link>http://warrenseen.com/blog/2006/03/27/coming-up-for-air/</link>
		<comments>http://warrenseen.com/blog/2006/03/27/coming-up-for-air/#comments</comments>
		<pubDate>Mon, 27 Mar 2006 05:13:28 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2006/03/27/coming-up-for-air/</guid>
		<description><![CDATA[I&#8217;ve been too busy lately with real work to keep up with the Ruby spider project, but I&#8217;m hoping to get back to it real soon.
This is a vent/rant/gratitude post, based on what I&#8217;ve spent my last 2 weeks dealing with.
I&#8217;ll start with the gratitude, but it&#8217;s all downhill from there. I am immensely thankful [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been too busy lately with real work to keep up with the Ruby spider project, but I&#8217;m hoping to get back to it real soon.</p>
<p>This is a vent/rant/gratitude post, based on what I&#8217;ve spent my last 2 weeks dealing with.</p>
<p>I&#8217;ll start with the gratitude, but it&#8217;s all downhill from there. I am immensely thankful for the developers responsible for the following tools which, IMO, no Linux developer should be without:</p>
<ul>
<li><a href="http://valgrind.org/">Valgrind</a> &#8211; helped me track down a bunch of obvious memory errors in the code</li>
<li><a href="http://dmalloc.com/">dmalloc</a> &#8211; helped me track down those which valgrind couldn&#8217;t</li>
<li><a href="http://www.gnu.org/software/gdb/">gdb</a> &#8211; the more I use gdb, the more effective a tool it becomes to me. Why aren&#8217;t you using it? At least learn to get a backtrace and inspect variables if you&#8217;re at all programming anything with GCC.</li>
<li><a href="http://distcc.samba.org">distcc</a> &#8211; chasing memory issues into base classes led to full recompilation more often than I would have liked. distcc let me put an extra 2 idle machines to work compiling the code. </li>
</ul>
<p>What started as a rather curious crash in our dev branch a couple of weeks ago turned into a major audit of how we allocate, use and free memory in our codebase. When I did get to the bottom of the crash, it turned out not to be a memory issue, but a library dependency inherited from libstdc++. </p>
<p>So here&#8217;s a little nugget for you right off the bat:</p>
<p><strong>If you use STL containers (or any code which uses STL&#8217;s default allocator) in a dynamic library which has been compiled with -MT, you must link any executable that dlopen&#8217;s said library with libpthread.</strong></p>
<p>In hindsight this sounds fairly obvious, right? <span id="more-30"></span>The problem seems to arise due to the fact that the gnu std lib stuff uses a multi-threaded allocator which is dependent on libpthread, yet the pthread_* functions are all weak references which will resolve to NULL if the actual functions can&#8217;t be found.</p>
<p>There are a few reasons why this issue was less than transparent.</p>
<ul>
<li>The error presented as a segfault in mt_allocator.h, rather than an undefined reference, which is usually an immediate sign that a library hasn&#8217;t been linked in.</li>
<li>Our build system uses autoconf/automake, and we have it configured in a way which obscures the fact that we compile all dynamic libraries using -MT (although this is clearly obvious when you watch the compiler output)</li>
<li>The test harness we experienced the issue in was compiled without -MT, although it shared identical AM_CPPFLAGS settings to the library in question.</li>
</ul>
<p>In the end, I found myself here: <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25409">http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25409</a>, and sure enough, adding -lpthread solved my problem. It sounds like they may have patched the mainline of libstdc++ to complain more about weakref&#8217;d symbols, which would be a good thing.</p>
<p>So my beef is not so much with libstdc++, but with how we set up the build system. However having said that, this code used to work fine so I suspect we&#8217;ve tripped over something that was recently changed either in our source, or in the library.</p>
<p>So that&#8217;s some gratitude and some venting. This is getting long&#8230; the rant will get its own post I think.
</p>
<p><!--e9aa18642644ea89bb999b809857e5e4--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2006/03/27/coming-up-for-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
