| <<< Comment: a good programming paractice... | Index | Trace: debug without the debugger >>> |
An assertion declares that a certain condition must be true at a specific point in a program.
The assertion is said to fail if the condition is false.
Assertions can tell why errors are happening.
Assertions can diagnose a problem at the first sign of trouble.
OK, what should I assert?
Short answer: everything!
Validate input parameters and check every assumption you made while writing your code.
Don't worry that putting in too many assertions degrades program performance: assertions usually active only in debug builds. Bug-finding opportunities outweigh the small performance hit!
IMPORTANT: Assertions should never change any variables or program state. Treat all data you check in assertions as read-only.
| <<< Comment: a good programming paractice... | Index | Trace: debug without the debugger >>> |