title: Better Java method Syntax? Return early or late?
body: <blockquote>
    <p><strong>Duplicate:</strong> <a href="https://stackoverflow.com/questions/36707">Should a function have only one return statement?</a></p>
  </blockquote>
  
  <p>Often times you might have a method that checks numerous conditions and returns a status (lets say boolean for now).  Is it better to define a flag, set it during the method, and return it at the end :</p>
  
  <pre><code>boolean validate(DomainObject o) {
    boolean valid = false;
    if (o.property == x) {
       valid = true;
    } else if (o.property2 == y) {
       valid = true;
    } ...
    return valid; 
  }
  </code></pre>
  
  <p>or is it better/more correct to simply return once you know the method's outcome?</p>
  
  <pre><code>boolean validate(DomainObject o) {
  
    if (o.property == x) {
       return true;
    } else if (o.property2 == y) {
       return true;
    } ...
    return false; 
  }
  </code></pre>
  
  <p>Now obviously there could be try/catch blocks and all other kinds of conditions, but I think the concept is clear.  Opinions?</p>