Re: Code References
| From: | Sterling Hughes | Date: | Mon, 19 May 2003 13:56:54 +0000 |
| Subject: | Re: Code References | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-1717@lists.php.net to get a copy of this message | ||
On Mon, 2003-05-19 at 11:09, Zeev Suraski wrote:
> At 16:34 19/05/2003, Sterling Hughes wrote:
> >On Mon, 2003-05-19 at 10:55, Wez Furlong wrote:
> > > use perl;
> >
> >Python, Ruby, LISP, Java, C, whatever, all support this in some form or
> >another (whether it be function pointers or code references.)
>
> And so does PHP, through create_function, using PHPish
> syntax. create_function is not related in any way to call_user_func(),
> it's fairly fast, and will be faster. I don't see any additional things
> that are supported by this syntax, other than a tiny performance gain, that
> comes at the price of significantly reduced functionality (the code cannot
> contain anything dynamic, whereas with create_function, it can).
>
That's why one has eval.
Create_function() is a really hacky way of having closures/callbacks.
Its not only inefficient, its ugly. create_function() is hardly ever
used because its such an inelegant (and inefficient) way of doing
things. From a syntax perspective anonymous functions are much clearer
(the problem with single quotes is you need to then escape all single
quotes).
(responding to a previous message re conditional compilation)
What about when a compiler cache is introduced? Every high performance
application most likely uses a compiler cache. Introducing a code
reference, would remove that overhead, and would seriously simplify and
improve callback code (I have a patch which optimizes nearly all of the
callback code in php5, which I'll send shortly, but its cleaner if we
had the concept of code references.)
-Sterling
--
"Reductionists like to take things apart. The rest of us are
just trying to get it together."
- Larry Wall, Programming Perl, 3rd Edition