Actively enforce your conventions

time to read 2 min | 253 words

Glenn posted about a test I wrote PrismShouldNotReferenceUnity, in which I codified an assumption that the team made.

This is something that I try to do whenever I decide that I will have some sort of convention. If at all possible, I will try to make sure that the compiler will break if you don't follow the convention, but that is often just not possible, therefor, tests and active enforcement of the system convention fill that place.

Wait a minute, I haven't even defined what a convention is! By convention, I means things like:

  • All services should have a Dispose() method - add a Dispose abstract method to AbstractService
  • All messages should be serializable - create a test that scan the message assemblies and check for non serializable messages.
  • You may only call the database twice per web request - create an http module that will throw an exception if you call it more than that
  • A request should take less than 100 milliseconds - add an interceptor that would fail if this is not the case.
  • The interface assembly may not contain logic - add a test that would fail if it find a class with a method on the interface assembly.

All of those are ways to increase the feedback speed. This is especially true if there is some extra step that you need to perform, or you want to draw a line in the sand, from which you will not deviate.

Actively enforced conventions keep you honest.