@ayende You ought to try Mercurial. in reply to ayende 2 weeks ago

May 2009

30
May

Sorry, but I am not a SharePoint expert

I’ve just been taking a look to see who’s following me on Twitter, and it seems that I’ve picked up a handful of SharePoint developers along the way. No doubt this stems from the fact that two of my most popular blog entries are SharePoint posts, almost entirely due to the fact that they feature rather prominently in various Google searches of a SharePointesque nature. It makes me wonder if I’ve unwittingly picked up a bit of a reputation as something of a B-list SharePoint guru.

Well I’m sorry to disappoint you folks, but I’m not one.

Those particular blog entries were actually my initial impressions of the first, and so far the only, SharePoint project I have ever worked on. I had only the vaguest idea of what I was doing and most of my SharePoint efforts at the time were firmly in the “cargo cult” category, as they generally are when you’re plunged in at the deep end with a new, unfamiliar and complex technology, no training, and a tight deadline. Furthermore, neither of them were intended as knowledge base type articles, but as rants — one of them about insanely over-complicated functionality and the other about an idiotic MSDN knowledge base article that didn’t work.

Now I have no idea what effect this post is going to have on my Feedburner subscriptions and Twitter following. If you fall into that category you’re more than welcome to stick around of course, but I just don’t have anything more to say on the subject. I think my SharePoint skills advanced beyond the cargo cult stage as the project progressed, but since I have not been developing for that particular platform for nearly a year now, I am no longer blogging about it either.

15
May

Inital SQL files breaking in Django syncdb

There’s a fairly long-standing bug in Django where initial SQL files break if they contain a double hyphen in a quoted string when you run manage.py syncdb. This bug also causes problems if you’re trying to create stored procedures in MySQL and need to change the delimiter to allow multiple statements.

Seems the problem is some overly naive code to split the SQL file into individual statements. Unfortunately there’s no easy fix without at least partially reinventing the SQL parser or spawning a separate mysql command line client process. Best approach in the meantime is to avoid using stored procedures and check any scripts that you do have using Django’s unit test framework.

11
May

Reinventing the wheel, badly

A few years ago, I inherited a VB.NET application in which every method (many of which were four hundred lines long, copied and pasted all over the place, and peppered with vague sounding variable names such as blnRunIf and blnRunElse) contained this boilerplate code:

Sub MyMethod()
    Try
        '
        ' ** snip ** '
        '
    Catch ex As Exception
        Throw New Exception ("MyClass.MyMethod::" + ex.Message)
    End Try
End Sub

Those who do not understand Exception.StackTrace are doomed to reinvent it, badly.

07
May

Rear airflow rucksacks are a nice idea, but…

My daily commute consists of a fifteen minute bike ride to Horsham station, fifty-five minutes on the train into London, and a twenty minute walk from London Victoria to the place where I spend most of my day staring at a computer screen before repeating the process in reverse. When you’re spending a little over three hours a day getting from A to B and back again, it’s essential to have a suitable means of humping your assorted bits and pieces around, so before I embarked on this particular adventure, I paid a visit to Millets in Horsham town centre and bought myself a rucksack that I thought would fit the bill perfectly.

Rear airflow rucksackAt the time I thought the rear airflow system of the Berghaus Freeflow 20 rucksack was a bit of a killer feature. My old rucksack (which was ten years old and falling to bits) had been giving me a sweaty back on my bike all summer, and I figured that since my daily quota of exercise was just about to double, anything to reduce that effect would be more than welcome.

Unfortunately, this comes at a price. The struts that hold it away from your back seriously reduce the amount of space that you have at your disposal. Most of the time it isn’t too bad, but sometimes it seems very inflexible somehow. There are occasions when I want to be able to take a couple of books with me as well as a change of clothes for the journey home if the weather deems it necessary to do so, or maybe even just stop off for some shopping. Thanks to the way they curve away from your back, my Microsoft Natural 4000 keyboard almost refused to fit into it at all. Helpful, that was not.

So last week I went and bought another new rucksack. It’s a different Berghaus model, without the rigid struts this time, which makes it much more flexible, as well as giving it a a slightly higher capacity of 25 litres instead of 20. Despite the lack of air flow between it and my back, so far it hasn’t been making me sweat like crazy, but then again, I have been getting a better diet in recent months than I was a year ago, when I was having KFC for lunch almost every other day.

04
May

Handling exceptions in assembly-level setup methods in MbUnit

MbUnit allows you to run assembly-level setup and teardown methods as part of your unit tests using the AssemblyCleanUpAttribute:

[assembly: AssemblyCleanUp(typeof(AssemblyCleaner))]
public class AssemblyCleaner
{
    [SetUp]
    public static void SetUp()
    {
        // blah
    }
    [TearDown]
    public static void TearDown()
    {
        // blah
    }
}

This is very useful if you want to do something like restore your database to a known configuration, perhaps incorporating all your change scripts into your unit tests. Unfortunately, there is a little gotcha. If your SetUp() method throws an exception, none of your unit tests will run, but MbUnit will still report success.

For what it’s worth, I think this is a bug, not a feature, but there is a way round it. Capture any exception, and create a unit test that re-throws it:

[assembly: AssemblyCleanUp(typeof(AssemblyCleaner))]

public class AssemblyCleaner
{
    private static Exception setupException = null;

    [SetUp]
    public static void SetUp()
    {
        try {
            // blah
        }
        catch (Exception ex) {
            setupException = ex;
        }
    }

    [TearDown]
    public static void TearDown()
    {
        // blah
    }

    internal static void RethrowSetupException()
    {
        if (setupException != null) {
            // Wrap the original exception to preserve its stack trace
            throw new InvalidOperationException(
                "An error occurred when setting up the tests",
                setupException);
        }
    }
}

// You need to have your unit tests in a separate class.
// MbUnit doesn't like you including test fixtures
// in your assembly cleanup class.

[TestFixture]
public class AssemblyCleanerTest
{
    [Test]
    public void ReportSetupException()
    {
        AssemblyCleaner.RethrowSetupException()
    }
}