July 2009 Blog Posts

Simple organisational improvements: Remember the alphabet

Software contains many examples where a number of named items must be listed in a context where the order is not important. This is particularly prevalent in configuration files but is also found in code. One example I’m currently looking at is a set of WCF service host classes that need to be run in a service. The order they start is irrelevant as long as they are all started. As there are a number of types it’d be nice if I didn’t have to scan the list every time I wanted to see if something was included. This...

posted @ Wednesday, July 22, 2009 2:37 PM | Feedback (0)

On the addressing of pain points

One of the criteria I have for separating true software developers from the hack and slash crowd is how someone goes about addressing the deficiencies and inefficiencies in their project. A project with a real software developer will see the number of pain points decrease over time, leading to higher efficiency and an easier to work with system. So what is a pain point? I define a pain point as any element of the system or its development environment that is unnecessarily complex, time-consuming or fragile. Pain points are the things that get between the development team and the...

posted @ Wednesday, July 22, 2009 12:43 AM | Feedback (0)

Clean the shared state your test uses before it runs

It is an unfortunate reality that it is not feasible to isolate your code from all shared state. Although the use of repositories, wrappers and similar can be used to provide decoupling their user is not always feasible. It is also desirable to test the implementation of the code providing the decoupling which will force us to work with the shared state. From a unit testing perspective shared state may be anything mutable that is visible between the execution of any two tests. This can include static properties, call context, relational databases and file contents. It may also include...

posted @ Tuesday, July 21, 2009 11:13 PM | Feedback (0)

Building Using MSBuild: Part 2

Way back in the deep and distant past I started discussing building systems using MSBuild. And promptly started ignoring the topic. So now I’m back with the build file I’m currently using in one of my personal projects. This build file is designed to version, build, test and package the system when invoked by a build server (in this case TeamCity). To do so it relies on the Gallio Automation Platform and the MSBuild Community Tasks Project. In the build process this file replaces the solution (.sln) file but uses the existing project files (.csproj) which are in MSBuild...

posted @ Monday, July 20, 2009 12:16 AM | Feedback (0)

Providing configuration via injected interfaces

Configuration is an important part of most large scale applications. It’s also a distinct concern the details of which we wish to hide from the rest of our system. I address this by defining an interface that provides the configuration values. By using such an interface we break the coupling between the configuration system and the rest of the system and enabled some more interesting scenarios. In a standard case you may have a configuration section and some configuration elements. In my example we define some interfaces: public interface IExampleConfiguration { IExampleComponent ConfigurationComponent { get; } ...

posted @ Saturday, July 18, 2009 1:14 AM | Feedback (0)

Repositories in LINQ-to-SQL

I’ve recently been working with LINQ-to-SQL as the ORM for a project. Although not my preferred choice I’ve been looking at the best ways I can apply the technology within the bounds of the project. In this case this means applying the Repository pattern. In this context the primary need for the repository was to break the direct link between the LINQ-to-SQL context and the business logic so that the business logic could be relatively independent of the database and could be tested in isolation. The business logic does tend to have queries in it which could be separated...

posted @ Wednesday, July 15, 2009 11:41 AM | Feedback (2)

The database is a bit bucket

I’m known to hold Views (with an explicit capital) on the development of enterprise application software. Today’s post covers my View of the role and application or RDBMSes in enterprise applications and is summarised by the post title: I hold that the database is a bit bucket for the application and that it is mistaken to expand its responsibility beyond this. By bit bucket I mean that the database is the container for the application’s data. It is responsible for the key concerns of storage, organisation and access of this data in a performant and transactional fashion. These are...

posted @ Saturday, July 11, 2009 3:20 PM | Feedback (0)

“Die Hippie Scum” and other things not to put into production code

Tonight I attended the Perth ALT.NET group and wrote part of the code in the Domain Driven Design Dojo (DDDD). As this code was to illustrate DDD principals only and never intended for production it exhibited a number of properties that real production code should not. This included little validation, static global types to supply dependencies and a repository that was backed by an in-memory collection. One notable piece was the InvalidOperationException I had the code throw on one particularly significant error. This had the highly informative message of “Die Hippie Scum”. This is not the type of message that...

posted @ Friday, July 10, 2009 12:48 AM | Feedback (1)

Applicability of the various methods for creating type instances

My previous post discusses the use of interfaces and base classes to break coupling between c lasses. Although it touches on it briefly it does not discuss in depth the creation of instances. This is an important topic in its own right. Done incorrectly you will get no decrease in coupling between classes. However there is not a single approach that is applicable to all type categories within a single application and the requirement to eliminate coupling likewise varies between these categories. From the perspective of instantiation we can consider types to be organised into a number of key...

posted @ Friday, July 10, 2009 12:32 AM | Feedback (0)

Why Interfaces?

In a recent discussion with colleagues the question was asked why we would use interfaces in a system where we generally will have only one implementation of the interface. This applies to things such as services but also to repositories and other infrastructure pieces. The question is legitimate, it does seem like additional overhead to maintain the interfaces when there are not going to be multiple implementations at runtime. The answer has to do with coupling and the nature of statically typed languages, in particular C# and the design choices made when creating the language. Where a class A...

posted @ Thursday, July 09, 2009 1:57 PM | Feedback (2)

Chain of responsibility using LINQ Extension methods

I recently had reason to implement a simple chain of responsibility in order to simplify some logic. Rather than a large number of sequential if statements to implement a sequence of conditional exclusive actions I used this structure to simplify the logic. The basis of the implementation is a field that is a collection of delegates. The delegate take parameters as needed to determine if an action is applicable and also to implement the action. It also returns bool. For example: private static readonly ICollection<Func<TestObject, bool>> _chain = new List<Func<TestObject, bool>> { ...

posted @ Friday, July 03, 2009 11:45 PM | Feedback (0)

Conditional references using MSBuild

I’ve been using SQLite in a personal project and have encountered an issue with referencing the assembly. The .NET assembly references the unmanaged SQLite proper assembly, and this varies between 32 and 64 bit systems. Hence when building the project on my netbook a number of tests fail. The solution lies in the following XML places in the project file. <Choose> <When Condition="$(PROCESSOR_ARCHITEW6432) == 'AMD64'"> <ItemGroup> <Reference Include="System.Data.SQLite, Version=1.0.62.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64"> ...

posted @ Friday, July 03, 2009 8:22 PM | Feedback (1)

Measuring developer productivity

Much has been written on the failure of counting lines of code (LOC) as a metric for productivity. I won’t further expand on this except to note that what I consider the most compelling argument against LOC is that it will penalise a superior design that can be expressed more succinctly. But if we don’t use LOC, what do we use? I’m of the opinion that the best low level metric for the development of new features is the rate at which unit tests are being added or modified. Unit tests form an executable specification of the behaviour of...

posted @ Thursday, July 02, 2009 10:09 PM | Feedback (0)