Defensive Coding

Depending on the context, can mean several things.

1. The act of putting in redundant error-checks (assertions and the like) in a program, to make sure that errors are caught early and caught as close to where they actually occur, as possible. Some methods/methodologists frown on this (BetrandMeyer? and DesignByContract in particular; one rule Meyer gives is never re-check a precondition in the function body). Others view this as a legitimate form of DefenseInDepth--useful especially if a process such as DesignByContract isn't followed rigorously.

2. Avoidance of programming constructs known to cause trouble. This can be good or bad--often times the "advice" is based on rumor, folklore, or plain inexperience (and may not be relevant to your environment anyway). Sometimes useful--one way to successfully program in C++ is to adopt a style of coding which avoids HeapAllocation? as much as possible (that way, you don't have to worry about deallocating the memory; a common bugbear for C++ programmers).

The first meaning already has a page at DefensiveProgramming.


EditText of this page (last edited January 23, 2004) or FindPage with title or text search