Daniel Hoelbling-Inzko talks about programming

How to ruin my day

Posted by Daniel Hölbling on September 16, 2009

In case you are somewhere stuck in a plan on how to make my day miserable I’ve got a tip for you:

Write absolutely horrible code like this and leave the maintenance to me:

Method signature:

internal void TryRequestSession(string securityToken, ref Guid secID)

Call site:

public ActionMethod Open(string securityToken)
	Guid secID = Guid.Empty;
		secID = new Guid(securityToken);
	Guid oldSecID = secID;
	provider.TryRequestSession(securityToken, ref secID);
	if (oldSecID == Guid.Empty)

There are many things wrong with this code, but I’ll spare you the details and say that new Guid(securityToken) will always throw a ArgumentException and that I have absolutely no tolerance for void methods that have ref parameters!

Whatever was going on in that chimps mind who wrote that, it couldn’t have anything to do with programming.

So, recap: If you expect other people to maintain your code (I’m currently rewriting this thing, it’s easier) make sure you do the following:

  1. Have Unit tests that specify the behavior
  2. Leave an actual spec that can be looked at
  3. NEVER use ref if you can use return
  4. Don’t swallow exceptions (and if you have to, leave a comment!)
  5. Make it run!

Yes that’s right. If you leave a piece of crap behind, at least make it compile! I had to search for 3 totally outdated libraries to even make this piece of junk compile on my machine. Again: The GAC is your enemy!

Thank you, you now may go on with your lives while I feel a lot better and my actually start enjoying my coffee :)

Filed under net, programmierung, projects
comments powered by Disqus

My Photography business


dynamic css for .NET