<?xml version="1.0" encoding="windows-1252"?>
<node id="632208" title="Re: Practical example of &quot;Is Perl code maintainable&quot;" created="2007-08-13 09:36:02" updated="2007-08-13 05:36:02">
<type id="11">
note</type>
<author id="180961">
Limbic~Region</author>
<data>
<field name="doctext">
[eyepopslikeamosquito],
&lt;br /&gt;
If I were writing it, it would probably look something like:
&lt;CODE&gt;
use constant MODE =&gt; 2;

sub file_mode {
    my ($file) = @_;
    return -1 if ! -f $file;
    return (stat($file))[MODE];
}
&lt;/CODE&gt;
&lt;p&gt;
I think perl's shortcuts can get in the way of writing maintainable code sometimes.  For instance, [doc://shift] can default to two different variables depending on where in the program it appears.  If I were to use [doc://shift], I would be sure to explicitly state which variable it was acting on.  By avoiding [doc://shift], adding additional positional variables doesn't require modifying both sides.
&lt;/p&gt;
&lt;p&gt;
I know that using _ to avoid another [doc://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.
&lt;/p&gt;
&lt;p&gt;
For the record, I am not a developer and do not write production code so take my comments with a boulder of salt.
&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-180961"&gt;
&lt;p&gt;
Cheers - [Limbic~Region|L~R]
&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
632152</field>
<field name="parent_node">
632152</field>
</data>
</node>
