Coding


Realised it’s Friday morning and I am doing something that I do most Fridays that I thought I’d share. Cleaning up my working copies. Whilst this should not ever be too much of an issue I am a bit retentive about being able to drop into any of our projects and be quickly up to date.

Subversion is iterative about how it works; if you Update frequently they are short processes. If you have not touched the repository for a while and you have uncommitted changes they can take a while! The process never takes to long when I keep “my room” tidy.

My programming day is very rarely all success or all disappointments; in truth it probably looks like a sine wave with a very high frequency. Over the course of my career, I have become better at noticing and dealing with how these successes and disappointments affect me as a person.

When I have taken a few disappointments on the chin in any given period, I will often revisit my unit tests and refactor them to make them more clear and readable and then jump back at the task at hand. Sometimes I will notice how to improve the test to be more effective as well. I find this practice has two tangible benefits. Firstly, my tests across time become clearer, more concise and more effective as I tweak them. Secondly, the “refactor / run tests” cycle gives me some easy wins and set me back on my way in a much better frame of mind.

Finally got on to twitter!

Thanks very much to Scott Hanselman and his blog post here.

I hope to put our build server on later in the day!

I had a torturous time trying to connect my new Windows Server 2008 (x64) install to the VPN at work. It just wouldn’t play dice. Thus far my best solution is an XP Pro (x86) VM. Whilst not being able to from the x64 box directly, I can still Remote Desktop the work box and mount network shares. Glad to be back in business (ED: Poor pun!)

This weekend I have been evaluating  Castle’s ActiveRecord as an object relation mapping solution. It is built upon NHibernate and is an implementation of the active record design pattern.

After browsing the quick start documentation and a couple of trips to Google, I had a simple object mapped to a table and was happily completing operations within my applications controller using Castle’s friendly syntax.

My first thoughts have been very positive. I had much less to do in the way of configuration than when using NHibernate on it’s own. This held true for both the general configuration (Indeed, ActiveRecord did not require any alteration of the web.config at all!) and on an object to object basis as mapping is done by the assigning of ActiveRecord attributes to the properties of the corresponding class (No more XML mapping files to maintain.)

Out of the box, Microsoft’s new code analysis tool (Style Cop) did not play with the firmly entrenched ReSharper in my Visual Studio IDE. However, a quick dash to CodePlex yielded a plug-in for ReSharper that had me back in business in minutes.

My first take on Style Cop was that it was a great deal of commenting and a new place for my using directives. Feeling a little affronted by the 199 warnings my ASP.NET MVC spike project generated on the first scan, I changed Studio to treat warnings and errors, made a cup of coffee and set about it.

I am pedantic. My wife is a saint as she lives with me and has yet to seriously hurt me and to my knowledge not on purpose, yet. This trait is either a symptom of my trade or a cause. There is a small amount of shame welling in me as I try to convey to you how much I adored the code I produced in the next couple of hours. It did not do anything different functionally (well some tiny bits) but it looked shiny. It was the type of code that I wish to encounter in projects that I work upon.

Style Cop is a winner with me! I heartily recommend trying it; if you have not already.

The senior technical lead in my department, Barry, has instructed me to add it to our build process. The way he put it, and I paraphrase was “I don’t agree with everything it suggests; but I’ll accept it for the standard of code it enforces others to produce.” I must concur!

If he is aware of just how number of times I end up on martinfowler.com, I am sure the premier Calgarian geek might think I am virtually stalking him.

Today’s foray was to find out more about fluent interfaces and method chaining. I have been using Phil Haack’s HttpSimulator quite heavily in the last few days and want APIs that I write to be as easy to use and part of such readable code.

For example:

using (HttpSimulator simulator = new HttpSimulator())
{
  simulator
   .SetFormVariable("Test1", "Value1")
   .SetFormVariable("Test2", "Value2")
   .SimulateRequest(new Uri("http://localhost/Test.aspx"));
}

Next Page »