Re: insteadof considered harmful

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> See http://us.php.net/manual/en/language.oop5.traits.php and scroll down to
> conflict resolution to see simple example. It is used to resolve method
> naming conflicts when multiple traits are used to emulate multiple
> inheritance.

I have read the manual, and the examples there are precisely my examples of 
insteadof's complete redundancy. Firstly, the manual says:

"To resolve naming conflicts between Traits used in the same class, the 
insteadof operator needs to be used to chose exactly one of the conflicting 
methods."

Why, why, why? Why not just name that "exactly one of the conflicting methods" 
using a fully trait-qualified name? That would be completely unambiguous. It's 
a simple task of choosing one from many, and such a choice can be 
unambiguously encoded by just naming the one, without having to list the 
remaining many. It is really that simple, no strings attached.

Here's the example from the manual:

trait A {
    public function smallTalk() {
        echo 'a';
    }
    public function bigTalk() {
        echo 'A';
    }
}

trait B {
    public function smallTalk() {
        echo 'b';
    }
    public function bigTalk() {
        echo 'B';
    }
}

class Talker {
    use A, B {
        B::smallTalk insteadof A;
        A::bigTalk insteadof B;
    }
}

class Aliased_Talker {
    use A, B {
        B::smallTalk insteadof A;
        A::bigTalk insteadof B;
        B::bigTalk as talk;
    }
}

I've been analyzing these 28 lines of code for months, and I cannot for the 
life of me understand why the same information couldn't be conveyed thus:

/* no changes in the traits */

class Talker {
    use A, B {
        B::smallTalk;
        A::bigTalk;
    }
}

class Aliased_Talker {
    use A, B {
        B::smallTalk;
        A::bigTalk;
        B::bigTalk as talk;
    }
}

All information is there. The insteadof clauses add nothing to the 
interpreter's knowledge of the programmer's intention. They are every last one 
of all the hundred damn percent redundant.

But perhaps there IS a purpose, only the examples in the manual fail to 
demonstrate it?

Szczepan Hołyszewski

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux