One thing I\'ve sometimes wondered is which is the better style out of the two shown below (if any)? Is it better to return immediately if a guard condition hasn\'t been sat
I prefer the first style, except that I wouldn't create a variable when there is no need for it. I'd do this:
// Style 3 public SomeType aMethod() { if (!guardCondition()) { return null; } SomeType result = new SomeType(); doStuffToResult(result); doMoreStuffToResult(result); return result; }