free hit counter

Tuesday, March 29, 2005

To ASSERT or not to ASSERT?

Here's justification for my reading of slashdot, an interesting question: "Do programmers actually use assertions?", with inteligent responses The discussion ranged beyond just asserts into general debugging strategies as well as defensive design.

Tidbits from comments that struck me:
* asserts help because the sooner you see the problem, the easier it is to find and fix
* asserts are bad because they can be turned off
* asserts are good because they bring little problems to light before they become big problems
* asserts != error handling
* asserts are for programmer errors (note: I'm still working on the finer gradations of what a programmer error is.)
* asserts gaurantee that future maintenance won't break the code
* programs shouldn't terminate because they are unhappy. They should recover and continue
gracefully

My conclusions:
* asserts never have quite sat right with me, because they can be turned off
* I've never seen a quality assert infrastructure in use
* I've seen crappy assert infrastructures in use
* asserts are often, and easily, confused with error handling
*

unit testing is the new assert

- it has all the good qualities of asserts + more


Links:
Debugging Functions
MS Symbol server
First bug, found in 1945
Design By Contract
GCC's fancy_abort()

Fail Fast

0 Comments:

Post a Comment

<< Home