[prev in list] [next in list] [prev in thread] [next in thread] 

List:       groovy-dev
Subject:    Re: [groovy-dev] Re: Adding @Trait to Groovy
From:       Marcin Gryszko <marcin () grysz ! com>
Date:       2013-07-02 18:56:00
Message-ID: CABH-wkxnwGDRQoJTathndhBihDMt_KrM3k5gbpyP6ur6Jyr6tQ () mail ! gmail ! com
[Download RAW message or body]

From the user point of view, stateful traits would be extremely useful. In
our case we use a lot of mixins for testing, but they are sometimes leaky -
besides mixing in a category, we have to declare explicitly collaborators
that the category requires.

Stateful mixins open a whole new range of design options - I can decide if
I want to use composition or multiple inheritance. In our Grails
application we have an ubiquitous service that wraps Spring MessageSource.
We inject this component into all services that have to generate
internationalized strings. Having traits, we could just add a field with a
MessageSource instance injected by Spring DI and a method that wraps a call
to MessageSource. I'm not sure if this design is better, but it's an option
> )

On the other hand stateless traits (although they seem easier to implement)
would be just better (or fixed) mixins.

Just my 2 ˘

Marcin Gryszko  <http://twitter.com/mgryszko>
<https://plus.google.com/112949188816397592850>
  <http://xing.com/profile/Marcin_Gryszko> <http://linkedin.com/in/mgryszko>
  <http://grysz.com>  <http://slideshare.net/mgryszko>


On Wed, Jun 26, 2013 at 5:13 PM, Guillaume Laforge <glaforge@codehaus.org>wrote:

> For those who want to play with that "trait" branch, I'll remind some
> quick instructions:
> 
> // add CĂ©dric's remote branch
> git add remote melix  https://github.com/melix/groovy-core.git
> 
> // fetch the branch
> git fetch melix
> 
> // checkout the branch with the trait experiment
> git checkout trait-experiment-phase2
> 
> // build Groovy
> ./gradlew iG
> 
> // then point your GROOVY_HOME to ./target/install
> export GROOVY_HOME=./target/install
> 
> // or if you use GVM, you can do
> gvm install groovy dev ./target/install
> 
> Then launch the Groovy console, for example, to try the examples we've
> given in this thread.
> 
> Have fun and give us your feedback :-)
> 
> Guillaume
> 
> 
> On Wed, Jun 26, 2013 at 4:40 PM, Guillaume Laforge <glaforge@codehaus.org>wrote:
> 
> > On top of CĂ©dric's recent changes, I've also pushed to his branch the
> > usage of the "trait" keyword.
> > 
> > So you can do
> > 
> > trait Nameable { String name } instead of @Trait class Nameable { String
> > name }.
> > 
> > 
> > On Tue, Jun 25, 2013 at 10:28 AM, CĂ©dric Champeau <
> > cedric.champeau@gmail.com> wrote:
> > 
> > > Hi guys,
> > > 
> > > I have made some updates to the
> > > https://github.com/melix/groovy-core/tree/trait-experiment-phase2branch. Now I \
> > > have initial support for properties, setters and closures defined in traits. \
> > > Generics are still not supported (Guillaume ;)). 
> > > I'd be glad to hear from you regarding this approach. Of course, there's
> > > a lot of work to do and we have a lot of questions to answer:
> > > 
> > > - what about annotations on traits, or members of traits?
> > > - what about AST transformations on traits? Should they be supported
> > > (my guess is yes)?
> > > - how about trait inheritance?
> > > - support for unary expressions (field++, field+=), ...
> > > - compatibility with static compilation (related to the ability to
> > > apply AST xforms on traits)?
> > > - dynamic traits? def duck = Trait.create(Duck, Swimming, Flying,
> > > name: 'Duffy')
> > > - your ideas here...
> > > 
> > > --
> > > CĂ©dric Champeau
> > > SpringSource - \
> > > Pivotalhttp://www.springsource.org/http://www.gopivotal.com/http://twitter.com/CedricChampeau
> > >  
> > > 
> > 
> > 
> > --
> > Guillaume Laforge
> > Groovy Project Manager
> > Head of Groovy Development at SpringSource
> > http://www.springsource.com/g2one
> > 
> 
> 
> 
> --
> Guillaume Laforge
> Groovy Project Manager
> Head of Groovy Development at SpringSource
> http://www.springsource.com/g2one
> 


[Attachment #3 (text/html)]

<div dir="ltr"><div style>From the user point of view, stateful traits would be \
extremely useful. In our case we use a lot of mixins for testing, but they are \
sometimes leaky - besides mixing in a category, we have to declare explicitly \
collaborators that the category requires.<br>

</div><div><br></div><div style>Stateful mixins open a whole new range of design \
options - I can decide if I want to use composition or multiple inheritance. In our \
Grails application we have an ubiquitous service that wraps Spring MessageSource. We \
inject this component into all services that have to generate internationalized \
strings. Having traits, we could just add a field with a MessageSource instance \
injected by Spring DI and a method that wraps a call to MessageSource. I&#39;m not \
sure if this design is better, but it&#39;s an option :)  </div>

<div><br></div><div style>On the other hand stateless traits (although they seem \
easier to implement) would be just better (or fixed) mixins.</div><div \
style><br></div><div style>Just my  <span \
style="color:rgb(68,68,68);font-family:arial,sans-serif;line-height:12.800000190734863px">2 \
˘</span></div>

</div><div class="gmail_extra"><br clear="all"><div>Marcin Gryszko  <a \
href="http://twitter.com/mgryszko" target="_blank"><img \
src="http://images.wisestamp.com/twitter.png"></a>  <a \
href="https://plus.google.com/112949188816397592850" target="_blank"><img \
src="http://images.wisestamp.com/googleplus.png"></a>  <a \
href="http://xing.com/profile/Marcin_Gryszko" target="_blank"><img \
src="http://images.wisestamp.com/xing.png"></a>  <a \
href="http://linkedin.com/in/mgryszko" target="_blank"><img \
src="http://images.wisestamp.com/linkedin.png"></a>  <a href="http://grysz.com" \
target="_blank"><img src="http://images.wisestamp.com/wordpress.png"></a>  <a \
href="http://slideshare.net/mgryszko" target="_blank"><img \
src="http://images.wisestamp.com/apps/slideshare.png"></a></div>


<br><br><div class="gmail_quote">On Wed, Jun 26, 2013 at 5:13 PM, Guillaume Laforge \
<span dir="ltr">&lt;<a href="mailto:glaforge@codehaus.org" \
target="_blank">glaforge@codehaus.org</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">

<div dir="ltr">For those who want to play with that &quot;trait&quot; branch, \
I&#39;ll remind some quick instructions:<div><br></div><div>// add CĂ©dric&#39;s \
remote branch</div><div><div>git add remote melix   <a \
href="https://github.com/melix/groovy-core.git" \
target="_blank">https://github.com/melix/groovy-core.git</a></div>


<div><br></div><div>// fetch the branch</div><div>git fetch \
melix</div></div><div><br></div><div>// checkout the branch with the trait \
experiment</div><div>git checkout trait-experiment-phase2</div> \
<div><br></div><div>// build Groovy</div><div>./gradlew \
iG</div><div><br></div><div>// then point your GROOVY_HOME to \
./target/install</div><div>export GROOVY_HOME=./target/install</div> \
<div><br></div><div>// or if you use GVM, you can do</div><div>gvm install groovy dev \
./target/install</div><div><br></div><div>Then launch the Groovy console, for \
example, to try the examples we&#39;ve given in this thread.</div>


<div><br></div><div>Have fun and give us your feedback :-)</div><span \
class="HOEnZb"><font \
color="#888888"><div><br></div><div>Guillaume</div></font></span></div><div \
class="HOEnZb"><div class="h5"><div class="gmail_extra">

<br><br><div class="gmail_quote">On Wed, Jun 26, 2013 at 4:40 PM, Guillaume Laforge \
<span dir="ltr">&lt;<a href="mailto:glaforge@codehaus.org" \
target="_blank">glaforge@codehaus.org</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">On top of CĂ©dric&#39;s recent changes, \
I&#39;ve also pushed to his branch the usage of the &quot;trait&quot; keyword.<div>


<br></div><div>So you can do  </div><div><br></div><div>trait Nameable { String name \
} instead of @Trait class Nameable { String name }.</div> </div><div \
class="gmail_extra"><div><div><br><br><div class="gmail_quote">On Tue, Jun 25, 2013 \
at 10:28 AM, CĂ©dric Champeau <span dir="ltr">&lt;<a \
href="mailto:cedric.champeau@gmail.com" \
target="_blank">cedric.champeau@gmail.com</a>&gt;</span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <div>Hi guys,<br>
      <br>
      I have made some updates to the
      
      <a href="https://github.com/melix/groovy-core/tree/trait-experiment-phase2" \
target="_blank">https://github.com/melix/groovy-core/tree/trait-experiment-phase2</a> \
branch. Now I have initial support for properties, setters and  closures defined in \
traits. Generics are still not supported  (Guillaume ;)).<br>
      <br>
      I&#39;d be glad to hear from you regarding this approach. Of course,
      there&#39;s a lot of work to do and we have a lot of questions to
      answer:<br>
      <br>
             - what about annotations on traits, or members of traits?<br>
             - what about AST transformations on traits? Should they be
      supported (my guess is yes)?<br>
             - how about trait inheritance?<br>
             - support for unary expressions (field++, field+=), ...<br>
             - compatibility with static compilation (related to the
      ability to apply AST xforms on traits)?<br>
             - dynamic traits? def duck = Trait.create(Duck, Swimming,
      Flying, name: &#39;Duffy&#39;)<br>
             - your ideas here...<br>
    </div><div>
    <pre cols="72">-- 
CĂ©dric Champeau
SpringSource - Pivotal
<a href="http://www.springsource.org/" \
target="_blank">http://www.springsource.org/</a> <a href="http://www.gopivotal.com/" \
target="_blank">http://www.gopivotal.com/</a> <a \
href="http://twitter.com/CedricChampeau" \
target="_blank">http://twitter.com/CedricChampeau</a></pre>  </div></div>

</blockquote></div><br><br clear="all"><div><br></div></div></div><div>-- \
<br>Guillaume Laforge<br>Groovy Project Manager<br></div><div>Head of Groovy \
Development at SpringSource<br><a href="http://www.springsource.com/g2one" \
target="_blank">http://www.springsource.com/g2one</a> </div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Guillaume \
Laforge<br>Groovy Project Manager<br>Head of Groovy Development at SpringSource<br><a \
href="http://www.springsource.com/g2one" \
target="_blank">http://www.springsource.com/g2one</a> </div>
</div></div></blockquote></div><br></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic