[TYPO3-core] RFC #15020: Enhancement of t3lib_div::testInt

Oliver Klee typo3-german-02 at oliverklee.de
Thu Jul 8 17:50:43 CEST 2010


Hi,

Am 08.07.2010 12:39, schrieb Nikolas Hagelstein:
> "In general there should be a single return statement in the function (see
> the preceding example). 
> However a function can return during parameter validation before it starts
> its main logic"

This is called a "guard clause" which can be used to improve readability:

<pseudocode>
function foo() {
  if (broken) {
    return FALSE;
  }
  if (emptyEdgeCase) {
    return TRUE;
  }

  startOfActualCode
  (many lines ... without a return)
  endOfActualCode

  return $result;
}

</pseudocode>


The point of the single return rule and the guard clause exception is to
not have returns in the middle of the function so that you only need to look

1. at the top of the function (for error cases etc.)
2. and the bottom (for the "normal" result).


Oli
-- 
Certified TYPO3 Integrator | TYPO3 Security Team Member


More information about the TYPO3-team-core mailing list