...
The following is preferable for code maintenance. By defining what constitutes a failure and explicitly testing for it, the behavior is clearly implied and future modifications are more likely to preserve it. If there is a future modification like the one above, it is immediately obvious that the if statement in processRequest does not utilize the specification of validateUser correctly.
Code Block | ||
---|---|---|
| ||
validateUser(User usr) { if(validUsers.contains(usr)) { return 1; } return 0; } processRequest(User usr, Request request) { if(foovalidateUser(usr) == 0) // explicit test for failure { return 0; { return "invalid user"; } else { serveResults(); } } |
Noncompliant Code Example
...