• Categories

  • .Net TimeBombHack

    I love this code which I found when digging around in some of Ayende’s source code , so I thought i’d share it with you, but I can’t take the credit for it.

    Its called the TimeBombHack class and you can use it for those times when your writing code when you would usually put in a  //TODO:  comment.

    However as is often the case sometimes these todos get forgotten and never get implemented and can make it into production. You can put the TimeBombHack into your code specifying a date and message. When the date arrives the code throws an exception, simple as that.

     TimeBombHack.Until(new DateTime(2009, 5, 14), "Add exception handling");

    Anyway the code looks like this:

     public static class TimeBombHack
         #region Public Methods
         public static void Until(DateTime expiredAt, string message)
              var hackExpiredMessage = string
                 .Format("The hack ({0}) expired on ({1}). You really should fix it already",
              if (DateTime.Today > expiredAt)
                 throw new HackExpiredException(hackExpiredMessage);
            #endregion Public Methods

    kick it on

    2 Responses to “.Net TimeBombHack”

    1. Philipp says:

      That’s a harsh one :)

      I’d rather use Debug.Fail however – I *really* wouldn’t want to see this one go off on a customer’s machine.

    2. Stuart C says:

      Hi Philipp I wouldn’t want it to get into production either. That’s why you would set the expiry date way before any production release date or the date of your testing phase. If it gets past your unit tests on your build server or your human testers and sneaks into production then you’ve probably got bigger problems on your hands.

      A non-impelemented piece of business logic can creep into production far more easily and can be just as costly.

      Hey but that’s just my two cents worth.

    Leave a Reply