[ANN] RubyTraits 0.1

<snip> >

> Hmm, I almost fail to see what merit modules have that traits do not have?
> That you can say isa? for an instance of a class that had a module mixed in?
> Maybe, no idea if this is worth it.

That's one reason. But more importantly, calling super, ie. method
inheritance. Does the formal design of traits have super?

Yup it is one of the cornerstones of the definition, super is resolved
dynamically
in the inheritance chain.
R

···

On 10/15/07, Trans <transfire@gmail.com> wrote:

--
what do I think about Ruby?
http://ruby-smalltalk.blogspot.com/

Robert Dober wrote:

Hi,

>I see. So you don't really like the fact that modules fit into the
>inheritance chain? That's interesting.

Actually they both have their own good. I like them both. I dislike
to have them both in a language. Traits injection is clear and less
error prone (there's no possibility of conflicts), but sometimes
method overriding is _very_ useful, where aliasing is very poor way to
create method combination.

If someone come to the idea to allow modules to have merits from both
mixins and traits at once (without demerit), I'd love to hear.

I solved this "problem" over two years ago with fine grained mixins.
Please see http://rubyforge.org/docman/view.php/735/309/README.html
and look at the synopsis. Ideas (and code) in that library also came
from Ara Howard and Mauricio Fernandez.

I don't want up front object composition. To me that's like static
typing, except for object composition. At worst, a warning should be
issued if a double inclusion occurs. This is what the 'use' library
does in verbose mode.

If what you did solves your problem than that is good, it however does
not address the issues that are adressed by traits.

The multi-mixin (i.e. total ordering) problem is one of the primary reasons for Traits, or at least, one of the main digs against mixin inheritence. My library solves that in a dynamic, but not strict, manner.

And the good thing about traits is that, if you do not want to use
them, then just do not.

As a third party library they're fine. But core? No.

I have followed the discussion on the Squeak Mailing List before
making traits part of the kernel. The killer argument was, ok we are
going to do this because it will make the code base "better" but
nobody will ever need to care about Traits unless they want.
To be fair, Squeak needed Traits much more than Ruby as they had no Mixins.

Exactly. In languages that have no mixins I think Traits are fine and, from what I can gather, it's the mixin capability those languages and communities are really after, not the composition.

OTOH I have never heard anybody complain that traits remind them of
static typing, would you mind to elaborate on that Daniel?

In a couple of ways. First, raising an error if method conflicts arise feels too strict for a dynamic language. I'd like a warning, but nothing more. Also, a trait requires a set of methods that serve as parameters for the provided behavior. Like static typing, that means up-front declarations that don't mesh well with the overall philosophy of dynamic languages IMO.

Regards,

Dan

···

On 10/15/07, Daniel Berger <djberg96@gmail.com> wrote:

On Oct 15, 9:38 am, Yukihiro Matsumoto <m...@ruby-lang.org> wrote:

In message "Re: RubyTraits 0.1" >>> on Tue, 16 Oct 2007 00:23:43 +0900, Trans <transf...@gmail.com> writes:

Hi,

···

In message "Re: RubyTraits 0.1" on Tue, 16 Oct 2007 02:23:30 +0900, Daniel Berger <djberg96@gmail.com> writes:

BTW, I uploaded some more examples here:

http://rubyforge.org/docman/view.php/735/2472/examples.html

How do you think one can choose use and include?
Should :alias be named :rename if it doesn't keep old name?

              matz.

I think you have a minor typo:

class Bar
   use Mod_B, :include => [:meth_b, :meth_c] # include only 'meth_a'
and 'meth_b'
   use Mod_B, :exclude => :meth_c # same net result as
above
end

Shouldn't that be :exclude => :meth_a instead, to get the same net
result?

···

On Oct 15, 11:23 am, Daniel Berger <djber...@gmail.com> wrote:

BTW, I uploaded some more examples here:

http://rubyforge.org/docman/view.php/735/2472/examples.html

Robert Dober wrote:
>>
>>> Hi,
>>>
>>>
>>> >I see. So you don't really like the fact that modules fit into the
>>> >inheritance chain? That's interesting.
>>>
>>> Actually they both have their own good. I like them both. I dislike
>>> to have them both in a language. Traits injection is clear and less
>>> error prone (there's no possibility of conflicts), but sometimes
>>> method overriding is _very_ useful, where aliasing is very poor way to
>>> create method combination.
>>>
>>> If someone come to the idea to allow modules to have merits from both
>>> mixins and traits at once (without demerit), I'd love to hear.
>> I solved this "problem" over two years ago with fine grained mixins.
>> Please see http://rubyforge.org/docman/view.php/735/309/README.html
>> and look at the synopsis. Ideas (and code) in that library also came
>> from Ara Howard and Mauricio Fernandez.
>>
>> I don't want up front object composition. To me that's like static
>> typing, except for object composition. At worst, a warning should be
>> issued if a double inclusion occurs. This is what the 'use' library
>> does in verbose mode.
> If what you did solves your problem than that is good, it however does
> not address the issues that are adressed by traits.

The multi-mixin (i.e. total ordering) problem is one of the primary
reasons for Traits, or at least, one of the main digs against mixin
inheritence. My library solves that in a dynamic, but not strict, manner.

> And the good thing about traits is that, if you do not want to use
> them, then just do not.

As a third party library they're fine. But core? No.

I was not thinking of making it core, and Matz said too that having
Mixins already he will refrain from putting them into core, I feel
that this is a reasonable choice, no hard feelings at all.

<snip>

> OTOH I have never heard anybody complain that traits remind them of
> static typing, would you mind to elaborate on that Daniel?

In a couple of ways. First, raising an error if method conflicts arise
feels too strict for a dynamic language. I'd like a warning, but nothing
more. Also, a trait requires a set of methods that serve as parameters
for the provided behavior. Like static typing, that means up-front
declarations that don't mesh well with the overall philosophy of dynamic
languages IMO.

Hmm honestly I think that your conclusion is correct but your premises are not.
Traits are as dynamical as modules if you just "use" them, the conflict handling
is an extra you get from combining them.
In the semantics of my traits package that would be
class A
   use t1, t2 # conflicts might be defined as this is equivalent to
   # use t1+t2 which is equivalent to use t2 + t1 per definition
end

class A
   use t1
   use t2
end

does almost exactly what you would have with modules only that use t2
will always take effect because of the flattening property.

Forgive me if I am too religious about this, but I feel that traits
are an exciting thing :).

But there is one thing which is "wrong" with my package if you are
going to dynamically extend traits they will break, but that is the
fault of my - simple - implementation not really the fault of traits
:(, it might even be fixable.

Thx for your time.

Cheers
Robert

···

On 10/16/07, Daniel Berger <djberg96@gmail.com> wrote:

> On 10/15/07, Daniel Berger <djberg96@gmail.com> wrote:
>> On Oct 15, 9:38 am, Yukihiro Matsumoto <m...@ruby-lang.org> wrote:
>>> In message "Re: RubyTraits 0.1" > >>> on Tue, 16 Oct 2007 00:23:43 +0900, Trans <transf...@gmail.com> writes:

--
what do I think about Ruby?
http://ruby-smalltalk.blogspot.com/

Hi,

>BTW, I uploaded some more examples here:
>
>http://rubyforge.org/docman/view.php/735/2472/examples.html

How do you think one can choose use and include?

I chose the word "use" because I thought it might be inappropriate to
redefine "include", not because I thought it needed a separate name in
order to distinguish behavior. Note that "use ModA" with no arguments
is the same as "include ModA".

Should :alias be named :rename if it doesn't keep old name?

Hm, you're probably right about that. :slight_smile:

Regards,

Dan

···

On Oct 15, 11:29 am, Yukihiro Matsumoto <m...@ruby-lang.org> wrote:

In message "Re: RubyTraits 0.1" > on Tue, 16 Oct 2007 02:23:30 +0900, Daniel Berger <djber...@gmail.com> writes:

It should be ":include => [:meth_a, :meth_b]"

Fixed at http://rubyforge.org/docman/view.php/735/2472/examples.html\.

Thanks,

Dan

···

On Oct 15, 2:15 pm, Phrogz <phr...@mac.com> wrote:

On Oct 15, 11:23 am, Daniel Berger <djber...@gmail.com> wrote:

> BTW, I uploaded some more examples here:

>http://rubyforge.org/docman/view.php/735/2472/examples.html

I think you have a minor typo:

class Bar
   use Mod_B, :include => [:meth_b, :meth_c] # include only 'meth_a'
and 'meth_b'
   use Mod_B, :exclude => :meth_c # same net result as
above
end

Shouldn't that be :exclude => :meth_a instead, to get the same net
result?

Matz
this is the link to the paper defining? traits, well it defines traits
pretty much as they
are defined in Squeak (and Scala AFAIK and maybe Fortress, not sure).

http://portal.acm.org/ft_gateway.cfm?id=1028771&type=pdf&coll=GUIDE&dl=GUIDE&CFID=7912496&CFTOKEN=77115102

···

On 10/15/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

--
what do I think about Ruby?
http://ruby-smalltalk.blogspot.com/

Although this syntax reads well:
  include ModA, :exclude => :foo
I think this particular syntax appears odd:
  include ModA, :include => :foo
where this is better:
  include ModA, :include => :foo

If 'include' were to be preserved in place of 'use', perhaps instead:
  include ModA, :exclude => :foo
  include ModB, :only => :bar #instead of a 2nd 'include'

···

On Oct 15, 12:54 pm, Daniel Berger <djber...@gmail.com> wrote:

On Oct 15, 11:29 am, Yukihiro Matsumoto <m...@ruby-lang.org> wrote:
> How do you think one can choose use and include?

I chose the word "use" because I thought it might be inappropriate to
redefine "include", not because I thought it needed a separate name in
order to distinguish behavior. Note that "use ModA" with no arguments
is the same as "include ModA".

I'm staring and staring and staring, but #2 still looks the same as #3.

If I cross my eyes, they still look the same, but I also see a 3D Ferris
wheel pop out.

···

On Mon, 15 Oct 2007 13:13:40 -0700, Phrogz wrote:

Although this syntax reads well:
  include ModA, :exclude => :foo
I think this particular syntax appears odd:
  include ModA, :include => :foo
where this is better:
  include ModA, :include => :foo

--
Jay Levitt |
Boston, MA | My character doesn't like it when they
Faster: jay at jay dot fm | cry or shout or hit.
http://www.jay.fm | - Kristoffer

> Although this syntax reads well:
> include ModA, :exclude => :foo
> I think this particular syntax appears odd:
> include ModA, :include => :foo
> where this is better:
> include ModA, :include => :foo

I'm staring and staring and staring, but #2 still looks the same as #3.

If I cross my eyes, they still look the same, but I also see a 3D Ferris
wheel pop out.

Uhm. Yeah. Oops. :slight_smile:

I had meant to type:

Although this syntax reads well:
  include ModA, :exclude => :foo
I think this particular syntax appears odd:
  include ModA, :include => :foo
where this is better:
  use ModA, :include => :foo

...but apparently got lazy. Sorry 'bout that.

Have fun at the 3D circus. :slight_smile:

···

On Oct 15, 3:24 pm, Jay Levitt <jay+n...@jay.fm> wrote:

On Mon, 15 Oct 2007 13:13:40 -0700, Phrogz wrote:

The :include option is the default if no keywords are supplied. So,
you can do this:

use ModA, :foo

If we override 'include', then it's just this:

include ModA, :foo

Regards,

Dan

···

On Oct 15, 3:35 pm, Phrogz <phr...@mac.com> wrote:

On Oct 15, 3:24 pm, Jay Levitt <jay+n...@jay.fm> wrote:

> On Mon, 15 Oct 2007 13:13:40 -0700, Phrogz wrote:
> > Although this syntax reads well:
> > include ModA, :exclude => :foo
> > I think this particular syntax appears odd:
> > include ModA, :include => :foo
> > where this is better:
> > include ModA, :include => :foo

> I'm staring and staring and staring, but #2 still looks the same as #3.

> If I cross my eyes, they still look the same, but I also see a 3D Ferris
> wheel pop out.

Uhm. Yeah. Oops. :slight_smile:

I had meant to type:> Although this syntax reads well:
> include ModA, :exclude => :foo
> I think this particular syntax appears odd:
> include ModA, :include => :foo
> where this is better:
> use ModA, :include => :foo

...but apparently got lazy. Sorry 'bout that.