Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
bgColor#CCCCFF

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

...