//PHP!! bool someFunc( $a = -1, $b = -1 ) { // Defensive programming! if ( $a == -1 ) { return false; } // More defensive programming! if ( $b == -1 ) { return false; } return true; }It's funny because you can tell the innocent thought process of the programmer who wrote this. It's simple: preset default unwanted values and reject them if they are not set. That way you can ensure that they are set by the invoker!
Except that it is much more robust and safer if the programmer would just remove the default arguments, together with the defensive programming lines of code.
I wonder if that programmer got stuck while dealing with a language without default argument support?
No comments:
Post a Comment