[Boulder.pm] Boulder-pm Digest, Vol 39, Issue 11

Walter Pienciak wpiencia at thunderdome.ieee.org
Thu Aug 23 11:07:39 PDT 2012


On Thu, Aug 23, 2012 at 11:52:59AM -0600, Rob Nagler wrote:
> > open MYSELF, '<', $0;
> > print while (<MYSELF>);
> 
> Since this is a perl list, and people have mentioned learning perl,  I
> have a comment about this style.  Walter has known me a long time so
> I'm sure he knows this is in the best interest of the programming
> public:
> 
> * Don't use <>.  It's an ambiguous operator, meaning glob and
> readline.  Searching for all instances of <bla> is almost impossible.
> You might as why would you ever do that?  Well, if you wanted to
> modularize access to the file system, because you now have to share
> state across multiple servers.
> 
> * Don't use implicit $_.  That's something that has bitten us more
> times than I can count.  If you do insist on using $_, make it
> explicit and do a local($_).  Avoid multiple calls when you can.  It's
> convenient to suck in lines and print them out, but that's extra
> parsing, calls, and doesn't describe what you are doing.  Use sysread
> and syswrite, because you don't need the buffering of stdio anyway.
> 
> * Check error codes, always.  If the program can't read itself, it
> should die.  You may say, "it's just a hack?"  Hmmmm... How many of
> you have had a credit card stolen?  Even though it is handled by the
> credit card company, it's a total hassle to not have that credit card
> for 10 days and/or have to update all your autopays to the new credit
> card.  Good code begins with the hacks, and works its way upward.
> 
> * Don't rely on file handles closing.  Do it explicitly. If you are
> relying on a stdio library (readline does), then check the return
> result of the close, because it may return an error.
> 
> Just my $.02.
> 
> Rob

All good points, Rob.

Rob and a few others have also heard me expound on academic
(produce the basic solution for the professor so you can get back
to drinking or whatever) versus production (evil exists) code.  

So -- disclaimer!!! (skull/crossbones and implications of dire
consequences) -- the possibility that I put minimal
effort/keystrokes into my solution(s) should not be discounted.

;^)

We were talking about books a bit ago.  Perl Cookbook and Perl
Best Practices (seems relevant to this thread) are the two I dip
into most often.

Walter


More information about the Boulder-pm mailing list