http://www.perlmonks.org?node_id=632208


in reply to Practical example of "Is Perl code maintainable"

eyepopslikeamosquito,
If I were writing it, it would probably look something like:
use constant MODE => 2; sub file_mode { my ($file) = @_; return -1 if ! -f $file; return (stat($file))[MODE]; }

I think perl's shortcuts can get in the way of writing maintainable code sometimes. For instance, shift can default to two different variables depending on where in the program it appears. If I were to use shift, I would be sure to explicitly state which variable it was acting on. By avoiding shift, adding additional positional variables doesn't require modifying both sides.

I know that using _ to avoid another stat call is a nice optimization but I would never do it in production code without a comment. I also prefer the use of constants for array indices so that another author can immediately see what is going on.

For the record, I am not a developer and do not write production code so take my comments with a boulder of salt.

Cheers - L~R