monkdiscuss
rvosa
Almost every day I learn about more little devils that might slip into my code details. For example, I'm slowly getting used to not doing:
<code>
open(FILE, $filename);
</code>
but instead doing:
<code>
my $fh;
open($fh, '<', $filename) or die "can't open $filename: $!"
</code>
Either approach is semantically correct, and there's more than one way to do things, but the second one is better practice because:
<ul>
<li>The file handle $fh is lexically scoped, preventing weird action-at-a-distance.</li>
<li>The mode is explicitly set, preventing unintended operations, i.e. overwriting $filename.</li>
<li><code>open</code> is tested, and errors returned by the file system - i.e. $! - are returned.</li>
</ul>
I am sure there's an endless number of other things that I'm still doing "wrong" because I don't know about them - although my programs execute just fine.
<br /><br />
Wouldn't it be a good idea to erect a place on perlmonks where those issues could be discussed in the form of mini code reviews? For example, someone has written a few blocks of code < $maxlength, where $maxlength is something manageable, like 100 lines. The code executes just fine, but the coder is inspired by [id://107600]'s book on <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0596001738/qid=1123172269/sr=8-1/ref=pd_bbs_sbs_1/104-4127024-1015130?v=glance&s=books&n=507846">Perl best practices</a> and would like further nitpicking for the edification of all and sundry. Other monks move in, and crush submitter's spirit with maddeningly anal comments.
<br /><br />
(I am reminded here of UWashington's ecology department's lunch seminar series <i>Eco-Lunch</i>, where willing grad students present research and field questions. The series is internally known as the <i>Ego-Crunch</i>.)
<br /><br />
The idea is that the code already works - i.e. not SoPW material -, is very much NOT obfuscated and might even be very UNCOOL, i.e. accountancy software.
<br /><br />
Your comments please!