<?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/"
		>
<channel>
	<title>Comments on: Towards Better Reuse: Traits in JavaScript</title>
	<atom:link href="http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 17 May 2012 07:43:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: jhurstus</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270241</link>
		<dc:creator>jhurstus</dc:creator>
		<pubDate>Sun, 04 Jan 2009 21:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270241</guid>
		<description>@ThomasHansen
I followed up with the inventors of Traits about why the trait composition validation mechanism stops at an existence check (&quot;does class Foo implement required methods x, y, z?&quot;) and doesn&#039;t do something more flexible like Eiffel contracts.  Their answer, as I suspected, was that checking method names was easy to implement in the first language to be augmented with Traits (Smalltalk/Squeak).  There is no conceptual reason that traits couldn&#039;t be extended to support different composition validation mechanisms like contracts.</description>
		<content:encoded><![CDATA[<p>@ThomasHansen<br />
I followed up with the inventors of Traits about why the trait composition validation mechanism stops at an existence check (&#8220;does class Foo implement required methods x, y, z?&#8221;) and doesn&#8217;t do something more flexible like Eiffel contracts.  Their answer, as I suspected, was that checking method names was easy to implement in the first language to be augmented with Traits (Smalltalk/Squeak).  There is no conceptual reason that traits couldn&#8217;t be extended to support different composition validation mechanisms like contracts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jhurstus</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270058</link>
		<dc:creator>jhurstus</dc:creator>
		<pubDate>Mon, 22 Dec 2008 23:49:45 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270058</guid>
		<description>@ThomasHansen: Also, to follow up on Cappuccino it does appear that Objective-J has a somewhat similar concept called &#039;Categories&#039;.  However traits differ in some notable ways: (1) traits unlike categories can be composed from multiple traits to build up new traits from existing traits (2) the rules for injecting trait methods into a class are slightly different (3) traits provide more control on how they are added into other traits or classes (via aliasing and excluding exported method names).  Thanks for the feedback!</description>
		<content:encoded><![CDATA[<p>@ThomasHansen: Also, to follow up on Cappuccino it does appear that Objective-J has a somewhat similar concept called &#8216;Categories&#8217;.  However traits differ in some notable ways: (1) traits unlike categories can be composed from multiple traits to build up new traits from existing traits (2) the rules for injecting trait methods into a class are slightly different (3) traits provide more control on how they are added into other traits or classes (via aliasing and excluding exported method names).  Thanks for the feedback!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jhurstus</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270056</link>
		<dc:creator>jhurstus</dc:creator>
		<pubDate>Mon, 22 Dec 2008 23:40:31 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270056</guid>
		<description>@ThomasHansen: I&#039;d echo Malde&#039;s comment.   I&#039;ll pass along your Eiffel observation to the people who did invent traits to see what they have to say.  Now that you mention it, it seems a little arbitrary that they limited the &#039;requires&#039; feature to method names as opposed to method signatures or full on contracts like Eiffel.  I suspect that this may have to do with the environment in which traits were first implemented (SmallTalk/Squeak).

@Malde I think it does.   I got in touch with one of the authors of the original traits research paper who said he would take a look at my implementation to make sure it matches their conception of traits, so we should know for sure soon.  My implementation does handle the specific case you mentioned correctly (unless one of the conflicting methods is excluded, of course, in which case there is no conflict to resolve).</description>
		<content:encoded><![CDATA[<p>@ThomasHansen: I&#8217;d echo Malde&#8217;s comment.   I&#8217;ll pass along your Eiffel observation to the people who did invent traits to see what they have to say.  Now that you mention it, it seems a little arbitrary that they limited the &#8216;requires&#8217; feature to method names as opposed to method signatures or full on contracts like Eiffel.  I suspect that this may have to do with the environment in which traits were first implemented (SmallTalk/Squeak).</p>
<p>@Malde I think it does.   I got in touch with one of the authors of the original traits research paper who said he would take a look at my implementation to make sure it matches their conception of traits, so we should know for sure soon.  My implementation does handle the specific case you mentioned correctly (unless one of the conflicting methods is excluded, of course, in which case there is no conflict to resolve).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Malde</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270054</link>
		<dc:creator>Malde</dc:creator>
		<pubDate>Mon, 22 Dec 2008 22:18:49 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270054</guid>
		<description>@ThomasHansenI don&#039;t think Joey claims to have invented anything. Traits are a (well) known term in object oriented programming and there are implementation for most dynamic programming languages. THe original impl. was in Smalltalk.

@Joey Does your library implement correct semantics for Trade composition. For example if one trade composes another and both implement the same method, does this method become a required method of the trait? Joose does not fully hit the required hehavior here. Moose::Role does.</description>
		<content:encoded><![CDATA[<p>@ThomasHansenI don&#8217;t think Joey claims to have invented anything. Traits are a (well) known term in object oriented programming and there are implementation for most dynamic programming languages. THe original impl. was in Smalltalk.</p>
<p>@Joey Does your library implement correct semantics for Trade composition. For example if one trade composes another and both implement the same method, does this method become a required method of the trait? Joose does not fully hit the required hehavior here. Moose::Role does.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ThomasHansen</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270053</link>
		<dc:creator>ThomasHansen</dc:creator>
		<pubDate>Mon, 22 Dec 2008 21:49:11 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270053</guid>
		<description>Congrats, looks like you&#039;ve re-invented the &quot;Design by Contract&quot; concept from Eiffel ... ;)
Still, probably great innovation - though just needed to say this...
.
Anyway, you can pull this *way* further also (by reading the specifications on &quot;Design by Contract&quot;) which also includes stuff like pre and post conditions on variables, return values etc...?
Though Eiffel I think does this (to some extend) compile time, which obviously is impossible in JS...
.
Anyway, doesn&#039;t Cappuccino have these mechanisms too...?</description>
		<content:encoded><![CDATA[<p>Congrats, looks like you&#8217;ve re-invented the &#8220;Design by Contract&#8221; concept from Eiffel &#8230; ;)<br />
Still, probably great innovation &#8211; though just needed to say this&#8230;<br />
.<br />
Anyway, you can pull this *way* further also (by reading the specifications on &#8220;Design by Contract&#8221;) which also includes stuff like pre and post conditions on variables, return values etc&#8230;?<br />
Though Eiffel I think does this (to some extend) compile time, which obviously is impossible in JS&#8230;<br />
.<br />
Anyway, doesn&#8217;t Cappuccino have these mechanisms too&#8230;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MattCoz</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270048</link>
		<dc:creator>MattCoz</dc:creator>
		<pubDate>Mon, 22 Dec 2008 20:13:50 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270048</guid>
		<description>This looks a lot like MooTools, which uses the Java-like &quot;Extends&quot; and &quot;Implements&quot;.  It is very useful.</description>
		<content:encoded><![CDATA[<p>This looks a lot like MooTools, which uses the Java-like &#8220;Extends&#8221; and &#8220;Implements&#8221;.  It is very useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jhurstus</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270046</link>
		<dc:creator>jhurstus</dc:creator>
		<pubDate>Mon, 22 Dec 2008 19:54:16 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270046</guid>
		<description>littlefyr: I definitely understand your concern.

I somewhat agree with your comments re pseudo-classical inheritance in JS.  For this reason, JSTraits was designed to be easily plugged into just about any existing inheritance mechanism, including Crockford&#039;s parasitic/beget inheritance to which you allude.  As noted in the JSTrait&#039;s documentation, the &#039;Class.define&#039; method is included mostly for testing convenience.  The core traits functionality could be (and I hope will be) added to just about any existing JS inheritance mechanism, not just the thin pseudo-classical one I&#039;ve included in JSTraits for examples/testing.

I&#039;d also argue that traits fit very well with prototype based inheritance.  Self, the language from which JS pretty much stole its prototype OO model, actually has a feature also known as &quot;traits&quot; that is very similar to what JSTraits provides.  The two were a natural fit in Self, and I suspect, just as you do, that the same will be true of JS and JSTraits.

It&#039;s both a blessing and a curse to work in a language that is flexible enough to easily accommodate changes to something as fundamental as the OO system.  On the one hand, programmers can easily adapt the language to their own tastes or to better fit the problem at hand.  On the flip side, these same customizations can lead to nasty compatibility issues when you try to pull in outside libraries that do not use the same idioms and language extensions of the rest of your code base.  I&#039;ve noticed that there is a continuum in this regard with extremely flexible languages like Lisp (defmacro...) populating one end, and more locked down languages like Java populating the other end.  JavaScript seems to fall somewhere near the Lisp side.</description>
		<content:encoded><![CDATA[<p>littlefyr: I definitely understand your concern.</p>
<p>I somewhat agree with your comments re pseudo-classical inheritance in JS.  For this reason, JSTraits was designed to be easily plugged into just about any existing inheritance mechanism, including Crockford&#8217;s parasitic/beget inheritance to which you allude.  As noted in the JSTrait&#8217;s documentation, the &#8216;Class.define&#8217; method is included mostly for testing convenience.  The core traits functionality could be (and I hope will be) added to just about any existing JS inheritance mechanism, not just the thin pseudo-classical one I&#8217;ve included in JSTraits for examples/testing.</p>
<p>I&#8217;d also argue that traits fit very well with prototype based inheritance.  Self, the language from which JS pretty much stole its prototype OO model, actually has a feature also known as &#8220;traits&#8221; that is very similar to what JSTraits provides.  The two were a natural fit in Self, and I suspect, just as you do, that the same will be true of JS and JSTraits.</p>
<p>It&#8217;s both a blessing and a curse to work in a language that is flexible enough to easily accommodate changes to something as fundamental as the OO system.  On the one hand, programmers can easily adapt the language to their own tastes or to better fit the problem at hand.  On the flip side, these same customizations can lead to nasty compatibility issues when you try to pull in outside libraries that do not use the same idioms and language extensions of the rest of your code base.  I&#8217;ve noticed that there is a continuum in this regard with extremely flexible languages like Lisp (defmacro&#8230;) populating one end, and more locked down languages like Java populating the other end.  JavaScript seems to fall somewhere near the Lisp side.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: littlefyr</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270040</link>
		<dc:creator>littlefyr</dc:creator>
		<pubDate>Mon, 22 Dec 2008 18:54:22 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270040</guid>
		<description>I would be a lot happier with this approach if it leveraged the existing JavaScript semantics for creating objects and prototypes. I think that Doug Crockford has sufficiently docuemented the &quot;JavaScript Way&quot; to objects from which you can create new objects. Yet another code framework that abuses JavaScript into a classical inheritance model is not a good thing.

However, I suspect that this represents some very useful syntax sugar that could easily be adapted to the approaches that Douglas recommends.</description>
		<content:encoded><![CDATA[<p>I would be a lot happier with this approach if it leveraged the existing JavaScript semantics for creating objects and prototypes. I think that Doug Crockford has sufficiently docuemented the &#8220;JavaScript Way&#8221; to objects from which you can create new objects. Yet another code framework that abuses JavaScript into a classical inheritance model is not a good thing.</p>
<p>However, I suspect that this represents some very useful syntax sugar that could easily be adapted to the approaches that Douglas recommends.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cromwellian</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270039</link>
		<dc:creator>cromwellian</dc:creator>
		<pubDate>Mon, 22 Dec 2008 18:46:34 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270039</guid>
		<description>Traits are also built into Scala :)</description>
		<content:encoded><![CDATA[<p>Traits are also built into Scala :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jhurstus</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270038</link>
		<dc:creator>jhurstus</dc:creator>
		<pubDate>Mon, 22 Dec 2008 18:11:07 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270038</guid>
		<description>Malde: It does indeed look like Joose and JSTraits provide very similar traits/roles functionality.  I&#039;ll do a deeper comparison sometime this week to see if either project could benefit from the inclusion of the other&#039;s code.  Thanks for the pointer.</description>
		<content:encoded><![CDATA[<p>Malde: It does indeed look like Joose and JSTraits provide very similar traits/roles functionality.  I&#8217;ll do a deeper comparison sometime this week to see if either project could benefit from the inclusion of the other&#8217;s code.  Thanks for the pointer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Malde</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270034</link>
		<dc:creator>Malde</dc:creator>
		<pubDate>Mon, 22 Dec 2008 17:15:27 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270034</guid>
		<description>Traits are called Roles in Joose. Here is the same example using Joose roles:
http://code.google.com/p/joose-js/wiki/CookbookRecipe6</description>
		<content:encoded><![CDATA[<p>Traits are called Roles in Joose. Here is the same example using Joose roles:<br />
<a href="http://code.google.com/p/joose-js/wiki/CookbookRecipe6" rel="nofollow">http://code.google.com/p/joose-js/wiki/CookbookRecipe6</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: HelderMagalhaes</title>
		<link>http://ajaxian.com/archives/towards-better-reuse-traits-in-javascript/comment-page-1#comment-270033</link>
		<dc:creator>HelderMagalhaes</dc:creator>
		<pubDate>Mon, 22 Dec 2008 16:59:10 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=5474#comment-270033</guid>
		<description>Well, without going too deep about this &lt;i&gt;traits&lt;/i&gt; concept, I&#039;d just like to leave a note about a potential confusion with the &lt;a href=&quot;http://www.w3.org/TR/SVGMobile12/svgudom.html#Attribute_Access&quot; rel=&quot;nofollow&quot;&gt;&lt;i&gt;traits&lt;/i&gt; concept of SVG Mobile 1.2&lt;/a&gt;:

&lt;blockquote&gt;A trait is the typed value (e.g. a number, not just a string), associated with an element by an XML attribute or a CSS property. The trait facilities in the SVG uDOM allow for strongly-typed access to certain attribute and property values.&lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<p>Well, without going too deep about this <i>traits</i> concept, I&#8217;d just like to leave a note about a potential confusion with the <a href="http://www.w3.org/TR/SVGMobile12/svgudom.html#Attribute_Access" rel="nofollow"><i>traits</i> concept of SVG Mobile 1.2</a>:</p>
<blockquote><p>A trait is the typed value (e.g. a number, not just a string), associated with an element by an XML attribute or a CSS property. The trait facilities in the SVG uDOM allow for strongly-typed access to certain attribute and property values.</p></blockquote>
]]></content:encoded>
	</item>
</channel>
</rss>

