Defensive Driving in Development
Do you have a problem on how to protect yourself from the cold, cruel world of invalid data, events that can “never” happen, and other programmers’ mistakes. Try being defensive. Be a defensive programmer by defensive programming.
In defensive programming, the main idea is that if a routine is passed bad data, it won’t be hurt, even if the bad data is another routine’s fault. More generally, it’s the recognition that programs will have problems and modifications, and that a smart programmer will develop code accordingly.
The idea is based on defensive driving. In defensive driving, you adopt the mind-set that you’re never sure what the other drivers are going to do. That way, you make sure that if they do something dangerous you won’t be hurt. You take responsibility for protecting yourself even when it might be the other driver’s fault.
Happy Driving!