Hack Bombing template for Resharper
A couple of days ago, Oren Eini blogged about a hack bombing which is a practice of time bombing a hack so that you’ll be reminded to fix it. Some people thought it was a terrible idea, pointing to previous experiences with developers checking in debugging-hacks which caused severe difficulties for the team and letting these hacks slip through to production. I really liked the concept of a time bombed hack, just because of the same reasons people disliked it. Developers generally don’t like to cut corners, but when their project is under pressure it is quite common that this principle is set aside. Some corners are cut, some dirty fixes are made and deferred as “fix it later”. Given the right circumstances, this is not necessarily a bad strategy – as long as you have a strategy for fixing it later. As Oren pointed out, time bombing such hacks is a way to actively remind the developer that a corner has been cut.
Oren has implemented a tiny hack bombing framework in his Rhino Commons library. While I use this library from time to time, it’s is not omnipresent in my projects. I therefore wrote a Live Template for Resharper to hack bomb my code.
#region Hack: Remove the hard coded string
#if DEBUG
// HACK: Remove the hard coded string
if (DateTime.Now > DateTime.Parse("2007.02.06", CultureInfo.InvariantCulture).AddDays(3))
{
throw new Exception("Norås, Anders has not fixed the "+
"hack \"Remove the hard coded string\" within the "+
"deadline. The hack was done 2007.02.06.");
}
#endif
#endregion
address.Country = "US";
To avoid problems similar to the one Adi pointed out, I’ve chosen to only timebomb a hack when the application is built with the debug configuration. I’ve also included a HACK comment, so that the hack will show up in the comments category in Visual Studio’s task list. You can download the Resharper template here.
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using