develooper Front page | perl.perl6.language | Postings from June 2005

Re: AUTLOAD and $_

Thread Previous | Thread Next
From:
Juerd
Date:
June 21, 2005 09:06
Subject:
Re: AUTLOAD and $_
Message ID:
20050621160552.GR7412@c4.convolution.nl
Adam Kennedy skribis 2005-06-21 12:10 (+1000):
> You are of course assuming that every use of AUTOLOAD, for all time, 
> will result in
> a) Calling another function
> b) An error

That is more or less what it's for. Do note that this other function
that is called can be entirely statementless, thus a no-op.

> Wouldn't this lead to hacks where people do things like this just to 
> prevent perl thinking it's a failure?

There is nothing we can do to prevent dumb programmers from doing dumb
things, except dropping lots of features and operators. But if we wanted
that, adding lexicals and closures to PHP would probably be easier.

> sub AUTOLOAD ($whatever) {  # but no *@_
>      my $s = get_subref_for $whatever;
>      our &::($whatever) := $s;
>      return sub () { 1 };

Then the subref will not be executed, and the bug will very quickly be
discovered. I don't see any problem with this.

There are also people who don't understand that TIE* methods should
return objects, because they are constructors. Has this ever been a
great problem? 

If there is a fixed interface that makes sense and is documented, people
not following it are either really dumb or very clever. 

> The ability to get complete control over the params and context of the 
> function, and maybe run something else AFTER the function call is important.

I disagree. In that case you should be using a wrapper or a macro. A
wrapper you can simply return, but I find it very bad style to install
foo and then run foo plus something else. And if you don't install foo
(with &foo := ...), you can do whatever you want anyway, by putting
whatever you want in the closure.

> So I suspect there might be some false economy in this optimisation.

It's not an optimization. It's necessary, unless there is a way to
receive arguments in unknown context, which is a bit of complexity and
complication we can very easily avoid needing.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About