[Bioperl-l] $_ assignment question

Aaron J Mackey ajm6q at virginia.edu
Thu Jul 31 16:01:51 EDT 2003


Uhh, let me put in my usual snobby and grumpy two cents and say that this
form of code Nazi-ism is really annoying, and introduces massively
difficult to follow CVS changes.  Next we'll need to change all
occurrences of:

  $obj->dosomething unless $dont;

to:

  if(!$dont)
  {
    $obj->dosomething();
  }

so that some Java programmers don't get confused.  I think this is wasted
effort.  Indirect object method syntax is not evil when the method is a
well understood and used "keyword" type of thing like "new", "open",
"connect", etc.  Many of us use it to mentally differentiate between
constructors and class methods:

Net::SMTP->debug(1);
my $smtp = new Net::SMTP @args;

Yes, I know a constructor is a class method, but (at least to me), it's a
different flavor that is very often seen written with indirect syntax in
Perl.  On the flip side, you don't typically see:

  debug Net::SMTP 1;

If *that* is the type of usage you'd like to get rid of, I have less
of a complaint.

Re: localized $_, I think you're barking up another pedantical tree.  If
you'd like to do this cleanly, then I'd rather see you change this:

while ($_ = $self->_readline) {
  if (m/foobar/) {
    # ...

Into:

while (my $line = $self->_readline) {
  if ($line =~ m/foobar/) {
    # ...

Rather than:

while (local $_ = $self->_readline) {
  if(m/foobar/) {
    # ...

Of course, this particular brand of pedanticness would indicate that this
construct:

while(<FH>) {
  # ...
}

... should also never be used.

But I (grumpily) consent that the various ways Perl can perform actions
at a distance can in some cases cause frustrating problems for others.

-Aaron

P.S. The Conway book is great, but it's not <i>ta biblia</i>.




More information about the Bioperl-l mailing list