|
Posted by Steve on 04/12/07 14:53
| consider this:
|
| function level($n, $l = 0)
| {
| $ff = get_folders();
| for ($i = 0; $i < count($ff); $i++)
| {
| if ($n != $ff[$i][0]){ continue; }
| if ($ff[$i][4] != 0)
| {
| $l++;
| level($ff[$i][4], $l);
| } else {
| return $l;
| }
| }
| }
lemme practice what i preach (and usually do)...
function level($n, $l = 0)
{
$ff = get_folders();
for ($i = 0; $i < count($ff); $i++)
{
if ($n != $ff[$i][0]){ continue; }
if ($ff[$i][4] != 0)
{
level($ff[$i][4], ++$l);
}
return $l;
}
}
the difference? NO else statements (as none are needed, as they rarely are)
and $l is only incremented in the recursive calls to level()...which helps
more plainly show that it is only a change for parameter calls in level()
rather than massaged elsewhere in level().
either way, it's still shitty code...there's just less of it to cause a
stinch and is more readily identifiable as shit since it can be read and
understood at a glance.
Navigation:
[Reply to this message]
|