[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [ID 20000111.008] use strict 'vars'
>I'm sure there is a really good reason that user defined sort subs
>use the global/local/univeral/magical variables $a and $b to determine
>sorting order, rather than having the sort routine look at a less painful
>variable, such at @_. faster, less memory, something.
Was that a question?
>but from a user point of view, its a hidden gotcha.
I fail to see how something that it is documented can be adjudged
"hidden". Neither do I understand how something that has worked in that
fashion since time immemorial (perl-wise) is "hidden". What, pray tell,
might we have to do to make it "not hidden"? Make it the first thing
in the the perl(1) manpage? Do you have a suggested patch to perlvar(1)?
>I recall writing some code that unknowingly used the $a $b
>variables (ran out of $i, $j, $k, $x, $y, $z) and had some
>weird behaviour that I didn't figure out until I asked a perl "guru".
Perhaps this is a special penalty for those with insufficient
imagination to use properly named variables. :-)
>could perl spit out some kind of note when it encounters $a or $b
>such as "this is a weird variable reserved for sorting."
>just to inform a neophyte that $a is not the same as $c .. $z?
>that the perl people know about it, and that the user should
>probably use a different variable?
Goodness, I don't think so.
>would it be too much to rename it to something less likely to
>collide with the neophyte? maybe $_sorting_variable_a_
Only if breaking it in that odious fashion should cause Perl to emit
your name, email address, and home phone number.
First of all, there's no reason to shamelessly destroy all existing sort
code. Secondly, designing something to be novice-friendly at the expense
of making it expert-hostile is a fundamental error, for you shall be a
novice but once and briefly, yet a trans-novice for all the days of your
life that follow your initiation into these the outermost mysteries.
Thirdly, so long a variable name as that is completely repugnant.
It reminds me of the same sentiment as drives the misguided to write
for ($loop_index_variable = 0;
$loop_index_variable < scalar(@array);
$loop_index_variable = $loop_index_variable + 1
)
{
$cumulative_sum = $cumulative_sum
+ $an_array_variable[$loop_index_variable];
}
>if there isn't much of a performance/memory/etc hit, could
>it use @_ since the sort routine must be a subroutine?
Sure, as long as you agree that Perl should in perpetuity emit your real
home phone number because you decided to hose a million people because
you stubbed your toe. Eschew immediate gratification.
>I don't like global variables to begin with.
Then perhaps you shouldn't use them. Deal? :-)
--tom
- References to:
-
london@pixelmagic.com
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]