Jonas Yorg sikyal:
Are you sure about this? I mean, have you hung out on the C and Python
newsgroups and observed the lack of questions regarding this topic? (I
haven't, so this is a non-rhetorical question.) I do know that this is a
common question--sort of--on the PHP newsgroups. It's much more easily
answered in PHP, though, since there is no broad censure against it, the
syntax is easier (usually just $$foo), and there are no hard references to
be used instead. These are not advantages of PHP, by the way, simply
reasons why this question comes up less frequently on that newsgroup.
Perhaps a personal example will help: when I first learned Perl, I was
learning it more or less as my first programming language, building off of
a fragmentary and inadequate knowledge of BASIC that I'd picked up from
somewhere. Before long, I wanted to use symbolic references, and my
reasons weren't dissimilar to the ones that the OP mentions: I thought
they were more elegant. Rather than creating a separate hash that would
serve no purpose other than to hold unconnected bits of data that I really
wanted, it seemed more concise and elegant to make a variable with a name
found in another variable.
These were my main reasons: conciseness and elegance. These are generally
good programming traits. The problem is that in this case, the perceived
benefit in elegance is outweighed by much larger costs in terms of
security and predictability. So the newbies that ask these questions
aren't completely clueless, as much as undereducated about the negative
effects of symbolic references.
--
Jesse S. Bangs (e-mail address removed)
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
Jesus asked them, "Who do you say that I am?"
And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."
And Jesus said, "What?"