On 05/10/2011 01:10 AM, Jordi Boggiano wrote:
On Tue, May 10, 2011 at 10:02 AM, Lars Schultz
To explain what I mean, I'll use the example provided in the RFC. Could
anyone please explain the advantages of having "passive" annotations over
"active" PHP Code.

I think your example shows very well why annotations are good, it's
much more concise.

By concise, you mean shorter, easier to read?

I have a really hard time looking at:

<Entity("users")>
class User {
    <Column("integer")>
    <Id>
    <GeneratedValue("AUTO")>
    <ManyToMany("Phonenumber")>
    protected $Phonenumbers;
}

as a PHP user and instantly understanding what this does. It looks completely foreign from a PHP syntax point of view.

Whereas:

class User_EntityAnnotation {
    public function getEntityName() {
        return 'users';
    }

    public function getColumnInfo($property) {
        switch($property) {
            case 'id': return array(
                'column'=>'integer',
                'isPrimary'=>true,
                'autoIncrement'=>true
            );

            case 'Phonenumbers': return array(
                'manytomany'=>'Phonenumber'
            );
        }
    }
}

is way more verbose, but I can instantly grok what is going on without learning a new syntax, without waiting for my opcode cache to support it, and without waiting for my editor to understand the new syntax.

Don't underestimate the difficulty in getting opcode cache support for something like this. If you think the engine code is complex, try digging into the opcode cache code. It will be much much harder to write the opcode cache support than it was to write the engine code for it.

I also have a personal problem with code that needs to introspect on every web request in order to run. But that is likely because I am old and gray and used to stare sceptically at the assembly output of the first C compilers to see if I could come up with an alternative that would take fewer cycles.

-Rasmus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to