Refactoring to smaller blocks isn't always practical, particularly with older legacy code. i've often used the style described, because inevitably, some hint that describes the block is more helpful than nothing at all. The project i currently work with is a nightmare of inconsistent patterns, procedural logic crammed into class methods, etc. Just getting things documented to understand inner workings of individual
blocks (let alone whole functions) has been a long, slow process.
That said, perhaps moving the "end-of" comment to the line
inside or
after the terminating
} can be helpful in most cases, but not perfect.
}
// END foreach($rows)
}
// END while ($count)
// END ridiculously large if ($foo)
} elseif ($bar) {
// ...
}
// END ridiculously large if/elseif chain
// END of foo()
}
}
There's no ideal solution, given other rules about splitting chained controls like "
} else[if ()] {" because there's no good placement of such a comment, nor good way to format it if complying with all the rules.