I think it would be very nice to be able to apply a trait directly to an
object, without having to create a new class.
This is possible for example in scala:

val myObject = new MyClass with MyTrait

I have programmed a simple implementation in Pharo which allows you to do:

myObject := (MyClass with: MyTrait) new.

The implementation is only a proof of concept and has some issues that
should be addressed before being able to use it in a real program, but I
can make it available if someone is interested.

What do you think about this?



On Thu, Feb 16, 2012 at 11:04 AM, Hernan Wilkinson <
hernan.wilkin...@10pines.com> wrote:

> I have an idea about the state issue in traits, maybe you thought about it
> too... I was thinking that the definition of representing something as
> state or not should be responsibility of the implementation, that is the
> class (nothing new here), so we delay that decision until the trait is
> used.
> So, maybe what we need is a way to indicate that a message send in a trait
> is not really that in a class... For example:
>
> TraitA>>m1
>
>     ^self name first
>
> Object subclass: #ClassA
>     uses: #TraitA
>     mapping: (MessageSendToInstanceVariable from: #name to: 'firstName')
> ... bla bla.
>
> So, #m1 in ClassA would look like:
>
> ClassA>>m1
>
>    ^firstName first
>
> Of course this implies some complexity when copying the behavior from the
> trait to the class (we can not use the same compiled method), also
> maintaining the relationship with changes on the trait (what happens if #m1
> is changed in TraitA and does not send #name anymore), etc.
> First class slot (a la Self) would be a nicer solution, but I feel that
> that implies a more radical change on the object model, vm, etc. and also
> has the disadvantages of making all state public (unless something is done
> to avoid that).
>
> At the same time, I would like to point out that having subclassing and
> traits at the same time as sharing mechanism is kind of confusing,
> programmers do not know which one is better to use, should I subclass or
> use a trait? how I'm sure which one is better? etc. We talk about this when
> you came to Argentina, do you remember? A student did his tesis about
> removing subclassing and using only traits as sharing tool, but the results
> were not as good as I expected (sadly, the thesis is written in Spanish...)
>
> Anyway, my two cents
> Hernan.
>
>
> On Thu, Feb 16, 2012 at 4:56 AM, Stéphane Ducasse <
> stephane.duca...@inria.fr> wrote:
>
>>
>> On Feb 15, 2012, at 11:30 PM, Hernan Wilkinson wrote:
>>
>> > what is the difference with the current trait implementation in pharo?
>> I could not see the difference…
>>
>> Stefan replied but what I wanted to say is that I would like to have the
>> time to see how we can introduce more nicely traits.
>> Right now there are edges where this is ugly and also rethink the system.
>> I think that if we would have first class slots we could have
>> traits with state in a much better fashion.
>>
>> Stef
>>
>> > On Wed, Feb 15, 2012 at 7:45 AM, Stéphane Ducasse <
>> stephane.duca...@inria.fr> wrote:
>> > Indeed. Now I would love that we rethink our trait implementation and
>> tool support but no time.
>> >
>> > On Feb 15, 2012, at 6:40 AM, blake wrote:
>> >
>> > > This is kinda cool:
>> > >
>> > > http://phpmaster.com/using-traits-in-php-5-4/
>> > >
>> >
>> >
>> >
>> >
>> >
>> > --
>> > Hernán Wilkinson
>> > Agile Software Development, Teaching & Coaching
>> > Mobile: +54 - 911 - 4470 - 7207
>> > email: hernan.wilkin...@10pines.com
>> > site: http://www.10Pines.com
>> > Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina
>> >
>>
>>
>>
>
>
> --
> *Hernán Wilkinson
> Agile Software Development, Teaching & Coaching
> Mobile: +54 - 911 - 4470 - 7207
> email: hernan.wilkin...@10pines.com
> site: http://www.10Pines.com <http://www.10pines.com/>*
> Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina
>
>

Reply via email to