> What do you think of Dave and Andy's comments?
Spot on. I was glad to read the comments on "Crash Early"; at a recent project I saw catch blocks like this
...
catch (Exception e) {
// will never happen
}
I said, "Since its never going to happen, why not put a System.exit in the catch block in this critical code?". People weren't so sure then :-) So we designed a mechanism for graceful shutdown.
Another thing we did which paid off big time was to go further than assertions and use class invariance in our domain model. When something went wrong we knew exactly where, why and who caused it. Furthermore, testing the invariance of objects passed to methods gave further protection.
This sounds like a lot of work but its actually a lot less work than finding and fixing bugs. Furthermore, it gives added confidence when refactoring in a similar way to unit tests do, you're testing the running system.
As Dave said "The reason you crash early is to stop errors from propagating far away from the cause.". I beleve this applies to assertions and invariance too - catch the problem before it pops up later in some bizarre way.
Channing