Using asserts AND keeping them in production builds.
This really helps whipping people into shape and making them pay attention to what they write. Also helps documenting the code in a very succinct way.
This really helps whipping people into shape and making them pay attention to what they write. Also helps documenting the code in a very succinct way.
You can also print backtraces when an assertion fails: https://stackoverflow.com/questions/77005/how-to-automatical...
(Whether you should use assert for that kind of checks that probably only should run in tests is debatable, but it sometimes happens)
switch (...) {
case A:
...
case B:
...
...
default: // all possible cases are dealt with above
assert(0);
} assert(!"You gave an invalid letter");
The string literal is a pointer, so !pointer is false. And then you get a nice explanation message when the assertion fails. I wish all assert gave optional explanation messages.