Someone says, "You should always check your arguments to see if they're in range." Someone else says, "Half the statements in this program are checking arguments that are intrinsically in range." Have they made the program better or worse? No, I think they've made it worse. I'm not a fan of checking arguments. On the other hand, there ought to be a fail fast. If you make a mistake, the program ought to stop. So there is an art to knowing where things should be checked and making sure that the program fails fast if you make a mistake. That kind of choosing is part of the art of simplification.
Very true. Argument checks are difficult. Personally for low level utility function I prefer to use ASSERT macros to check arguments. They are there in Debug Version to track bugs faster and no performance penalty in Release version. It has happened many times that testing team reports a bug and I start the application in Debug mode. Out pops a 'assertion failure' message. Nearly Zero efforts to locate the cause of bug. In my experience time to find the location bug is usually large percentage of total bug fixing time. If I can reduce that time, then it greatly helps in reducing the total development time and improving the project code quality.
Also it has another benefit that if you wrote a module with asserts and other developer makes a mistake in using those functions, he will get assertion failure during the development/unit testing phase itself. As you know, a bug is detected and correct early, has low cost.
Post a Comment