indirect function calls and variable variables
Cameron Laird
claird at lairds.com
Tue May 27 07:59:59 EDT 2003
In article <slrnbd3e45.emb.ramen at lackingtalent.com>,
Dave Benjamin <ramen at lackingtalent.com> wrote:
>In article <vcmt074rchvb4d at corp.supernews.com>, Cameron Laird wrote:
>> PHPers do indeed use variable variables often--too much,
>> in fact. It's a general principle that languages which
.
.
.
>The reason the "variable variable" phenomenon (actually "call-by-name") pops
>up so much in PHP is due to its lack of support for functions as values.
>However, since PHP has a single, global namespace for functions, this ends
>up being an effective way to write a dispatch, and safer than an eval().
>
>> Erik illustrated the pattern with his function invocation
>> above. He didn't write there that such usage generally
>> invites consideration for refactoring into an object-
>> oriented polymorphism scheme.
>
>I find that dispatching with an eval or dictionary lookup is often simpler
>and more concise than using subtype inheritance with polymorphism. YMMV.
>
>Dave
Yes and no.
I think people overdo polymorphism. Dispatching with
a dictionary lookup is indeed often simpler and more
concise than inheritance elaboration. You are quite
right. I suspect we agree that the two are close,
though; when a design involves one, it's probably timely
to evaluate the other, as an alternative.
I don't follow your first paragraph. At least one of us
doesn't understand the other. I am writing about
"variable variables", as in the variables named
$variable1
$variable2
...
one often sees in Perl and PHP code. My observation is
that, for several reasons, it's generally better to
transform such segments into references to
$variable(1)
$variable(2)
...
<URL: http://groups.google.com/groups?frame=left&th=4d786ca1e1b89b0c >
illustrates this.
You seem to have in mind idioms for function invocation,
rather than variable dereferencing. Or are you making a
subtle point about one masquerading as the other?
Programmers do indeed cherish first-class functions, of
course.
--
Cameron Laird <Cameron at Lairds.com>
Business: http://www.Phaseit.net
Personal: http://phaseit.net/claird/home.html
More information about the Python-list
mailing list