2007/9/13, Peter Scott <[EMAIL PROTECTED]>:
> On Wed, 12 Sep 2007 09:00:44 -0700, Tom Phoenix wrote:
> > On 9/12/07, Peter Scott <[EMAIL PROTECTED]> wrote:
> >
> >> If you do
> >>
> >>   my $a = 6.023E23;  # Avagadro's number
> >>   # Many lines of chemistry code elided
> >>   @elements = sort { $atomic_wt{$a} <=> $atomic_wt{$b} } @elements;
> >>
> >> you get
> >>
> >>   Can't use "my $a" in sort comparison
> >>
> >> which is going to annoy someone who then has to change all the
> >> references to Avagadro's number.
> >
> > That would be annoying. But why would they change dozens of $a's to
> > $avogadro instead of simply fixing the sort to use the right package
> > variable, as perldiag suggests?
> >
> >   @elements = sort { $atomic_wt{$pkg::a} <=> $atomic_wt{$pkg::b} } 
> > @elements;
> >
> > There's no doubt that $a and $b were poor choices for sort. It's too
> > bad that Larry didn't choose other names, or capitalize them, or
> > something. I rarely use single-letter names for long spans of code,
> > but if I did, I'd capitalize the name because $A stands out and makes
> > a better name Avogadro. And you can use it during a sort().
>
> Well, quite, and so would I.  I was answering in a beginners' context,
> though.  The $a/$b specialness hasn't bothered *me* for a long time
> and I'm sure it hasn't bothered you either.  But I think your average
> beginner is not au fait with perldiag and doesn't want to spelunk to the
> bottom of the perldoc explanations for simple things where the explanation
> turns to advanced things, when they're trying to do something that seemed
> simple to begin with.  That said, I'll readily admit to being solidly in
> hair-splitting territory.
>

most other languange's lessons (like python,JS etc),use 'a' and 'b' as
sample variable names.so as a perl beginner,who may also think '$a'
and '$b' are good variable names.:)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to