<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Humblecoder]]></title>
  <link href="http://humblecoder.co.uk/atom.xml" rel="self"/>
  <link href="http://humblecoder.co.uk/"/>
  <updated>2013-02-05T00:54:25+00:00</updated>
  <id>http://humblecoder.co.uk/</id>
  <author>
    <name><![CDATA[Will]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Lc.exe Crashing During Build]]></title>
    <link href="http://humblecoder.co.uk/blog/2013/02/04/crashing-lc-dot-exe-when-building/"/>
    <updated>2013-02-04T15:30:00+00:00</updated>
    <id>http://humblecoder.co.uk/blog/2013/02/04/crashing-lc-dot-exe-when-building</id>
    <content type="html"><![CDATA[<p>For a while now I&#8217;ve had an intermittent problem when building WinForm projects that contain
3rd party library controls, DevExpress in this case, where lc.exe crashes during the build causing
it to fail.  I&#8217;ve never gotten to the bottom of why it does it, but I have got as far as noticing it is
a problem with the contents of .licx files. So a simple and quick fix is to empty the contents
of the licx files. If you delete them the build will fail, this means they can&#8217;t be excluded from
version control as build machine builds will fail.</p>

<p>If you go to the root of your solution and run the command below from PowerShell it should clear the contents
of all of them, then a quick clean/rebuild from the IDE gets it up and running again.</p>

<pre><code>get-childitem .\ -include *.licx -recurse | foreach ($_) {set-content $_.fullname $null }
</code></pre>

<p>Hope that helps someone else :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Updated DDDNorth Android App]]></title>
    <link href="http://humblecoder.co.uk/blog/2012/09/27/updated-dddnorth-android-app/"/>
    <updated>2012-09-27T20:43:00+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2012/09/27/updated-dddnorth-android-app</id>
    <content type="html"><![CDATA[<p>This year I was delighted to once again be selected as a speaker for <a href="http://developerdeveloperdeveloper.com/North2/Default.aspx">DDDNorth</a>
 and to celebrate I decided to update the <a href="http://humblecoder.co.uk/blog/2011/09/24/ddd-north-sessions-android-app/">DDDNorth Android App</a>
I created last year with some new features!</p>

<h2>The App</h2>

<p>Along side last years features of the full schedule, the ability to select sessions
and see a personalised schedule, I&#8217;ve added some new Twitter related related features,
these include:</p>

<ul>
<li><strong>#DDDNorth Twitter Search</strong> Alongside the schedule and your personalised schedule is
a search of twitter for the DDDNorth hashtag so you can keep with what everyone is
saying!</li>
<li><strong>Halo Tweet</strong> When you first launch the app you see one of the last ten tweets
from the #DDDNorth hashtag.</li>
<li><strong>Auto Schedule Update</strong> the app now has the ability to check for schedule updates
(handy as DDDNorth still has TBC sessions).</li>
</ul>


<p>Again nothing fancy and completely unoffical so please redirect all queries/complaints to me
 and not the excellent DDDNorth team.</p>

<p>You can download it from <a href="https://market.android.com/details?id=com.havedroid.dddsched">here</a>.</p>

<h2>My Session</h2>

<p>My session this year is called &#8220;Test All The Things Or Maybe Not&#8221; and I want to talk
through my experiences of unit testing.  From complete beginner who took the advice literally
to where I am today.  Where is that?  With hard won battle scars from poor, difficult to maintain and
flaky unit tests.</p>

<p>I&#8217;m not trying to be an expert, but I hope people starting out will avoid making
the same mistakes I did and others will realise it&#8217;s OK to break the rules :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Moving to Octopress from Wordpress]]></title>
    <link href="http://humblecoder.co.uk/blog/2012/08/11/moving-to-octopress-from-wordpress/"/>
    <updated>2012-08-11T15:13:00+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2012/08/11/moving-to-octopress-from-wordpress</id>
    <content type="html"><![CDATA[<p>Yes, this is yet another another I&#8217;ve moved from Wordpress to Octopress post.  I made the move because I want to get MySQL off the box that hosts my blog and Octopress is pretty awesome.</p>

<p>When choosing a new way to host it I looked at Heroku and GitHub pages but neither (at the time of writing) offered redirects without hitting Ruby middleware and I wanted to keep my old links working.  So I choose to host it myself and serve it up using Nginx.</p>

<p>I found a number of posts on how to make the move but none covered how to deal with links or comments. So I thought I&#8217;d document the steps I took and hope it help others.</p>

<p>1) Goto the <a href="http://octopress.org/">Octopress site</a> and follow the directions to get up and running.</p>

<p>2) Setup Disqus for your current Wordpress blog and import all the comments (this can take a while).</p>

<p>3) Export all your posts from the Wordpress admin area and then run <a href="https://github.com/thomasf/exitwp/">exitwp</a> to convert all your posts to markdown. It might choke at this point on the XML so it&#8217;s just a case of fixing the errors and trying again</p>

<p>4) Run through all your posts and fix them, the Wordpress editor and Windows Live Writer produce some interesting output that doesn&#8217;t convert to well.</p>

<p>5) Run <a href="https://github.com/Dotnetwill/wp2oct-links">wp2oct-links</a> with the exported XML to generate nginx rewrite rules for all your old urls and add them to the nginx conf.</p>

<p>6) Test, deploy, etc then when you&#8217;re happy change the DNS over.</p>

<p>7) Go back to Disqus and get it to spider your site and it should update all the links.</p>

<p>That should do it.</p>

<p>Have fun cursing at Markdown :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Hosting Nancy on Debian with Nginx]]></title>
    <link href="http://humblecoder.co.uk/blog/2012/01/07/hosting-nancy-on-debian-with-nginx/"/>
    <updated>2012-01-07T00:06:08+00:00</updated>
    <id>http://humblecoder.co.uk/blog/2012/01/07/hosting-nancy-on-debian-with-nginx</id>
    <content type="html"><![CDATA[<p>Over the Christmas break I found myself with a bit of free time to play with Nancy.  For a long time I’ve fancied writing a link shortener, I even bought the domain vfy.be to serve shortened links from.  I originally had grand plans, it was going to be a social link shortener where links “trusted”/visited by your friends took you straight to them, otherwise you hit a landing page with the amount of hits, the real url and what Google thinks about it or I was going to iframe the page in with a toolbar.  Anyway, twitter got in the link shortening business and I got another idea and decided to move on.  But still how they worked intrigued me.</p>

<p>So I wrote one for fun using C#, mono 2.10 and Nancy.  When looking at the Nancy docs, it is slightly lacking in how to host on Linux so I thought I’d do my bit by writing a quick overview.</p>

<h2>Options</h2>

<p>There is a couple of options when hosting on Linux, one is to create your Nancy project as a mono ASP.NET project then serve it using xsp (the mono ASP.NET server) and proxying to it or using FastCGI.  This is fairly well documented at the mono site and writing a Nancy app using ASP.NET for hosting is also well documented.  However, I wanted to take a different approach to try and host it in the minimum amount of RAM on an LEB (LowEndBox), because I have a 256MB Xen Debian VPS just sat around doing nothing.</p>

<p>So to minimise RAM I went for self hosting, using pretty much the stock sample with a slight mod (see below). When self hosting the Nancy app will listen on the loopback address at a specified port so we are going to use Nginx to serve static content and forward all requests to our mono process and use Supervisord to monitor the process.</p>

<h2>Pull it all together</h2>

<p>For this you’ll need the following installed on the Linux machine:</p>

<ul>
<li> Mono 2.10</li>
<li> Supervisord</li>
<li> Nginx</li>
</ul>


<p>The first we’re going to do is configure Supervisord.  Supervisord is a process monitoring application that can run any normal process as a daemon and automatically restart it if it crashes.  I first came across this when working with Python sites to keep FastCGI processes running.   The configuration should look something like:</p>

<div><script src='https://gist.github.com/1572767.js?file='></script>
<noscript><pre><code>[program:vfybe]
command=/usr/bin/mono vfy.be.exe -d
user=www-data
stderr_logfile = /srv/www/vfy.be/logs/vfy-stderr.log
stdout_logfile = /srv/www/vfy.be/logs/vfy-stdout.log
directory=/srv/www/vfy.be/app/</code></pre></noscript></div>


<p>The important bits are:</p>

<ul>
<li> command – this specifies the command believe it or not,</li>
<li> user – by default supervisord runs all processes as root, this is bad for webapps.</li>
<li> directory – this sets the working directory, so if you’re app needs anything off disc this needs to be correct.</li>
</ul>


<p>As I said above I needed to make a tweak to the sample self hosting project.  The sample uses Console.ReadLine() to stop the process from exiting, but under Mono when running as a daemon this returns EOF and causes the application to close.  So I updated it to sleep (shamelessly stolen from xsp source  ):</p>

<div><script src='https://gist.github.com/1572840.js?file='></script>
<noscript><pre><code>class MainClass
{
    public static void Main (string[] args)
    {
        // initialize an instance of NancyHost (found in the Nancy.Hosting.Self package)
            var host = new NancyHost(new Uri(&quot;http://127.0.0.1:8888&quot;));    
            host.Start();  // start hosting

            //Under mono if you deamonize a process a Console.ReadLine with cause an EOF 
        //so we need to block another way
        if(args.Any(s =&gt; s.Equals(&quot;-d&quot;, StringComparison.CurrentCultureIgnoreCase)))
        {
            while(true) Thread.Sleep(10000000); 
        }
        else
        {
                Console.ReadKey();    
        }
            
            host.Stop();  // stop hosting
    }
}
</code></pre></noscript></div>


<p>Moving on we need to configure Nginx. The strength of Nginx is serving up static content quickly so we’re going to intercept all requests for static files and then forward the rest to our Nancy app. The configuration below defines an ‘upstream’ which is typically used for load balancing we can use it here for just forwarding requests. Also note we are intercepting and serving requests for /Content using Nginx.  At debug time the default conventions in Nancy will serve this up correctly so we get best of both worlds</p>

<div><script src='https://gist.github.com/1572876.js?file='></script>
<noscript><pre><code> upstream nancyapp {
     server 127.0.0.1:8888;
 }
 
 server {
        listen       80;
        server_name  vfy.be;
        root /srv/www/vfy.be/;

        access_log  /srv/www/vfy.be/logs/access.log;
        error_log  /srv/www/vfy.be/logs/error.log;  

        location /Content/{
             root  /srv/www/vfy.be/app/;
        }

        location / {
            proxy_pass http://127.0.0.1:8888;
        }
}</code></pre></noscript></div>


<h2>How well does it do on our LEB?</h2>

<p>Impressively, idle the combination of Debian Sid, Supervisord, Nginx and the Mono process takes up just 37MB of RAM, but the most important question is can it handle load?  <strong><em>Beware completely unscientific results below  </em></strong></p>

<p>Lets take a look at hitting one of the json API methods* using ApacheBench (that is bundled with OSX  ):</p>

<ul>
<li> 1000 continuos requests with a max of 10 concurrent connections peaks memory at 53MB</li>
<li> 1000 continuos requests with a max of 25 concurrent connections peaks memory at 54MB but 18 out of the 1000 failed with connection reset by peer, which is more the box failing than the app</li>
<li> 1000 continuos requests with a max of 50 concurrent connections peaks memory at 55MB but my own boardband gave up after 700 connection, clearly not enough upspeed</li>
</ul>


<p><em>It’s important to note that this app is one static html page with ajax queries back to a JSON api served by Nancy</em></p>

<h2>Wrapping Up</h2>

<p>I hope someone finds my configuration snippets useful and it is worth noting that my LEB (£2.20 a month for 256MB Xen) failed before the my app did, so I find this very encouraging for it’s performance under Mono and Linux.</p>

<p>Source for the link shortener and conf files can be found at https://github.com/Dotnetwill/vfy.be
The shortener running on Mono http://vfy.be</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[TFS From the Trenches]]></title>
    <link href="http://humblecoder.co.uk/blog/2011/12/04/tfs-from-the-trenches/"/>
    <updated>2011-12-04T10:57:30+00:00</updated>
    <id>http://humblecoder.co.uk/blog/2011/12/04/tfs-from-the-trenches</id>
    <content type="html"><![CDATA[<p>It seems I whenever I see TFS mentioned on twitter/HN/Reddit it is usually
closely followed by mocking or derisive comments. But all these comments lack
any real explanation or reasoning, outside of generally hating on MS, from the
author. So as someone who works with, and has worked with for the past 3 or so
years, TFS on a daily basis I&#8217;d like to add on my two cents on how TFS works
and what my pain points are.</p>

<p>Bear in mind I&#8217;m not an VCS geek, I&#8217;m not going to start talking about how the
extensionalist index metabear does not quite model that of the intrinsically
4D nature of time and application architecture. This is just how I get on with
it while trying to get shit done.</p>

<p>I&#8217;m only going to cover the two parts we use, source control and build
management.</p>

<p>TL;DR; It has lots promise but sadly missing features and poorly thought
functionality severely hamper it.</p>

<h3>Editing Files</h3>

<p>Let&#8217;s cut the crap, working on a file and checking it in is the same in
virtually every VCS. And TFS is not exception here, you work away, see your
changes, check them in and if there is a conflict you get a diff. Not rocket
science and works well enough.</p>

<p>However, this does quickly breakdown if you want edit files outside of Visual
Studio (VS). The problem is files need to be &#8220;checked out&#8221; before you can make
edits. If it didn&#8217;t happen while it was checked out it, it didn&#8217;t happen. I&#8217;ve
lost count of the number of times I&#8217;ve tweaked an XML file, build file, none
cs file and done it in Programmers Notepad only to check in and break the CI
build because the tweaks have been missed.</p>

<p>Editing and merging csproj or sln files is a complete and utter nightmare and
I&#8217;ve never understood why.  Let&#8217;s face it if you&#8217;re using TFS you&#8217;re fairly
invested in the MS ecosystem so you&#8217;re using VS and one of TFS&#8217;s big features
is integration into VS so why oh why, for the love of God why, can&#8217;t TFS parse
and merge sln and csproj files? They are MS formats, produced by an MS tool
and managed in an MS tool W. T. F.</p>

<h3>Merging And Branching</h3>

<p>Personally I&#8217;ve been completely spoilt by local branching in DVCS (Distributed
Version Control System) and I sometimes get lost in what branching means in a
more centralised context. In TFS and svn branching can only be done on the
server allowing multiple people to work on the same branch. Whereas with DVCS
and local branching only you can make edits and commits then when you&#8217;re ready
to integrate your work with your team you pull the upstream, merge it and push
it. So it&#8217;s in your best interest to keep the two as close as possible to
minimise your own pain.</p>

<p>The more centralised models put the onus on nobody to sync the branch with
upstream because somebody, IE not you, will have to do the merge. Many teams
will try to manage this through policy to varying degrees of success and lets
not forget that it is entirely possible to get into the same mess with DVCS.</p>

<p>For me the secret sauce of branching with DVCS is that it moves the emphasis
of the responsibility and management of the branch on to the individual
developer. No amount of nifty features or tooling can make up for the fact
that a branch that hasn&#8217;t been synced with its parent for 3 weeks and has lots
of code churn is going to be a nightmare to merge.</p>

<p>So I don&#8217;t think it&#8217;s fair to pick on TFS over branching, yes it doesn&#8217;t
support local branching but at the same time that has the same issues of good
branching requiring proactive syncing, thought about management and
discipline.</p>

<p>One area where TFS has massively improved recently is in history across
branch. Pre-2010 there was no easy way to follow the history of an item cross
branch but thankfully this has now been added.</p>

<h3>Checking Out, Moving Files and IDE integration</h3>

<p>For those that don&#8217;t know when you do a pull in TFS every file is readonly by
default if you want to edit a file you have to go source control explorer,
find it and check it out.  If you have VS integration turned on (and if you
don&#8217;t you&#8217;re a mentalist) it is all quickly taken care of for you when working
inside of VS.  There is, of course, an option to make files readable on pull
but that only introduces a whole new, more annoying, problem, working out what
has actually changed.  There is no &#8220;Hey TFS, I&#8217;ve change some things figure
out what&#8217;s different and list them as pending changes for this checkin&#8221;, I&#8217;ll
run that by you again if you don&#8217;t check it out TFS doesn&#8217;t know what has
changed.  This is complete lunacy and is a significant barrier when trying to
get shit done.  To be fair, it does have this functionality when your connect
goes offline and when coming back online it will look for changes and
generally find them.  But there is no way to do this from the IDE normally.</p>

<p><strong>Checking out files is a completely moronic concept.</strong><br/>
I said earlier that if it wasn&#8217;t checked out it didn&#8217;t happen, let me amend
that to if didn&#8217;t happen inside source control explorer with the correct verb
then it didn&#8217;t happen.  This is most frustrating with file moves, recently I
restructured one of our main solutions splitting several new projects from one
monster. I created the new projects then cut and paste the required files via
Solution Explorer with TFS integration enabled, expecting TFS to pick up the
moves but it did delete/adds and completely f&#8217;ed up the merges for everyone
else and the history.</p>

<p>For me all this TFS having to be explicitly told what you&#8217;re doing shouldn&#8217;t
be a problem when working in VS, this should be it&#8217;s killer feature.  It
should be don&#8217;t worry just work as normal, TFS is watching and will know what
to do but nothing could be further from the truth.</p>

<p>Oh and on moving, you can&#8217;t multi select files to move them in source control
explorer you either do the whole folder or the files one by one :-/ (I think
it&#8217;s because &#8220;moves&#8221; are actually &#8220;renames&#8221; so it needs to know the filename
but WTF)</p>

<h3>Shelvesets</h3>

<p>Shelvesets on the surface seem a pretty nice feature, it allows you save a
copy of your current changes without checking them in.  They get stored
centrally so can move between machines and even users, handy if you want a
code review or you want to quickly spike something out then share it without
checking it in or branching.</p>

<p>Over time I have found the omission of features deeply frustrating.
Shelvesets themselves do not have any history, I find this fustrating because
the first time I seen them I thought great, I can make changes and have lots
and lots of small checkpoints before checking in the finished bits and it
doesn&#8217;t matter if they don&#8217;t build or cause tests to fail.  But nope,
shelvesets overwrite each other if they have the same name.</p>

<p>The other use case is using them as a stash, so you&#8217;re working away on a
feature or a bug and you discover you&#8217;re working on the wrong branch or
something else high priority comes in so you shelve your current changes.
Later you go to unshelve them on another branch so you can finish up, nope
can&#8217;t do that shelves can&#8217;t move cross branch for reasons known only to MS.</p>

<p>Again another should be a killer feature but so widely misses the mark.</p>

<h3>Builds</h3>

<p>I work for an MS shop so we use MSBuild for builds and TFS build is all
MSBuild based so it integrates nicely.  It can schedule builds, run the CI,
the build machine setup is a little clunky but it makes sense.  Overall
running and managing builds it does a good job.  The only major frustration is
notifications.</p>

<p>Not only is it really difficult to set up a notification, the UI is horrendous
and none obvious, but if someone has setup a notification on your behalf then
you can&#8217;t delete it, see it or see who created it.  So if you want to piss
someone off you can setup for them to be notified on every build that is done
ever and there is nothing they can do about it.  Yes, you can go to the TFS
database and remove them but that&#8217;s a bit extreme and not many developers have
that kind of access.</p>

<h3>Overall</h3>

<p>TFS has so much promise but the combination of idiotic concepts, poor
integration and lacklustre features really harms productive.  A sign of a good
tool should be one that doesn&#8217;t get in the way and in this respect TFS fails
massively.  I would even go as far to say it actively promotes bad VCS habits
from individual developers.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[DDD North Sessions Android App]]></title>
    <link href="http://humblecoder.co.uk/blog/2011/09/24/ddd-north-sessions-android-app/"/>
    <updated>2011-09-24T17:50:35+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2011/09/24/ddd-north-sessions-android-app</id>
    <content type="html"><![CDATA[<p>I was massively honoured to have my session on Android development voted into
DDD North and I&#8217;ve spent the last couple of weeks thinking about and planing
my content to do the honour justice.  While doing this I&#8217;ve created a small
application that lists all the available sessions at DDD North and lets you
keep track of what you&#8217;re planning to attend.  Partly to help recentre my
Android zen and partly to give something back.  So here it is:</p>

<p><a href="http://humblecoder.co.uk/wp-%0Acontent/uploads/2011/09/ddd_screen2.png"><img src="http://humblecoder.co.uk/wp-%0Acontent/uploads/2011/09/ddd_screen2-180x300.png" alt="" /></a> <strong>Features:</strong></p>

<ul>
<li>Full session list stored locally, so it will work when you have no wifi or signal</li>
<li>Includes the title, full description, room, time and presenter of every session</li>
<li>The welcome screen gives you a heads up of your next session</li>
<li>A &#8220;My Schedule&#8221; view, once you&#8217;ve selected the sessions you want to attend you can see them all at a glance.</li>
</ul>


<p>It&#8217;s nothing ground breaking, or pretty :), but I hope you find it useful.
You can download it from:</p>

<p><a href="https://market.android.com/details?id=com.havedroid.dddsched">Market Link</a></p>

<p>And the source is up at <a href="https://github.com/Dotnetwill/DDDNorth-Schedule-Android">https://github.com/Dotnetwill/DDDNorth-Schedule-
Android</a> so if you
want to add features you&#8217;re more than welcome just send me a pull request!</p>

<p><strong><strong>Disclaimer</strong> </strong>Although I use the official DDDNorth logo and colours this is 100% unoffical so please direct all complaints and issues to me, not the wonder DDDNorth team :)</p>

<h2>My Session</h2>

<p>My session is an introduction to Android development from my .Net perspective,
I&#8217;m going to go over the basics you need to get an internet facing application
up and running using Java and the Android SDK.  I&#8217;ll cover, roughly,
Activities, basic XML layout, AsyncTask, Intents, permissions, list adapters
and, of course you can&#8217;t miss, context.  Along the way I&#8217;ll share with you
bits of Java that have caught me out or are relevent to help get these things
done.</p>

<p>If you&#8217;ve written an Android application I doubt there is going to be much
there for you.  If you&#8217;re an experience Java developer I&#8217;ll probably just make
you angry as I butcher the language.  But if you&#8217;ve got experience with .NET
and would like to learn about Android native dev and bare in mind that this
isn&#8217;t best practice or even particular wonderful code then please come and
long and enjoy it.</p>

<p>Hope to see you there!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Update: DirLinker 2.1.1.0]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/12/20/update-dirlinker-2-1-1-0/"/>
    <updated>2010-12-20T08:50:00+00:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/12/20/update-dirlinker-2-1-1-0</id>
    <content type="html"><![CDATA[<p>This morning I have pushed a new version of <a href="http://dirlinker.codeplex.com/releases/view/57839">DirLinker to
Codeplex</a>.  The only
change, a response to <a href="http://dirlinker.codeplex.com/workitem/3">a bug raised on
codeplex</a>, is to allow the entry of
network paths in DirLinker’s UI because it possible to create symbolic links
to network locations on Vista (or later) but the strict validation used would
not allow it.  There is a couple of things to be aware of when creating them:</p>

<ul>
<li>It only works on Vista or later</li>
<li>It can be used for file and folder links</li>
<li>You can not create a link on a network location back to your local machine</li>
<li>If a sym link created on Vista/Server 2008 (or later) is in a shared folder, XP machines will not be able to use it.  As they don’t support sym links, only junction points.</li>
</ul>


<p>As usual don’t hesitate to raise any bugs or give any feedback
<img src="http://www.humblecoder.co.uk.gridhosted.co.uk/wp-%0Acontent/uploads/2010/12/wlEmoticon-smile.png" alt="Smile" /></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[What Makes a Good Code Review?]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/10/13/what-makes-a-good-code-review/"/>
    <updated>2010-10-13T07:14:00+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/10/13/what-makes-a-good-code-review</id>
    <content type="html"><![CDATA[<p>I love code reviews, I really do.  I like having my code looked at and
receiving feedback and I like to look at other peoples to see differing
styles, techniques and library functions I might not be aware of.  But I
always struggle to find the best way to do code reviews.  So I want to take a
look what you need to perform a code review and how to review the code.</p>

<h4>Prerequisites</h4>

<p>Some people are just really bad at writing bug reports and work items (I&#8217;m
looking at you developers) but this is the most important thing you need when
reviewing the code, apart from the code.  You need to able to read the
original bug report and understand it then see the developers analysis and
proposed solution so you know what you&#8217;re looking at when you review it.
Without this it becomes extremely difficult and time consuming to redo all the
work that has already been done to identify the problem.</p>

<p>Leave your style at the door, at the office we don&#8217;t have one complete
standard, we have general rules about casing, and what not, but there isn&#8217;t
one enforced style. I find it really helps to tune out to subtle differences
in style, so long as it&#8217;s readable it really doesn&#8217;t matter.</p>

<h4>The Review</h4>

<p>I like to start with some simple things:</p>

<ul>
<li><strong>Run it - </strong>Check that the bug has been fixed or the work item has been implemented.  Take it through some basic sanity checks with the debugger attached, if possible, with stop on EVERYTHING enabled and see what it does.  No point in reviewing code that doesn&#8217;t do what it&#8217;s meant to do.  If it has unit tests run them, step through a few with the debugger to get a feel for how it&#8217;s meant to work.</li>
<li><strong>Check for build warnings - </strong>Ok that might sound petty, but I generally think warning should be treated as errors.</li>
<li><p><strong>Is it readable – </strong>This is the most important, if you can’t read it how do you expect it to be maintained?  Or you don’t understand the change enough to give it a good review.
By this point we have checked that the code is working and that we understand
it. Now for the hard part, looking at it.  At the business end of a code
review I generally look for the following things (C# specific):</p></li>
<li><p><strong>Delegate Registration – </strong>Whenever I see a delegate being registered I always look for a corresponding deregistration.</p></li>
<li><strong>Resources Being Release – </strong>If a resource (file, db, etc) is opened, make sure it is released again at some point.</li>
<li><strong>General Exception Handling – </strong>I always look for things I know, from experience, are likely to throw and see if there is exception handling around it.  Whenever there is a catch block, I look at how it is dealt with and what is caught.</li>
<li><strong>TryParse v Parse – </strong>Parsing values is always error prone, and we do a lot of it in our codebase, so I’m a stickler for correct exception handling or using the TryParse methods.</li>
<li><strong>Null Checking (or Use of a Null Pattern) – </strong>Defensive coding should be our bread and butter so this should always be present</li>
<li><strong>General WTF-ery – </strong>Anything that makes me utter those three little letters.
I think this covers most points, it’s not an exhaustive list but I think code
reviews are more about checking maintainability than quality, although it
definitely helps with it.</li>
</ul>


<p>When giving feedback I like to try and speak to the person first and ask them
about it, remember one person’s WTF is another person’s complex issue.
Alternatively, I jot a few points down in an email.  I don’t see the need for
a separate code review tool when other forms of communication are effective
and flexible.  Finally, always be constructive, it’s hard to get people to
listen if your just being negative so state your reasons clearly, ask them why
it’s like that and always resist the urge to say “W.T.F is going on here
dude”.</p>

<p>I started off this blog post with a view to clarifying in my own mind how best
to do code reviews, but looking back and rereading my approach I feel there is
room for improvement.  So I ask you my dear readers:  <strong>What do you think
makes a good code review?</strong></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[My Gateway Drug to Professionalism]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/10/11/my-gateway-drug-to-professionalism/"/>
    <updated>2010-10-11T20:35:48+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/10/11/my-gateway-drug-to-professionalism</id>
    <content type="html"><![CDATA[<p>“Have you considered working in another area in software, you don’t seem to
have the right personality type to be a developer”…Said the head of
development sat across the table from me.  I sat, head down, a mere 18 months
out of university having just delivered my first major product release being
told that I was no good at what I do.  I love programming, it has been my
hobby since I got my first computer and it was the only job I’d ever wanted to
do.</p>

<p>As I’m sure you can imagine, I was devastated but not entirely shocked.  You
see I used to rush through a task or bug to get to the next one or get
distracted by something shiny.  The best way I can describe it, is as a Magpie
effect and, as I was being made aware of at that moment in time, developers
are expected to be completer finishers and meticulous to a fault.</p>

<p>I was aware of TDD and I had tried to write some tests but I really struggled
with how to make code testable and good unit tests that didn’t just test
“stuff”.  But this time I was determined to learn more and put it in to
practice, it seemed like the perfect answer.</p>

<h4>Present Day…</h4>

<p>That was nearly two years ago now, I’ve grown massively as a developer since
that day and TDD has been <em>my gateway drug to professionalism</em>. When I started
off with TDD I thought it was about testing but when I look back at my journey
thus far, it&#8217;s about anything but.</p>

<p>One of my biggest problems was rushing, I was always desperate to finish and I
missed things or didn&#8217;t think them through properly.  The first thing that
writing unit tests helped me to do was slow down and break problems into much
smaller chunks.  Just taking a few minutes to consider how best to write the
test normally exposes any concerns that need to be separated, edge cases and
how the class or function will be interacted with.  If I&#8217;m ever struggling to
make a test pass, write a test or if I can&#8217;t make all the tests pass, it
normally means I need to go back and look at the tests to see if I&#8217;m trying to
solve too much in one go or if it has contradictory responsibilities.</p>

<p>The tests provide excellent documentation that is hard to argue with and stays
in step with the code.  This is key because it gives me an insight in to what
I was thinking and how I intended on it being consumed.  It&#8217;s, also, the
closest to an interactive interrupter for C# I have used, which is great for
rapidly checking assumptions and questioning your own code.</p>

<p>Overall it has taught me so much about architecture, design, good practice and
maintainability of code.  One conclusion I have to come is that unit testing
has a very low regression value.  At this moment in time I rarely, if ever,
find bugs using unit tests.  Yes they help to identify failure points but it&#8217;s
not very often I find regressions using them.  All they have done is shifted
the pain point from if the logic works to if it all works together.  My next
challenge is step deeper into the world of the integration testing.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Stop TFS From Telling You “Windows Live Messenger is not running”]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/08/09/stop-tfs-from-telling-you-windows-live-messenger-is-not-running/"/>
    <updated>2010-08-09T11:51:23+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/08/09/stop-tfs-from-telling-you-windows-live-messenger-is-not-running</id>
    <content type="html"><![CDATA[<p>I’ve recently stopped using Live Messenger (moved to Pidgin) and one
unexpected side effect of switching was TFS reminding me every time I went to
Team Explorer that Messenger isn’t running with this lovely error message:</p>

<p><a href="http://www.humblecoder.co.uk.gridhosted.co.uk/wp-%0Acontent/uploads/2010/08/image.png"><img src="http://www.humblecoder.co.uk.gridhosted.co.uk/wp-content/uploads/201%0A0/08/image_thumb.png" alt="image" /></a></p>

<p>For the past few weeks I’ve been living with it, but it’s becoming
increasingly annoying.  So today I finally worked out how to stop it:</p>

<ol>
<li>Go to the Team Members item in Team Explorer and right click on it</li>
<li>Select _Personal Settings _</li>
<li>On the dialog there is a Collaboration setting, change the provider to <em>None</em></li>
<li>Be free of annoying dialog.</li>
</ol>


<p>Hope this helps some else regain their sanity
<img src="http://www.humblecoder.co.uk.gridhosted.co.uk/wp-%0Acontent/uploads/2010/08/wlEmoticonsmile.png" alt="Smile" /></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Multiple Asserts]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/06/01/multiple-asserts/"/>
    <updated>2010-06-01T17:31:09+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/06/01/multiple-asserts</id>
    <content type="html"><![CDATA[<p>I’ve read many books and blogs that advocate only having one assert in a unit
test and lots of people take that to mean literally assert statement.  I’ve
always disagreed with taking it literally, I’ve always thought of it as one
logical assert, as in you assert one concept at a time which could lead to
multiple assert statements.</p>

<p>The main arguments against having more than one assert statement seems to be
it’s not as readable and it’s sometimes difficult to understand what is
failing because of it.  My normal response is to create my own asserts that
accurately describe what the multiple asserts do and hide the real asserts in
there.  For example:</p>

<pre><code>   1: public void AssertIsValidClone(Customer oldCustomer, Customer actualCustomer)




   2: {




   3:     Assert.AreNotSame(oldCustomer, actualCustomer);




   4:     StringAssert.AreEqual(oldCustomer.Name, actualCustomer.Name);




   5:     StringAssert.AreEqual(oldCustomer.Address, actualCustomer.Address);




   6: }




   7:  




   8: [Test]




   9: public void Clone_ValidCustomer_ValuesAreTheSameReferenceIsDifferent()




  10: {




  11:     //Some setup




  12:  




  13:     var result = aCustomer.Clone();




  14:     




  15:     AssertIsValidClone(aCustomer, result);




  16:     




  17: }
</code></pre>

<p>Ok so this is a very contrived example but we can clearly see what the intent
of the assert is rather than having several making it harder to understand.
But what this doesn’t do is address the second concern. IE anyone of those
three asserts could fail, so we fix it then the next fails, etc.</p>

<p>Enter an nUnit plug in called <a href="http://rauchy.net/oapt/">OAPT</a>, this allows you
to have multi asserts that generate multi unit tests in the runner so you can
see exactly what is failing.  I won’t warble on too much about the details
because it’s all in the link But let’s just rewrite our unit test:</p>

<pre><code>   1: [Test, ForEachAssert]




   2: public void Clone_ValidCustomer_CloneIsNewItemWithValidData()




   3: {




   4:     //some setup




   5:     




   6:     var newCustomer = originalCustomer.Clone();




   7:  




   8:     AssertOne.From(




   9:         () =&gt; Assert.AreNotSame(originalCustomer, newCustomer)




  10:         () =&gt; StringAssert.AreEqual(originalCustomer.Name, newCustomer.Name)




  11:         () =&gt; StringAssert.AreEqual(originalCustomer.Address, newCustomer.Address));




  12: }
</code></pre>

<p>Much more concise and it will run as three separate tests.  I still do have an
issue with it though, each test uses the test name with an appended number. It
would be nice if you could pass in some text for it to append.  But then again
it is open source so maybe I could add that feature myself :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Directory Linker 2.1 – XP Support]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/05/05/directory-linker-2-1-xp-support/"/>
    <updated>2010-05-05T07:23:13+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/05/05/directory-linker-2-1-xp-support</id>
    <content type="html"><![CDATA[<p>Today I have pushed new binaries to <a href="http://dirlinker.codeplex.com">CodePlex for
DirLinker</a>.  This new release brings support
for folder links in Windows XP/2003.  It is not able to create file links,
this is because of the limitations in reparse points in earlier versions of
Windows.</p>

<p>This is something I didn’t think I would do but after releasing Dirlinker 2 on
Codeplex, a ticket was raised in the bug tracker because it was failing on XP
and I was chatting to a friend on IM about it who basically said “Well why
doesn’t it?”.  The main reason was because the API call for creating symbolic
links is only available in Vista and later.  XP does have an equivalent but
the behaviour of the links they create is subtly different.  In XP they are
Reparse Points where as in Vista+ they are hard links (similar to *nix), I
will go in to the difference in a future post.</p>

<p>It turns out that with a little help from <a href="http://www.codeproject.com/KB/files/JunctionPointsNet.aspx">a CodeProject
article</a>, it took
less than an hour to put in and test, so it made it in.  I am definitely
parking this to new features now.  Only bug fixes will be added from now on.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Directory Linker 2]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/05/03/directory-linker-2/"/>
    <updated>2010-05-03T08:14:50+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/05/03/directory-linker-2</id>
    <content type="html"><![CDATA[<p>After literally months of procrastination Directory Linker 2 is finally in
state that I’m not too ashamed of.  So today I have posted up <a href="http://dirlinker.codeplex.com">new binaries on
Codeplex</a>.</p>

<h3><strong>What’s New?</strong></h3>

<ul>
<li><strong>Undo Support</strong> <strong>–</strong> If the process of moving and deleting a folder before creating a link at the same location failed, you could end up with some files in the new location, some in old and two partial directory structures.  If this happens now DirLinker will offer to put the original folder back how it was.</li>
</ul>


<p>If you’re using the just delete option and it fails, undo <strong>can not</strong> undelete
any files but it will put back any folders it deleted.</p>

<ul>
<li><strong>File Links</strong> – It can now create symbolic links for files as well as directories.  You don’t have to do anything different, just select a file in the link location or the link to field.  There has been a small change to the UI to allow you to browse for files aswell as folders.</li>
</ul>


<p>In a future post I’m going to talk about the difference between symbolic links
and shortcuts.  But for now the important difference is the application
opening file doesn’t know the file is only a link when using symbolic links.</p>

<ul>
<li><strong>Progress Window Changes – </strong>The progress window has been slightly overhaul and now keeps a list of everything it has done.  So if it does fail or something goes wrong, you can work out exactly what it’s done.</li>
</ul>


<p><a href="http://www.humblecoder.co.uk/wp-%0Acontent/DirectoryLinker2_AE58/progressWindow.png"><img src="http://www.humblecoder.co.uk/wp-content/DirectoryLinker2_A%0AE58/progressWindow_thumb.png" alt="Progress Window" /></a></p>

<p>With these features I’m planning on parking Directory Linker development, I
will of course fix any bugs that may come up but I can’t see any new features
being added.</p>

<p>Enjoy!</p>

<p>PS, If you have no idea what Directory Linker is, <a href="http://www.humblecoder.co.uk/?p=50">this
is</a> a good place to start.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Visual Studio Versions || .Net Versions != C# Version]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/04/18/visual-studio-versions-net-versions-c-version-2/"/>
    <updated>2010-04-18T10:47:35+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/04/18/visual-studio-versions-net-versions-c-version-2</id>
    <content type="html"><![CDATA[<p><strong>Update</strong> Generic variance can be used (and a couple of other things) when multi targeting see here: <a href="http://blogs.msdn.com/ed_maurer/archive/2010/03/31/multi-targeting-and-the-c-and-vb-compilers.aspx">http://blogs.msdn.com/ed_maurer/archive/2010/03/31/multi-targeting-and-the-c-and-vb-compilers.aspx</a></p>

<p>I’m finally getting stuck into finishing off
<a href="http://dirlinker.codeplex.com">DirLinker</a> 2.0 and with VS2010 being released
I decided to upgrade the project to VS2010 still targeting .NET 3.5 for
compatibility.  While enjoying the new IDE features, I discovered some of the
C# 4.0 features work when targeting .NET 3.5.</p>

<h2>#</h2>

<h3><strong>Optional and Named Parameters</strong></h3>

<p>This is something I’ve been looking forward to, I think it will make my code
prettier by removing the ridiculous number of overloads you can some times end
up with.  I’m not going to explain the feature because it has been well
covered by better writers than I :).  So imagine my surprise when I discovered
I could use this feature while targeting .NET 3.5.  Just to test the theory I
wrote the following console application and targeted it at .NET 2.0:</p>

<pre><code>static void Main(string[] args)
{
    FunctionCalledUsingNamedParams("str1", "str2");
    FunctionCalledUsingNamedParams(String2: "str2", string1: "str1");  
    FunctionWithTwoOptionalParams();
    FunctionWithTwoOptionalParams(200);
    FunctionWithTwoOptionalParams(56, "Called from main");
    FunctionWithTwoOptionalParams(message: "test", number: 29);  
    Console.ReadKey();
}  
static void FunctionCalledUsingNamedParams(String string1, String String2)
{
    Console.WriteLine(String.Format("{0} : {1}", string1, String2));
}  
static void FunctionWithTwoOptionalParams(Int32 number = 1, String message = "default message")
{
    Console.WriteLine(String.Format("{0}: {1}", message, number));
}
</code></pre>

<p>This compiles, runs and outputs the correct information just fine.  I even ran
it to a machine that had never seen .NET 4.0 to be sure.  It would appear it’s
C# 4.0 feature not a .NET 4.0 feature.  I have only tried this with optional
params but I doubt that dynamic <strike>and co/contra-variance will
work</strike>, I think the general rule is if it doesn&#8217;t require the Base
Class Library or CLR support then it will work.</p>

<p>(The source for app along with a compiled version is available
<a href="http://bitbucket.org/humblecoder/BlogPostCode/">here</a> )</p>

<h3><strong>Of Course This is Not New </strong></h3>

<p>Within the past 12 months my work place has moved to VS2008 from VS2005 but
still targeting .NET 2.0.  One of the things I quickly discovered was that
lambdas, auto properties and  object initialization syntax all still works
perfectly when targeting .NET 2.0 from VS2008.  Making them a feature of C#
3.0 not .NET 3.5!</p>

<p>So it’s important to remember this simple expression:</p>

<p><strong>Visual Studio Version || .Net Version != C# Version</strong></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why Can’t TFS Remember My Credentials?!]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/03/29/why-cane28099t-tfs-remember-my-credentials/"/>
    <updated>2010-03-29T13:45:09+01:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/03/29/why-cane28099t-tfs-remember-my-credentials</id>
    <content type="html"><![CDATA[<p>At the office we use TFS and it pesters me for credentials every time I start
Visual Studio because I’m not on the domain.  This does quickly become very
tiresome.</p>

<h3><strong>Solution</strong></h3>

<p>I set about trying to cache my credentials this morning after, mixed with a
case of the Mondays, I’d finally had enough with it pestering me.  The dialog
does not have any <em>remember my password option</em> so the next stop is to save it
in my Windows Profile.  To do this:</p>

<ol>
<li>Open “Control Panel”</li>
<li>Go to “User Accounts” and select the option “Manage your network passwords”</li>
<li>In the dialog enter the path to your TFS server and your credentials, for example
<a href="http://www.humblecoder.co.uk.gridhosted.c%0Ao.uk/wp-content/uploads/2010/03/AddNetworkPassword1.png"><img src="http://www.humblecoder.co.uk/wp-content/uploads/2010/%0A03/AddNetworkPassword1-271x300.png" alt="Add Network Password" /></a></li>
</ol>


<p>This worked great for Visual Studio but I still had to log into the TFS
Sharepoint portal site every time.  I discovered you also have to enter the
TFS server address into the “Intranet Zone” in “Internet Options”.  To do
this:</p>

<ol>
<li>Open “Control Panel”</li>
<li>Go To “Internet Options” and select the “Security” tab</li>
<li>Then select “Intranet Zone” and click on the “Sites” option</li>
<li>Now enter the address of the TFS server, for example:
<a href="http://www.humblecoder.co.uk.gridhosted.co.uk/wp-%0Acontent/uploads/2010/03/intranetZone1.png"><img src="http://www.humblecoder.co.uk/wp-content/uploads/2010/03/intr%0AanetZone1-300x196.png" alt="Intranet Zone" /></a></li>
</ol>


<p>Then you should never be harassed again :)  This works / is needed on Sever
2008 and Vista, as per usual the story is a lot better under Win 7 and Server
2008 R2.  It’s just a shame my main development VM is 2008 and I don’t have
time to reimage it.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[OCInject Release 2]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/03/22/ocinject-release-2/"/>
    <updated>2010-03-22T10:00:02+00:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/03/22/ocinject-release-2</id>
    <content type="html"><![CDATA[<p>When I originally <a href="http://www.humblecoder.co.uk/?p=102">released OCInject</a> I
omitted one important feature, lifestyle management.  This coupled with the
release of a <a href="http://www.grumpydev.com/2010/03/02%0A/announcing-tinyioc-an-easy-to-use-hassle-free-inversion-of-control-%0Acontainer/">feature full TinyIOC</a> has made me re-evaluate my position on not adding too many
features to OCInject.  Release 2 of OCinject brings the following features:</p>

<ul>
<li><strong>Life style management</strong> – It’s possible to register types as singletons or instance</li>
<li><strong>Func<T> factories</strong> – OCInject from day one supported delegate factories, now you can use Func<TContract> instead of typed delegates</li>
<li><strong>Simplified Registrations – </strong>In the previous release of OCInject types are registered using TContract –> TImplemenation to enforce programming to interface.  It’s now possible to register with TContract as the concrete type with one call</li>
<li><strong><strong>Largest Resolvable Constructor</strong> – </strong>In the previous release of OCInject it simply grabbed the first constructor it found.  It will now select the greediest constructor it can resolve.  It makes the assumption that <em>any known types are resolvable</em>, for performance reasons.</li>
<li><strong>Unresolveable Callback</strong><strong> – </strong>It is now possible to supply a call back function if the container can’t resolve a type.</li>
<li><strong>Child Container Support – </strong>OCInject can create child containers that call back to the parent for any unknown types. </li>
</ul>


<p>The latest stable version can be downloaded from
<a href="http://ocinject.codeplex.com">Codeplex</a> and all stableish development
releases can be found at
<a href="http://bitbucket.org/humblecoder/ocinject">BitBucket</a>.</p>

<h2>#</h2>

<h3><strong>Future Features</strong></h3>

<p>One major feature still missing from OCInject is named registrations.  This is
because I personally dislike ‘magic strings’, with this in mind a planned
future feature of OCInject is factory delegate registration only.  Also, auto
generated factories from interfaces.  More to come on this in a future post.</p>

<h3><strong>Life Style Management</strong></h3>

<p>By default all types registered with the OCInject container are transient. You
can register a type as singleton in two ways.  The first method is to use
<em>.AsSingleton() </em>this will cause the object to be created the first time it is
requested.  The second method is to use <em>.AlwaysReturnObject(obj), </em>this will
return the instance you specified.   When using either method, if the type
implements IDisposable it will be disposed when the container is.  Usage
example:</p>

<pre><code>ClassFactory container = new ClassFactory();  
//Normal Singleton
container.RegisterType&lt;TestClass&gt;()
           .AsSingleton();  
//Preconstructed Singleton
AnotherClass instanceOfAClass = new AnotherClass();  
container.RegisterType&lt;TestClass&gt;()
         .AlwaysReturnObject(instanceOfAClass);
</code></pre>

<h3><strong>Func<T> Factories</strong></h3>

<p>When resolving constructors if OCInject discovers a Func<T> where T is a
registered type, it will pass in a func to create the type.  This uses the
standard container resolve, so if T is a singleton you will always get the
same instance when the factory is called. Usage example:</p>

<pre><code>class FuncConsumer
{
    public FuncConsumer(Func&lt;TestClass&gt; factory)
    {
    }
}  
ClassFactory container = new ClassFactory();  
container.RegisterType&lt;FuncConsumer&gt;();
container.RegisterType&lt;TestClass&gt;();  
//Successfully created with the ability to create TestClass
FuncConsumer f = container.ManufactureType&lt;FuncConsumer&gt;();
</code></pre>

<h3><strong>Simplified Registrations </strong></h3>

<p>Registrations no longer require the separation of contract and implement so
just an implementation can be registered.  Usage example:</p>

<pre><code>ClassFactory container = new ClassFactory();  
container.RegisterType&lt;TestClass&gt;();  
var t = container.ManufactureType&lt;TestClass&gt;();
</code></pre>

<h3><strong>Largest Resolvable Constructor</strong></h3>

<p>This is quite a complicated area that is worthy of a blog post itself but
OCInject’s behaviour has changed.  When creating a type the constructors are
ordered so the largest, in terms of parameters, is first.  It then looks at
each parameter and to see if it can resolve it, first by checking ‘resolve
time args’ (values passed in when the resolve is requested, normally from
generated factories) then by seeing if the type is a registered contract
within the container.   <strong>It does not check if the type can be created just
that it knows about it, if it’s registered it assumes it can be created.</strong></p>

<p>The first completely resolvable constructor will be used to construct the
type.</p>

<h3><strong>Unresolveable Callback</strong></h3>

<p>If the container is unable to resolve the type you can now register a function
that is called before the container throws an exception.  To do this you need
register a <em>Func&lt;Object, Type></em> with the <em>CallToResolve </em>propriety.  Returning
null will cause the container to throw an exception.  Usage example:</p>

<pre><code>ClassFactory container = new ClassFactory();  
container.CallToResolve = (type) =&gt; { return new TestClass(); };  
ITestClass manufacturedType = factory.ManufactureType&lt;ITestClass&gt;();
</code></pre>

<h3><strong>Child Container Support</strong></h3>

<p>Calling <em>CreateChildContainer() </em>will return a new <em>ClassFactory </em>object with
no registrations but a link back to the parent.  If a type is not known to the
child it will ask the parent to fulfil the request.  Any registrations with
the child will not effect the parent and singletons registered with the child
will be disposed when it is. Usage example:</p>

<pre><code>ClassFactory container = new ClassFactory();
ClassFactory child = factory.CreateChildContainer();
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA["hg push -b default" is Massively Handy]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/03/22/hg-push-b-default-is-massively-handy/"/>
    <updated>2010-03-22T06:56:53+00:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/03/22/hg-push-b-default-is-massively-handy</id>
    <content type="html"><![CDATA[<p>A little while ago I wrote a <a href="http://www.humblecoder.co.uk/?p=113">quick start guide to branching in Mercurial</a> and, as is normally the case when you
don’t actively follow development, Mercurial 1.5 has been released with a
lovely new feature which impacts working with branches.</p>

<p>My biggest annoyance when working with branches is by default <strong>all</strong> branches
are pushed/pulled to the remote repository.  When in reality, I often want to
just push the branch I’m currently on.  Mercurial addressed this by adding a
branch only option to Push, Pull, Clone, Incoming and Outgoing.  To use the
branch only option you append –<em>b </em>to the command followed by the branch name,
for example:</p>

<pre><code>hg push -b default
</code></pre>

<p>This will only push the default branch back to where the repository was cloned
from (You can still specify a location to push to if required.)  This works
exactly the same for all the other commands.</p>

<p>A handy shortcut to push the current branch is use ‘.’ as the branch name:</p>

<pre><code>-b .
</code></pre>

<h2>#</h2>

<hr />

<p>This will perform the command only to the branch you’re currently on.  Since I
tend to push more than I do most of the others, I have set up an alias to map
push current branch to <em>pc.  </em>You can do this by adding a section to your
<a href="http://www.selenic.com/mercurial/hgrc.5.html">hgrc</a> like:</p>

<pre><code>[alias]
pc = push -b .
</code></pre>

<h3><strong>Branching Without Having It In Your History</strong></h3>

<p>Cloning locally has always been an option to create a branch or fork of the
code that is still linked to the original code base, IE you can push and pull
to it, but it doesn’t become part of your history in the other repo unless you
pushed it back.  But I’ve never liked it because it takes a copy of everything
and sets the current branch to the default branch.  Trivial, maybe, but not
something I found desirable.</p>

<p>The new branch options makes cloning locally a lot more attractive to me.  It
means I can just clone a branch, make a quick change or two and either merge
it back in or delete the directory and pretend I never had that idea!</p>

<h3>****</h3>

<h3><strong>Powershell and Mercurial</strong></h3>

<p>As part of my continuous improvement I’ve been learning PowerShell.  One way
I’ve done this is by replacing all my cmd.exe usage with the PowerShell prompt
instead.  This led me to discover an excellent cmd-let (script or whatever the
proper name is, I’m still learning :)) to display the name of the current
branch and status of it when you’re in a Mercurial repository.  It looks like:</p>

<p><a href="http://www.humblecoder.co.uk.gridho%0Asted.co.uk/wp-content/uploads/2010/03/ps.png"><img src="http://www.humblecoder.co.uk.gridhosted.co.uk%0A/wp-content/uploads/2010/03/ps_thumb.png" alt="Powershell Status Display" /></a> More information can be found
about this <a href="http://www.learnaholic.me/2009/12/24/powershell-prompt-with-%0Amercurial-status/">here</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Passing Reference Types Using Ref, Take Two]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/03/16/passing-reference-types-using-ref-take-two/"/>
    <updated>2010-03-16T11:42:44+00:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/03/16/passing-reference-types-using-ref-take-two</id>
    <content type="html"><![CDATA[<p>In <a href="http://www.humblecoder.co.uk/?p=121">my last post</a> I talked about passing
reference types using the ref keyword but it didn’t make a lot of sense.  So I
just want to go over it again, hopefully making a bit more sense.</p>

<p>When a method is called in C# a <strong>copy </strong>of the all parameters are given to
the method.  This is fairly obvious with value types because if we change the
value of an int, for example, the caller does not get the updated value.</p>

<p>However this is not so clear for reference types.  The called method can
update the state of the object it was passed, for example append extra data to
a StringBuilder, and the caller’s object will have these updates.  This can
lead to confusion about what is really happening, it looks as if the
StringBuilder was passed by reference but a copy of the reference to it was
taken.</p>

<p>It maybe subtle semantics under normal use but it becomes key to understanding
behaviour when the <em>ref</em> keyword is used.  For value types this means that if
we increment an int we are passed, the caller will have the new value too.
For reference types the reference we are passed is actually a reference to the
caller’s reference. Meaning if we assign a new reference to it, the caller
will get the new reference.</p>

<p>We can demonstrate this with the following code:</p>

<pre><code>static void Main(string[] args)
{
    StringBuilder sb = new StringBuilder();
    sb.AppendLine("Added by Main");  
    AddToSBPassedAsNormal(sb);
    Console.Write(sb.ToString());
    //Output: Added by Main
    //        AddToSBPassedAsNormal  
    AddToSBPassedByRef(ref sb);
    Console.Write(sb.ToString());
    //Output: AddToSBPassedByRef  
    AddToSBPassedAsNormalNewUsed(sb);
    Console.Write(sb.ToString());
    //Output: AddToSBPassedByRef  
    Console.ReadLine();
}  
private static void AddToSBPassedAsNormal(StringBuilder sb)
{
    sb.AppendLine("AddToSBPassedAsNormal");
}  
private static void AddToSBPassedByRef(ref StringBuilder sb)
{
    sb = new StringBuilder();
    sb.AppendLine("AddToSBPassedByRef");
}  
private static void AddToSBPassedAsNormalNewUsed(StringBuilder sb)
{
    sb = new StringBuilder();
    sb.AppendLine("AddToSBPassedAsNormalNewUsed");
}
</code></pre>

<p>From the code above we can see that the StringBuilder after the first method
contains both strings.  But after the method call, where it is passed by ref,
the previously entered data has been lost and, finally, using new when not
being passing by reference has no effect on <em>Main()</em>’s reference to the
StringBuilder.</p>

<p>Before passing a reference type using the <em>ref </em>keyword you must think
carefully about the implications of the caller changing the reference.  As it
can lead to some esoteric and difficult to track down bugs.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[C# Basics: Ref’ing References, Ref’ing Hell]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/03/12/c-basics-refing-references-refing-hell/"/>
    <updated>2010-03-12T23:20:33+00:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/03/12/c-basics-refing-references-refing-hell</id>
    <content type="html"><![CDATA[<p>For the past couple of weeks I’ve been deep in some legacy code.  The code has
all kind of hidden charms, while I’m not going to be overly critical because
it was written at a time when a .NET 2.0 application was cutting edge.  I
uncovered this gem:</p>

<pre><code>public void SomeHighLevelFunction(out String feedback)
{
    StringBuilder mySb = new StringBuilder();  
    _WorkerItem1.DoWorkOne(ref mySb);
    _WorkerItem2.DoWorkTwo(ref mySb);
    _WorkerItem3.DoWorkThree(ref mySb);  
    feedback = mySb.ToString();
}
</code></pre>

<p>Ignoring the void with the out String, why pass the StringBuilder by ref?
This code was written by a migrating C++ programmer; if you’ve worked with C++
at all a little light bulb may have just gone off for you.  It works, even
though it might be the very definition of programming by coincidence, so why
is this so bad?</p>

<h3>#</h3>

<h3><strong>Why So Bad?</strong></h3>

<p>When calling a method in C# all parameters are passed by value.  It is a
common misconception that reference types are passed by reference when they
are infact passed by value.  This backs up the position of the C++ programmer,
so what is the difference?</p>

<p>C# and its documentation has no concept of pointers (outside of IntPtr) when
they are used extensively under the hood.  When you call a method and pass a
reference type you are actually passing a pointer (that lives on the stack) to
a memory location on the heap.    The pointer is copied so you can still
manipulate the memory but you can’t affect the reference.  <a href="http:%0A//bitbucket.org/humblecoder/blogpostcode/src/22e29d9b8ae8/RefDemo/">For example</a>:</p>

<pre><code>static void Main(string[] args)
{
    StringBuilder sb = new StringBuilder();
    sb.AppendLine("Added by Main");  
    AddToSBPassedByRef(ref sb);
    AddToSBPassedAsNormal(sb);  
    Console.Write(sb.ToString());  
    Console.ReadLine();
}  
private static void AddToSBPassedByRef(ref StringBuilder sb)
{
    sb = new StringBuilder();
    sb.AppendLine("Added by AddToSBPassedByRef");
}  
private static void AddToSBPassedAsNormal(StringBuilder sb)
{
    sb = new StringBuilder();
    sb.AppendLine("AddToSBPassedAsNormal");
}
</code></pre>

<p>Has the output of:</p>

<pre><code>Added by AddToSBPassedByRef
</code></pre>

<p>This could be confusing to a C++ developer because all classes, in C++, are
created on the stack unless you declare a pointer and use <em>new </em>to create them
on the heap.  Having said that a simple rule applies to both to C# and C++, if
you have to use <em>new </em>it gets created on the heap and everything else is
created on the stack.  Anything on the stack, value types or reference types,
is copied between method calls.</p>

<p></rant></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Pair programming, Peach or Plum?]]></title>
    <link href="http://humblecoder.co.uk/blog/2010/03/09/pair-programming-peach-or-plum/"/>
    <updated>2010-03-09T20:44:51+00:00</updated>
    <id>http://humblecoder.co.uk/blog/2010/03/09/pair-programming-peach-or-plum</id>
    <content type="html"><![CDATA[<p>I’m currently in my third week of pair programming and I wanted to talk about
some of my experiences, both positive and negative.  I pushed for a pair
programming ‘experiment’ at work but I was dubious as to its value and
usefulness in the cut and thrust world of professional software development.
So the justification for it seems a good place to start.</p>

<h3><strong>Two Expensive Resources Working Slower, Yeah Right!</strong></h3>

<p>Let’s not beat about the bush, pair programming means that two expensive
resources, developers, are tied up on a task without necessarily bringing two
‘man days’ to a task.  What pair programming aims to do is reduce the overall
cost of ownership of code.  It can work as a mentoring technique to develop
less experienced programmers but this maybe defeating the object of the type
of pair programming that really brings value.</p>

<p>In a traditional software development lifecycle the cost of fixing a bug rises
exponentially as you move through the software’s (or feature’s) lifecycle.
I’m sure we’ve all seen a graph similar to below at some point in our careers.
It shows the costs of fixing a bug versus the stage development is currently
in.</p>

<p><a href="http://www.humblecoder.co.uk.gridhosted.co.uk%0A/wp-content/uploads/2010/03/costCurve3.gif"><img src="http://www.humblecoder.co.uk.gridhosted.co.uk/wp-content/upload%0As/2010/03/costCurve3_thumb.gif" alt="costCurve3" /></a></p>

<p>The aim of pair programming is to raise the costs slightly at the start, with
a view to reducing the sharp curve towards the end.  So we end with a smoother
curve and we spend list time in the costly area of the graph.</p>

<h3><strong>The Good, the Bad and the Ugly</strong></h3>

<p>My experience has been overwhelmingly positive, but the ones that stick out
the most are:</p>

<ul>
<li><strong>More Focused – </strong>I’ll admit I have problems concentrating at times, I’ll see a tweet, Google something related to what I’m doing and find an interesting blog, etc.  Working in a pair has really focused me on the task at hand and I think I’m more productive.</li>
<li><strong>Less Rabbit Holing – </strong>I’ve found just verbalising my ideas about what I want to do with a design, refactoring or while investigating a bug helps to work out problems or see things I’ve missed.  Also, the navigator can ask questions about less clear areas.  All leading to a better design, bug fix, etc.</li>
<li><strong>Differing Styles – </strong>Participating in or watching someone else&#8217;s thought process has helped show me areas where I could improve and given me new approaches to try when blocked.</li>
<li><p><strong>Naming – </strong>One thing I struggle with at times is how best to name things to best express my intentions, having a partner to ask “this is what this does, do you think that’s descriptive?” .  All this leads to better and more maintainable code.
The not so good:</p></li>
<li><p><strong>Breaks – </strong>It can be awkward to be stuck to someone else&#8217;s brew up times, smoke breaks, lunches, etc.  It can break the flow and make it feel like you’re spending time waiting on others.</p></li>
<li><strong>Thinking Time – </strong>This is very subjective and probably should be a pair activity, but sometimes when confronted with difficult to understand legacy code, a strange bug or just several choices.  It’s nice to go through your ritual, whether that be listen to your favourite music, rock the water cooler or chat to that cute girl in marketing, it all has the same outcome you feel better and have had thinking time.  I’ve found this particular hard when your partner is looking, listening, questioning and <strong>waiting</strong> for you to carry on.
Overall, it’s definitely been a worthwhile experience and one that I will be
continuing.</li>
</ul>


<h3><strong>Remember It’s Not For Everyone</strong></h3>

<p>We’ve been careful to explain to people that it is not an experiment with a
view to introducing it across the team, just something we wanted to do.  It
started off with just two of us but a third has joined with one or two more
interested in joining if the opportunity came up.  But it’s important you
don’t force the issue.  For it to be a success you need people who:</p>

<ul>
<li><strong>Check their ego at the door – </strong>There is no room for “this is the way I do it and it’s the right way” one of the biggest take aways for me has been learning from someone else’s style and approach, even if I disagreed.</li>
<li><strong>Are Interested</strong> – This is so important, for the navigator role to work well the person needs to want to do it.  Not just be sat thinking “God, when can I drive”.</li>
<li><strong>Be Strong – </strong>I have a strong personality and it can over power people around me.  As much as I’ve tried to rein it in when working with less strong personalities, it’s still important the other person is strong and is willing to defend their opinion.</li>
</ul>

]]></content>
  </entry>
  
</feed>
