Thanks for replying. I guess I wasn't clear enough. Actually, the two $a variables are supposed to be unrelated. The "my $a" is hypothetically a reasonably appropriate name chosen for the variable given its meaning, but it happens to conflict with perl's use of global $a. | [reply] |
I have significant difficulty in accepting that hypothesis.
$i/$j/(occasionally) $k are sufficiently widely-used and well-known that they are acceptable as loop counters. $x/$y/$z are appropriate for geometric coordinates, again due to long and widespread use.
Offhand, I can think of no other cases in which a single-character variable name is "reasonably appropriate", regardless of whether it happens to conflict with a magical name built into the language or not.
| [reply] |
| [reply] [d/l] |
$u and $v are also standard for coordinates, as of course is $r (in the company of a $theta).
And plenty of other things use single-letter variables by convention. If I were implementing a quadratic equation solver, for example, I would consider it obfuscation to name the coefficients anything other than $a, $b, and $c.
The question should never be "does this variable name meet some arbitrary standard", but rather "will my successor, trying to maintain this code in a few years' time, immediately grasp what this variable is for". If the answer is "yes" (and can be justified!), then any name is potentially appropriate, regardless of length.
| [reply] |