[TYPO3-dev] Code humor
Martin Kutschker
martin.kutschker-n0spam at no5pam-blackbox.net
Wed Jan 28 14:11:24 CET 2009
Oliver Klee schrieb:
> Hi,
>
> Bernhard Kraft schrieb:
>> I also follow Martins preference: Early returns are ok ... at least if they
>> make sense like in above situation.
>>
>> It would probably even make sense in above situation to collect multiple
>> error
>> messages if more of them apply at the same time ...
>
> In my projects, we use this strategy:
>
> Use early returns *only* for guard clauses (for errors an trivial
> "empty" cases) at the very beginning of the function *and* if they
> improve readability.
The early returns should usually be only guard clauses.
What I also don't like is cascades like that. Actually this only the
"flattened" verions of the if-mountain:
$error = false;
$error = first_stuff();
if (!$error) second_stuff();
if (!$error) third_stuff();
if ($error) return false else return true;
It's more readable then the if-mountain, but you have a lot of ifs only
make a single return.
Masi
More information about the TYPO3-dev
mailing list