<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Day 18: Roles</title>
	<atom:link href="http://perl6advent.wordpress.com/2009/12/18/day-18-roles/feed/" rel="self" type="application/rss+xml" />
	<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/</link>
	<description>Something cool about Perl 6 every day</description>
	<lastBuildDate>Sun, 03 Feb 2013 05:15:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: mina86</title>
		<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/#comment-203</link>
		<dc:creator><![CDATA[mina86]]></dc:creator>
		<pubDate>Wed, 23 Dec 2009 01:09:28 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=304#comment-203</guid>
		<description><![CDATA[Now I see it wasn&#039;t used by only specified type constraint (you can get a bit of a headache if you switch too fast between Perl and C++ ;) ). Thanks for pointing that out -- it actually makes more sense to me now. :P

Still, two more questions if I may:

First of all, what happens if two roles use the same attribute? The paper pointed out traits must not have attribute to avoid diamond problem (for those who don&#039;t know what it is and have better things to do then read overly-long papers ;) it&#039;s situation where class A inherits from B and C and both B and C inherit from D) and here it seems as if the problem was not avoided at all.

And finally, from what I&#039;ve understood one cannot parametrize classes. Question is: Why? For instance, a legitimate use case would be to have a &quot;Container[::Type]&quot; role and a &quot;RBTree[::Type]&quot; class which &quot;does&quot; the role.]]></description>
		<content:encoded><![CDATA[<p>Now I see it wasn&#8217;t used by only specified type constraint (you can get a bit of a headache if you switch too fast between Perl and C++ ;) ). Thanks for pointing that out &#8212; it actually makes more sense to me now. :P</p>
<p>Still, two more questions if I may:</p>
<p>First of all, what happens if two roles use the same attribute? The paper pointed out traits must not have attribute to avoid diamond problem (for those who don&#8217;t know what it is and have better things to do then read overly-long papers ;) it&#8217;s situation where class A inherits from B and C and both B and C inherit from D) and here it seems as if the problem was not avoided at all.</p>
<p>And finally, from what I&#8217;ve understood one cannot parametrize classes. Question is: Why? For instance, a legitimate use case would be to have a &#8220;Container[::Type]&#8221; role and a &#8220;RBTree[::Type]&#8221; class which &#8220;does&#8221; the role.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jnthnwrthngtn</title>
		<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/#comment-175</link>
		<dc:creator><![CDATA[jnthnwrthngtn]]></dc:creator>
		<pubDate>Sat, 19 Dec 2009 17:23:21 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=304#comment-175</guid>
		<description><![CDATA[&quot;Different things should look different&quot; is a Perl 6 design principle. Thus why we have a method routine declarator (even though a method is just a sub that takes an invocant and can be dispatched to a bit differently), a grammar package declarator (even though a grammar is just a class that inherits from Grammar by default) and so forth.

As a further benefit, the different names imply something about the purpose. Sure, I can write a class with named regexes in it (albeit missing the useful built-ins that I&#039;d inherit if I&#039;d used the grammar keyword) and a grammar with methods in it. But that doesn&#039;t mean having them called different things to state the difference in intent is a bad thing.

To get a better grasp of the differences between inheritance and composition, I suggest reading the original paper, which offers a much more detailed explanation:

http://scg.unibe.ch/archive/papers/Scha02bTraits.pdf

Finally, you noted that I did use a role on its own in my last example. I guess you meant:

my Tray of Glass of MulledWine $valuable;

But here I am not using the role - just setting it as a type constraint on the variable. Any object that does that role could then be stored in $valuable.]]></description>
		<content:encoded><![CDATA[<p>&#8220;Different things should look different&#8221; is a Perl 6 design principle. Thus why we have a method routine declarator (even though a method is just a sub that takes an invocant and can be dispatched to a bit differently), a grammar package declarator (even though a grammar is just a class that inherits from Grammar by default) and so forth.</p>
<p>As a further benefit, the different names imply something about the purpose. Sure, I can write a class with named regexes in it (albeit missing the useful built-ins that I&#8217;d inherit if I&#8217;d used the grammar keyword) and a grammar with methods in it. But that doesn&#8217;t mean having them called different things to state the difference in intent is a bad thing.</p>
<p>To get a better grasp of the differences between inheritance and composition, I suggest reading the original paper, which offers a much more detailed explanation:</p>
<p><a href="http://scg.unibe.ch/archive/papers/Scha02bTraits.pdf" rel="nofollow">http://scg.unibe.ch/archive/papers/Scha02bTraits.pdf</a></p>
<p>Finally, you noted that I did use a role on its own in my last example. I guess you meant:</p>
<p>my Tray of Glass of MulledWine $valuable;</p>
<p>But here I am not using the role &#8211; just setting it as a type constraint on the variable. Any object that does that role could then be stored in $valuable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mina86</title>
		<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/#comment-173</link>
		<dc:creator><![CDATA[mina86]]></dc:creator>
		<pubDate>Sat, 19 Dec 2009 16:01:44 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=304#comment-173</guid>
		<description><![CDATA[Honestly I don&#039;t see it. For me it seems classes and rules are the very same thing expect inheritance works a bit different plus rule can be parametrized and (by arbitrary decision) class cannot.]]></description>
		<content:encoded><![CDATA[<p>Honestly I don&#8217;t see it. For me it seems classes and rules are the very same thing expect inheritance works a bit different plus rule can be parametrized and (by arbitrary decision) class cannot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bened</title>
		<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/#comment-170</link>
		<dc:creator><![CDATA[bened]]></dc:creator>
		<pubDate>Sat, 19 Dec 2009 14:46:54 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=304#comment-170</guid>
		<description><![CDATA[@mina86: Implementing the Perl 6 rule behaviour into normal class inheritance would mean naming two different things equally. Didn&#039;t we have enough of this in Perl 5? I am happy that different concepts get different names in Perl 6.]]></description>
		<content:encoded><![CDATA[<p>@mina86: Implementing the Perl 6 rule behaviour into normal class inheritance would mean naming two different things equally. Didn&#8217;t we have enough of this in Perl 5? I am happy that different concepts get different names in Perl 6.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mina86</title>
		<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/#comment-167</link>
		<dc:creator><![CDATA[mina86]]></dc:creator>
		<pubDate>Fri, 18 Dec 2009 14:55:55 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=304#comment-167</guid>
		<description><![CDATA[From what I understood the difference between composition and inheritance is forcing user to manually resolve name conflicts. If so then personally I&#039;d prefer to have this behaviour work for inheritance and remove the whole &quot;rule&quot; things which IMHO serves no purpose (yes, I&#039;m of an opinion that the less entities the better). Or introduce two words for inheriting from base classes -- one with inheritance and another with composition behaviour.

Also &quot;we can not use a role on its own&quot; but if it&#039;s a parametrized role we can use it on its own if we specify parameters (as seen in the last example). Doesn&#039;t this inconsequence strike you?]]></description>
		<content:encoded><![CDATA[<p>From what I understood the difference between composition and inheritance is forcing user to manually resolve name conflicts. If so then personally I&#8217;d prefer to have this behaviour work for inheritance and remove the whole &#8220;rule&#8221; things which IMHO serves no purpose (yes, I&#8217;m of an opinion that the less entities the better). Or introduce two words for inheriting from base classes &#8212; one with inheritance and another with composition behaviour.</p>
<p>Also &#8220;we can not use a role on its own&#8221; but if it&#8217;s a parametrized role we can use it on its own if we specify parameters (as seen in the last example). Doesn&#8217;t this inconsequence strike you?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jnthnwrthngtn</title>
		<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/#comment-166</link>
		<dc:creator><![CDATA[jnthnwrthngtn]]></dc:creator>
		<pubDate>Fri, 18 Dec 2009 13:06:56 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=304#comment-166</guid>
		<description><![CDATA[I gave a few more examples in a post I wrote just after implementing these - it&#039;s a bit old, but still looks to be all correct in terms of the code examples.

http://use.perl.org/~JonathanWorthington/journal/38308]]></description>
		<content:encoded><![CDATA[<p>I gave a few more examples in a post I wrote just after implementing these &#8211; it&#8217;s a bit old, but still looks to be all correct in terms of the code examples.</p>
<p><a href="http://use.perl.org/~JonathanWorthington/journal/38308" rel="nofollow">http://use.perl.org/~JonathanWorthington/journal/38308</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jnthnwrthngtn</title>
		<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/#comment-165</link>
		<dc:creator><![CDATA[jnthnwrthngtn]]></dc:creator>
		<pubDate>Fri, 18 Dec 2009 13:04:18 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=304#comment-165</guid>
		<description><![CDATA[The option to have them parameterized is really just a nice extra, and not the heart of what roles are about. The key thing in roles is the composition mechanism, which has different semantics from inheritance and thus doesn&#039;t silently make choices in the case of conflicts, which leads to fragile hierarchies. In academia the concept has been referred to as traits; Perl 6 chose the name &quot;roles&quot; as it better indicates their use case. The initial academic work on traits, iirc, was done this decade, and while various languages are exploring them, the composition mechanism is an innovation.

You&#039;re right that the parameterization isn&#039;t ground-breaking in itself. One difference is that we use multiple dispatch to decide between possible variants of a role based upon the arguments. Another thing that distinguishes Perl 6 from some (but not all) implementations of things like this is that arguments may be values or types. The Perl 6 standard grammar makes use of roles parameterized on values.

Hope this helps,

Jonathan]]></description>
		<content:encoded><![CDATA[<p>The option to have them parameterized is really just a nice extra, and not the heart of what roles are about. The key thing in roles is the composition mechanism, which has different semantics from inheritance and thus doesn&#8217;t silently make choices in the case of conflicts, which leads to fragile hierarchies. In academia the concept has been referred to as traits; Perl 6 chose the name &#8220;roles&#8221; as it better indicates their use case. The initial academic work on traits, iirc, was done this decade, and while various languages are exploring them, the composition mechanism is an innovation.</p>
<p>You&#8217;re right that the parameterization isn&#8217;t ground-breaking in itself. One difference is that we use multiple dispatch to decide between possible variants of a role based upon the arguments. Another thing that distinguishes Perl 6 from some (but not all) implementations of things like this is that arguments may be values or types. The Perl 6 standard grammar makes use of roles parameterized on values.</p>
<p>Hope this helps,</p>
<p>Jonathan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jnthnwrthngtn</title>
		<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/#comment-164</link>
		<dc:creator><![CDATA[jnthnwrthngtn]]></dc:creator>
		<pubDate>Fri, 18 Dec 2009 12:49:37 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=304#comment-164</guid>
		<description><![CDATA[That&#039;s not quite right - the does here is not parsed as an operator, but rather as a trait modifier. It&#039;s defined as:

&lt;pre&gt;    token trait_mod:does {
        :my $*PKGDECL ::= &#039;role&#039;;
        &lt;sym&gt;:s &lt;module_name&gt;
    }&lt;/pre&gt;

So at the moment you need to write &quot;does&quot; each time, but I guess it&#039;d be possible to tweak the trait_mod parsing rule there to allow multiple. One issue is if people will view them as somehow &quot;grouped&quot;, when in reality it means nothing extra at all over writing &quot;does&quot;... The harder problem is that the trait mod compiles to a multi-dispatch, so we&#039;d have to work out what happens there (I guess we&#039;d dispatch a list of things, and the candidate that handles a list would iterate and re-dispatch on each of them). Anyway, it&#039;s a little deeper than just a syntax change.]]></description>
		<content:encoded><![CDATA[<p>That&#8217;s not quite right &#8211; the does here is not parsed as an operator, but rather as a trait modifier. It&#8217;s defined as:</p>
<pre>    token trait_mod:does {
        :my $*PKGDECL ::= 'role';
        &lt;sym&gt;:s &lt;module_name&gt;
    }</pre>
<p>So at the moment you need to write &#8220;does&#8221; each time, but I guess it&#8217;d be possible to tweak the trait_mod parsing rule there to allow multiple. One issue is if people will view them as somehow &#8220;grouped&#8221;, when in reality it means nothing extra at all over writing &#8220;does&#8221;&#8230; The harder problem is that the trait mod compiles to a multi-dispatch, so we&#8217;d have to work out what happens there (I guess we&#8217;d dispatch a list of things, and the candidate that handles a list would iterate and re-dispatch on each of them). Anyway, it&#8217;s a little deeper than just a syntax change.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mina86</title>
		<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/#comment-163</link>
		<dc:creator><![CDATA[mina86]]></dc:creator>
		<pubDate>Fri, 18 Dec 2009 11:59:36 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=304#comment-163</guid>
		<description><![CDATA[But honestly, how is it better then abstract classes with arguments (or templates as they are called in C++)? It appears to me as if someone just invented a new name for something that is already there in other languages.]]></description>
		<content:encoded><![CDATA[<p>But honestly, how is it better then abstract classes with arguments (or templates as they are called in C++)? It appears to me as if someone just invented a new name for something that is already there in other languages.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carl</title>
		<link>http://perl6advent.wordpress.com/2009/12/18/day-18-roles/#comment-162</link>
		<dc:creator><![CDATA[carl]]></dc:creator>
		<pubDate>Fri, 18 Dec 2009 08:04:32 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=304#comment-162</guid>
		<description><![CDATA[One superficial reason, which borders on begging the question, is that &#039;does&#039; has a much tighter precedence than the comma. &#039;does&#039; falls under &quot;structural infix&quot;, level 12, in the precedence table, whereas the comma is on level 19.]]></description>
		<content:encoded><![CDATA[<p>One superficial reason, which borders on begging the question, is that &#8216;does&#8217; has a much tighter precedence than the comma. &#8216;does&#8217; falls under &#8220;structural infix&#8221;, level 12, in the precedence table, whereas the comma is on level 19.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
