July 25, 2007

A Dubious Assertion

Filed under: Tech — Chris @ 2:44 am

Being a conscientious software engineer, I try to be good about putting assert statements in my code. And being a verification guy, I find myself tempted to express fairly deep correctness properties in my assertions. And this fills me with such satisfaction, that I am such a wise and clever programmer, that I should do such things.

But then I’m trying to optimize some code so that it runs in something like an acceptable amount of time and for some reason I just can’t shake this routine out of its stupor… What’s going on here?

Don’t add assertions that change the asymptotic complexity of your algorithm. That’s just dumb. (Of course you can always compile your code with assertions turned off, but even in testing the difference between O(n) and O(1) can pinch.)

And now look at how much more wise and clever and self-satisfied I can be.


Create a free website or blog at

%d bloggers like this: