I worked on a horrible, interesting bug today. But first, some background: assertions. If you're a coder, assertions are probably the best thing that you've probably done in your code before you even knew they were called assertions, and something that they should teach in CS classes. (I didn't learn the proper term for them until I started here.) Simply put, they're this:
Assert(everythingIsOkay, "Crap! Something's broken!");
The macro Assert would then expand to something like this in a debug-only build:
if (!(everythingIsOkay)) Output("Crap! Something's broken!");
So, you litter your code, especially at the beginnings and ends of methods, with these assertions to say that you're sure that when you get to that point, something will be true. This object will never be null. This counter will always be at least 1. The user is currently logged in. Stuff like that. They let you know immediately if some other part of the program is broken. They don't affect the performance of final versions of your program, because final versions that ship to customers aren't built in debug mode, and assertions disappear automatically in final builds.
Anyway, we use those all over the place in SharePoint Designer. When you're using a debug version of SPD (customers never see debug versions), you get a message box popping up telling you what went wrong. But today, I worked on a bug that's like a bad time travel episode of Star Trek: the reason that we crashed was because we asserted that something bad was going to happen. The very act of showing that warning dialog is what caused the actual crash to happen. (I won't get into the details of how exactly that is possible because they're pretty arcane...)
Sure enough, if I get rid of that dialog, everything is peachy-keen. So, there's no actual bug that will affect a user, because only people on my team will ever be using these debug builds of the product.
Ah, that was amusing. Amusing and frustrating, because I spent so much time looking at it. But, I'd been looking for an excuse to talk about assertions for quite some time, seeing as I have all sorts of readers who write code only occasionally, probably haven't thought of them, and can probably get some use out of the idea.