Re: Control Flow Coding Style

"Johannes Brodwall" <[email protected]>
Newsgroups gmane.comp.programming.language-of-the-year
Message-ID <[email protected]>
Consider

Object doIt() {
  Object result = null;
  for ( Object candidate : potensials ) {
     if ( matches(candidate) ) {
       result = candidate;
       break;
     } else {
        // What?!?
     }
  }
  return result;
}

versus

Object doIt() {
  for ( Object candidate : potensials ) {
    if ( matches(candidate) ) {
      return candidate;
    }
  }
  return null;
}

Which one is most likely to contain bugs?

The only coding standard I have seen that has come close to working
is: Don't write crappy code.



~Johannes
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.