[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: [ID 20000111.008] use strict 'vars'



Tom Christiansen wrote:
> 
> >Don't break anything, but possibly produce incorrect warnings. If new
> >warnings are regarded as breakage, we're screwed. I know use strict
> >'vars' currently produces errors, not warnings, but it's not a big leap
> >to convert those to warnings for $a and $b only. Perhaps you wanted me
> >to mention that detail.
> 
> If you suddenly produce a warning just because someone was using
> $a and $b, you will be shot.  Not by me, but by millions of users.
> But if you make it $some_idiotically_long_variable_a, then you won't
> be shot by millions of users--because this time I'll be at the front
> of the line.
> 
> If you dont' believe me, try it.  Here's an "I told you so" in
> advance.

Hm. TomC, you seem to be responding to my suggestions as if they were
the union of my actual suggestions and Greg's. I do not have the least
desire to rename $a or $b. I do not want to affect sort { $a <=> $b } at
all either. sub mysort { $a <=> $b } I'm not entirely convinced must be
preserved forever, but leave that aside for now.

Yes, I am proposing issuing a warning just because someone was using $a
or $b -- but only in the hopefully rare cases that perl has an incorrect
but strong suspicion that they aren't being used as sort variables. sort
BLOCK would never issue such a warning (I mean, if the $a or $b were
actually present in the block and not in a called subroutine). $a = 5 at
the toplevel scope would, but then, unless I have a severe lack of
imagination, that warning would always be correct. sub mysort might once
in a while issue an incorrect warning, but normally wouldn't.

> >If use strict said clearly "$a
> >is a special case, so this warning might be in error", you won't see the
> >bug report any more.
>
> I do believe I suggested a documentation patch.

I was assuming the implementation of the above proposal, and the message
is in perldiag or maybe the warning issued, not the documentation.

> Finally, the notion that "using single-letter variable names is a
> crime that carries its own punishment" is especially apt here.

Much of the example code in the documentation uses $a, $b, and $c.
Justifiably, since the purpose of the variables is not relevant to the
lesson being imparted. But first, that means that many people will be
using them; and second, there are many instances in actual code where
the purpose of variables is irrelevant.

my $a, $b; # oops!
# Set $a and $b to something useful, then
($$a, $$b) = ($$b, $$a);

Forbidding $a and $b in general and in these kinds of situations in
particular is rather bizarre and not the way I think of perl doing
things. Go ahead and do weird things with $; if you like; leave $a with
$x. Scowling at single-letter variables is much the same as demanding
that every line of code contain a comment. Or taking away all the
prepositions that people were using to end their sentences with. Most of
the time it's a great idea, but all of the time it's not.


References to:
Tom Christiansen <tchrist@chthon.perl.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]