Versions Compared

Key

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

...

Although failures are frequently indicated by a return value of zero (which C considers to be false), there are common conventions that may conflict in the future with code where the test for non-zero is not explicit. In this case, defaulting the test for non-zero welcomes bugs if and when a developer modifies foo to return an error code or -1 rather than 0 to indicate a failure (all of which are common conventions). 

Code Block
bgColor#ffcccc

validateUser(User usr)
{
  if(foovalidUsers.contains(usr))
  {
    return 1;
  }

  return 0;
}

processRequest(User usr, Request request)
{
  if(validateUser(usr))
  {
    return "invalid user";
  }
  else
  {
    serveResults();
  }
}

The code above will work

Compliant Solution

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.

...