<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>[PHP] insteadof considered harmful</title>
        <description> I must admit with embarrassment that after months of googling and posting 
questions to various forums I still fail to understand the purpose of the 
&amp;quot;insteadof&amp;quot; keyword and the insteadof clause.

As I currently see it, the whole insteadof clause is completely redundant. In 
a clause like this:

Foo::tweak insteadof Bar;

the &amp;quot;insteadof Bar&amp;quot; part does not specify any information that is not already 
unambiguously specified by the &amp;quot;Foo::tweak&amp;quot; part. &amp;quot;Foo::tweak;&amp;quot; already 
conveys the intention of using tweak from the trait Foo instead of any other 
trait that has a member named tweak. What if we are using seven such traits? 
Do we have to list them all after insteadof? Why do we have to explicitly 
enumerate things that we DON'T want to use?

I would like to see a small code example where the insteadof clause provides  
information that is BOTH necessary to make the program unambiguous AND cannot 
be conveyed with the simple &amp;quot;Foo::tweak;&amp;quot; syntax. Absent such example, I 
consider &amp;quot;insteadof&amp;quot; harmful because it does nothing and adds a maintenance 
chore. It should be made optional and deprecated ASAP, and removed at some 
point in the future.

Szczepan Hołyszewski

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php</description>
        <link>http://www.serverphorums.com/read.php?8,475677,475677#msg-475677</link>
        <lastBuildDate>Sun, 19 May 2013 09:11:44 +0200</lastBuildDate>
        <generator>Phorum 5.2.18</generator>
        <item>
            <guid>http://www.serverphorums.com/read.php?8,475677,475774#msg-475774</guid>
            <title>Re: [PHP] insteadof considered harmful</title>
            <link>http://www.serverphorums.com/read.php?8,475677,475774#msg-475774</link>
            <description><![CDATA[ &gt; See <a href="http://us.php.net/manual/en/language.oop5.traits.php" target="_blank"  rel="nofollow">http://us.php.net/manual/en/language.oop5.traits.php</a> and scroll down to<br />
&gt; conflict resolution to see simple example. It is used to resolve method<br />
&gt; naming conflicts when multiple traits are used to emulate multiple<br />
&gt; inheritance.<br />
<br />
I have read the manual, and the examples there are precisely my examples of <br />
insteadof's complete redundancy. Firstly, the manual says:<br />
<br />
&quot;To resolve naming conflicts between Traits used in the same class, the <br />
insteadof operator needs to be used to chose exactly one of the conflicting <br />
methods.&quot;<br />
<br />
Why, why, why? Why not just name that &quot;exactly one of the conflicting methods&quot; <br />
using a fully trait-qualified name? That would be completely unambiguous. It's <br />
a simple task of choosing one from many, and such a choice can be <br />
unambiguously encoded by just naming the one, without having to list the <br />
remaining many. It is really that simple, no strings attached.<br />
<br />
Here's the example from the manual:<br />
<br />
trait A {<br />
    public function smallTalk() {<br />
        echo 'a';<br />
    }<br />
    public function bigTalk() {<br />
        echo 'A';<br />
    }<br />
}<br />
<br />
trait B {<br />
    public function smallTalk() {<br />
        echo 'b';<br />
    }<br />
    public function bigTalk() {<br />
        echo 'B';<br />
    }<br />
}<br />
<br />
class Talker {<br />
    use A, B {<br />
        B::smallTalk insteadof A;<br />
        A::bigTalk insteadof B;<br />
    }<br />
}<br />
<br />
class Aliased_Talker {<br />
    use A, B {<br />
        B::smallTalk insteadof A;<br />
        A::bigTalk insteadof B;<br />
        B::bigTalk as talk;<br />
    }<br />
}<br />
<br />
I've been analyzing these 28 lines of code for months, and I cannot for the <br />
life of me understand why the same information couldn't be conveyed thus:<br />
<br />
/* no changes in the traits */<br />
<br />
class Talker {<br />
    use A, B {<br />
        B::smallTalk;<br />
        A::bigTalk;<br />
    }<br />
}<br />
<br />
class Aliased_Talker {<br />
    use A, B {<br />
        B::smallTalk;<br />
        A::bigTalk;<br />
        B::bigTalk as talk;<br />
    }<br />
}<br />
<br />
All information is there. The insteadof clauses add nothing to the <br />
interpreter's knowledge of the programmer's intention. They are every last one <br />
of all the hundred damn percent redundant.<br />
<br />
But perhaps there IS a purpose, only the examples in the manual fail to <br />
demonstrate it?<br />
<br />
Szczepan Hołyszewski<br />
<br />
-- <br />
PHP General Mailing List (http://www.php.net/)<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Szczepan Hołyszewski</dc:creator>
            <category>php-general</category>
            <pubDate>Mon, 09 Apr 2012 17:40:03 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?8,475677,475730#msg-475730</guid>
            <title>Re: [PHP] insteadof considered harmful</title>
            <link>http://www.serverphorums.com/read.php?8,475677,475730#msg-475730</link>
            <description><![CDATA[ On Apr 9, 2012, at 7:15 AM, Szczepan Hołyszewski wrote:<br />
<br />
&gt; <br />
&gt; I must admit with embarrassment that after months of googling and posting <br />
&gt; questions to various forums I still fail to understand the purpose of the <br />
&gt; &quot;insteadof&quot; keyword and the insteadof clause.<br />
&gt; <br />
&gt; As I currently see it, the whole insteadof clause is completely redundant. In <br />
&gt; a clause like this:<br />
&gt; <br />
&gt; Foo::tweak insteadof Bar;<br />
&gt; <br />
&gt; the &quot;insteadof Bar&quot; part does not specify any information that is not already <br />
&gt; unambiguously specified by the &quot;Foo::tweak&quot; part. &quot;Foo::tweak;&quot; already <br />
&gt; conveys the intention of using tweak from the trait Foo instead of any other <br />
&gt; trait that has a member named tweak. What if we are using seven such traits? <br />
&gt; Do we have to list them all after insteadof? Why do we have to explicitly <br />
&gt; enumerate things that we DON'T want to use?<br />
&gt; <br />
&gt; I would like to see a small code example where the insteadof clause provides  <br />
&gt; information that is BOTH necessary to make the program unambiguous AND cannot <br />
&gt; be conveyed with the simple &quot;Foo::tweak;&quot; syntax. Absent such example, I <br />
&gt; consider &quot;insteadof&quot; harmful because it does nothing and adds a maintenance <br />
&gt; chore. It should be made optional and deprecated ASAP, and removed at some <br />
&gt; point in the future.<br />
<br />
See <a href="http://us.php.net/manual/en/language.oop5.traits.php" target="_blank"  rel="nofollow">http://us.php.net/manual/en/language.oop5.traits.php</a> and scroll down to conflict resolution<br />
to see simple example. It is used to resolve method naming conflicts when multiple traits are used to emulate multiple inheritance.<br />
<br />
Tom<br />
<br />
<br />
-- <br />
PHP General Mailing List (http://www.php.net/)<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>TR Shaw</dc:creator>
            <category>php-general</category>
            <pubDate>Mon, 09 Apr 2012 16:00:02 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?8,475677,475677#msg-475677</guid>
            <title>[PHP] insteadof considered harmful</title>
            <link>http://www.serverphorums.com/read.php?8,475677,475677#msg-475677</link>
            <description><![CDATA[ I must admit with embarrassment that after months of googling and posting <br />
questions to various forums I still fail to understand the purpose of the <br />
&quot;insteadof&quot; keyword and the insteadof clause.<br />
<br />
As I currently see it, the whole insteadof clause is completely redundant. In <br />
a clause like this:<br />
<br />
Foo::tweak insteadof Bar;<br />
<br />
the &quot;insteadof Bar&quot; part does not specify any information that is not already <br />
unambiguously specified by the &quot;Foo::tweak&quot; part. &quot;Foo::tweak;&quot; already <br />
conveys the intention of using tweak from the trait Foo instead of any other <br />
trait that has a member named tweak. What if we are using seven such traits? <br />
Do we have to list them all after insteadof? Why do we have to explicitly <br />
enumerate things that we DON'T want to use?<br />
<br />
I would like to see a small code example where the insteadof clause provides  <br />
information that is BOTH necessary to make the program unambiguous AND cannot <br />
be conveyed with the simple &quot;Foo::tweak;&quot; syntax. Absent such example, I <br />
consider &quot;insteadof&quot; harmful because it does nothing and adds a maintenance <br />
chore. It should be made optional and deprecated ASAP, and removed at some <br />
point in the future.<br />
<br />
Szczepan Hołyszewski<br />
<br />
-- <br />
PHP General Mailing List (http://www.php.net/)<br />
To unsubscribe, visit: <a href="http://www.php.net/unsub.php" target="_blank"  rel="nofollow">http://www.php.net/unsub.php</a>]]></description>
            <dc:creator>Szczepan Hołyszewski</dc:creator>
            <category>php-general</category>
            <pubDate>Mon, 09 Apr 2012 13:20:02 +0200</pubDate>
        </item>
    </channel>
</rss>
