All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: Petr Baudis <pasky@suse.cz>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/5] gitweb: Do not use bareword filehandles
Date: Sun, 10 May 2009 11:27:51 +0200	[thread overview]
Message-ID: <200905101127.51963.jnareb@gmail.com> (raw)
In-Reply-To: <20090510075053.GA6058@machine.or.cz>

On Sun, 10 May 2009, Petr Baudis wrote:
> On Sun, May 10, 2009 at 02:36:19AM +0200, Jakub Narebski wrote:

> > ---
> > Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles
> > 
> >   Write open my $fh, q{<}, $filename; instead of open FH, q{<}, $filename;.
> > 
> >   Using bareword symbols to refer to file handles is particularly evil
> >   because they are global, and you have no idea if that symbol already
> >   points to some other file handle. You can mitigate some of that risk by
> >   'local'izing the symbol first, but that's pretty ugly. Since Perl 5.6, you
> >   can use an undefined scalar variable as a lexical reference to an
> >   anonymous filehandle.
> > 
> > See also Damian Conway's book "Perl Best Practices",
> > chapter "10.1. Filehandles" (Don't use bareword filehandles.)
> > 
> > 
> > This follows similar patch for git-send-email.perl by Bill Pemberton
> > http://permalink.gmane.org/gmane.comp.version-control.git/117886
> > 
> > CC-ed Pasky, who is responsible for code in both cases...
> 
> Yeah, the book I learnt Perl from many years ago used bareword
> filehandles (but it was an excellent textbook in most other aspects)
> so this is a custom I have to work hard to evict. ;-)
> 
> Acked-by: Petr Baudis <pasky@suse.cz>

Well, on one hand this is less of an issue for standalone script like
gitweb is than for library / module.  On the other hand we use indirect
filehandles everywhere else, so it is also matter of style consistency.

"Perl Best Practices" gives as an example of bad behavior which we can
get by using bareword [global] filehandles: 1) automatic closing of
other filehandle with the same name (e.g. not only you use FILE for
bareword filehandle); 2) open might fail if there exist subroutine /
constant with the same name as filehandle e.g. EXDEV (from POSIX module).

Note however that prior to Perl 5.6 it was not that easy to avoid
using bareword filehandles. Perhaps the book in question (or author of
the textbook you mention) started with earlier Perl...


P.S. Git.pm generates surprisingly small amount of perlcritic-isms,
most of whose are either matter of style, or are false positives.
-- 
Jakub Narebski
Poland

  reply	other threads:[~2009-05-10  9:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-10  0:03 [PATCH 0/5] gitweb: Some code cleanups (up to perlcritic --stern) Jakub Narebski
2009-05-10  0:05 ` [PATCHv2 1/5] gitweb: Remove function prototypes Jakub Narebski
2009-05-10  9:05   ` Jakub Narebski
2009-05-10  0:36 ` [PATCH 2/5] gitweb: Do not use bareword filehandles Jakub Narebski
2009-05-10  7:50   ` Petr Baudis
2009-05-10  9:27     ` Jakub Narebski [this message]
2009-05-11  1:21   ` [PATCH v2 " Jakub Narebski
2009-05-10  0:38 ` [PATCH 3/5] gitweb: Always use three argument form of open Jakub Narebski
2009-05-11  1:29   ` [PATCH v2 " Jakub Narebski
2009-05-10  0:39 ` [PATCH 4/5] gitweb: Localize magic variable $/ Jakub Narebski
2009-05-10  0:40 ` [PATCH 5/5] gitweb: Use block form of map/grep in a few cases more Jakub Narebski
2009-05-11  0:47 ` [PATCH 0/5] gitweb: Some code cleanups (up to perlcritic --stern) Junio C Hamano
2009-05-11  1:33   ` Jakub Narebski
2009-05-11  4:21     ` Junio C Hamano
2009-05-11  5:13       ` Daniel Pittman
2009-05-11  7:19       ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200905101127.51963.jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pasky@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.