How to ruin my day
September 16, 2009 by Daniel HoelblingIn 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; try { secID = new Guid(securityToken); } catch {} 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:
- Have Unit tests that specify the behavior
- Leave an actual spec that can be looked at
- NEVER use ref if you can use return
- Don’t swallow exceptions (and if you have to, leave a comment!)
- 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 :)