[TYPO3-core] RFC #16586: Refactor conditions in t3lib_extFileFunc
Jigal van Hemert
jigal at xs4all.nl
Tue Nov 30 14:35:16 CET 2010
Hi Andreas,
Thank you for the effort to make TYPO3 better.
On 30-11-2010 13:41, Andreas Wolf wrote:
> Argh. Yes. The example is wrong. It should have been:
>
> after:
> if (!condition) {
> $this->writeLog(...);
> return FALSE;
> }
> foo();
> bar();
In these kind of case the Coding Guidelines [1] mention: "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."
In the original code are already far too many return statements and your
version adds many more :-(
Some suggestions to streamline these monster functions could be:
- move the checks to separate methods
- move the actions (move/copy/delete for files/folders etc.) to separate
methods
- see if there are common parts which can be shared without expanding
the code too much or make the code harder to maintain
- try to add unit tests so future modifications can be easily tested
(shorter functions are easier to test because they contain less
variations in results than large, complex functions)
Hopefully you're still motivated to contribute, but changes to monster
functions are best done by splitting things up in parts which are easy
to understand.
[1] http://goo.gl/WTjG5
--
Kind regards / met vriendelijke groet,
Jigal van Hemert
skype:jigal.van.hemert
msn: jigal at xs4all.nl
http://twitter.com/jigalvh
More information about the TYPO3-team-core
mailing list