Traits in PHP

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Traits in PHP

blake watson
Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Stéphane Ducasse
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/
>


Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

EstebanLM
cool :)

yeah, next tool generation (glamoroust?) should be made taking traits in mind

best,
Esteban

El 15/02/2012, a las 7:45a.m., Stéphane Ducasse escribió:

> 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/
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Damien Cassou
In reply to this post by Stéphane Ducasse
On Wed, Feb 15, 2012 at 11:45 AM, Stéphane Ducasse
<[hidden email]> wrote:
> Indeed. Now I would love that we rethink our trait implementation and tool support but no time.

Give me a position, I will take care of that :-)

--
Damien Cassou
http://damiencassou.seasidehosting.st

"Lambdas are relegated to relative obscurity until Java makes them
popular by not having them." James Iry

Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Stéphane Ducasse

On Feb 15, 2012, at 4:55 PM, Damien Cassou wrote:

> On Wed, Feb 15, 2012 at 11:45 AM, Stéphane Ducasse
> <[hidden email]> wrote:
>> Indeed. Now I would love that we rethink our trait implementation and tool support but no time.
>
> Give me a position, I will take care of that :-)

we have one :)
and indeed it would be reeeallllllly cool.

Stef
>

Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Hernan Wilkinson-3
In reply to this post by Stéphane Ducasse
what is the difference with the current trait implementation in pharo? I could not see the difference...

On Wed, Feb 15, 2012 at 7:45 AM, Stéphane Ducasse <[hidden email]> 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: [hidden email]
site: http://www.10Pines.com
Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina

Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Stefan Marr-3
Hi Hernan:

On 15 Feb 2012, at 23:30, Hernan Wilkinson wrote:

> what is the difference with the current trait implementation in pharo? I could not see the difference...

There are only cosmetic differences. (If I remember correctly what Pharo's traits entail.)

Most importantly, you cannot exclude arbitrary methods from a trait.
Thus, there is no exclude operator.
Instead, conflicts are resolved by explicitly stating which method wins a conflict with the insteadof keyword.

And, because PHP has a much more dynamic notion of object fields/slots, I added a couple of rules to make that manageable. https://wiki.php.net/rfc/horizontalreuse#handling_of_propertiesstate
The main idea is, break on obviously incompatible things, and leave the rest to the normal dynamic semantics. (which means, we do not have a solution for state).

Best regards
Stefan


--
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax:   +32 2 629 3525


Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Stéphane Ducasse
In reply to this post by Hernan Wilkinson-3

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 <[hidden email]> 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: [hidden email]
> site: http://www.10Pines.com
> Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina
>


Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Hernan Wilkinson-3
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 <[hidden email]> 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 <[hidden email]> 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: [hidden email]
> 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: [hidden email]
site: http://www.10Pines.com
Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina

Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Nicolas Passerini
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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: [hidden email]
> 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: [hidden email]
site: http://www.10Pines.com
Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina


Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Mariano Martinez Peck
In reply to this post by Hernan Wilkinson-3


On Thu, Feb 16, 2012 at 3:04 PM, Hernan Wilkinson <[hidden email]> 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,

For the slower ones ... why would first class slots solves this?  I didn't get it.

Thanks!

 
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 <[hidden email]> 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 <[hidden email]> 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: <a href="tel:%2B54%20-%20911%20-%204470%20-%207207" value="+5491144707207" target="_blank">+54 - 911 - 4470 - 7207
> email: [hidden email]
> site: http://www.10Pines.com
> Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina
>





--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Mobile: <a href="tel:%2B54%20-%20911%20-%204470%20-%207207" value="+5491144707207" target="_blank">+54 - 911 - 4470 - 7207
email: [hidden email]
site: http://www.10Pines.com
Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina




--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Hernan Wilkinson-3
if you use an object model a la Self, there is no difference between an instance variable and a method from the "sender" point of view. So, in this code "self name", name could be implemented as a "data slot" (a slot that references an object) or a "method slot", it is up to the receiver. 
So, the sender always sends the message #name, no matter if name is implemented as method or "variable". At the end it is not first class slots what solves the problem but the uniformity of using only message send to represent computation (no variable assingments, etc).

So, going to the trait example, if the trait says "self name", the class that uses that trait could implement "name" as a data slot or method slot, it does not matter to the trait and therefore the trait is state agnostic... at least that is what I understood from Stef comment :-), but may be he meant other thing! :-)


On Thu, Feb 16, 2012 at 2:11 PM, Mariano Martinez Peck <[hidden email]> wrote:


On Thu, Feb 16, 2012 at 3:04 PM, Hernan Wilkinson <[hidden email]> 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,

For the slower ones ... why would first class slots solves this?  I didn't get it.

Thanks!

 
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 <[hidden email]> 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 <[hidden email]> 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: <a href="tel:%2B54%20-%20911%20-%204470%20-%207207" value="+5491144707207" target="_blank">+54 - 911 - 4470 - 7207
> email: [hidden email]
> site: http://www.10Pines.com
> Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina
>





--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Mobile: <a href="tel:%2B54%20-%20911%20-%204470%20-%207207" value="+5491144707207" target="_blank">+54 - 911 - 4470 - 7207
email: [hidden email]
site: http://www.10Pines.com
Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina




--
Mariano
http://marianopeck.wordpress.com




--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Mobile: +54 - 911 - 4470 - 7207
email: [hidden email]
site: http://www.10Pines.com
Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina

Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Hernan Wilkinson-3
In reply to this post by Nicolas Passerini
It looks interesting, but how this relates to the state issue?

On Thu, Feb 16, 2012 at 12:35 PM, Nicolas Passerini <[hidden email]> wrote:
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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: [hidden email]
> 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: [hidden email]
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: [hidden email]
site: http://www.10Pines.com
Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina

Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Stéphane Ducasse
In reply to this post by Nicolas Passerini

On Feb 16, 2012, at 4:35 PM, Nicolas Passerini wrote:

> 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?

I do not think that I want that.
Because:
        what about tools support?
        I do not see the use case.

Now you can do prototypes for fun.
Stef
Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Nicolas Passerini
In reply to this post by Hernan Wilkinson-3


On Thu, Feb 16, 2012 at 4:20 PM, Hernan Wilkinson <[hidden email]> wrote:
It looks interesting, but how this relates to the state issue?


 
It is not directly related to the state issue. Just to different trait models, I think that it would be a nice yet very simple enhancement, to be able add a trait directly to an object at instantiation time istead of always having to create a new class.

I apologise if my mail was confusing.

However mi little traits extension has also something to say about state. When I do:
myObject := (MyClass with: MyTrait) new

The class of myObject is created dynamically, so I can have MyTrait declaring its required state an then the instance variables are created automatically. It is also a little extension to declaring required methods.


Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Nicolas Cellier
In reply to this post by Stéphane Ducasse
Le 16 février 2012 22:09, Stéphane Ducasse <[hidden email]> a écrit :

>
> On Feb 16, 2012, at 4:35 PM, Nicolas Passerini wrote:
>
>> 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?
>
> I do not think that I want that.
> Because:
>        what about tools support?
>        I do not see the use case.
>
> Now you can do prototypes for fun.
> Stef

I find it interesting if ever you create plenty composition options
and don't want to provide a static implementation for the whole set of
partitions
N composable traits => (2 raisedTo: N) partitions...
This also avoid to have a whole zoo of class names.
But then, each instance will have it's own class copy created on the
gly, which might be suboptimal. Unless we cache...

Here is a dumb example (with stateful traits): you want to stop
wasting 12 bits of identity hash in each object header, when you only
rarely put these objects in identity hashed collections... You thus
add the trait on the fly

IdentityDictionary at: key put: value
    key acquireIdentityHash.
    snip...

Object>>acquireIdentityHash
    ^self becomeForward: ((self class withTrait: IdentityHashed)
basicNew copyStatesFrom: self; initializeIdentityHash)

IdentityHashed>>acquireIdentityHash
   ^self

IdentityHashed>>initializeIdentityHash
    identityHash ifNil: [identityHash := self createRandomIdentityHash]

IdentityHashed>>identityHash
    ^identityHash


If this was possible, you would of course not duplicate each class
with its IdentityHashed variant :)

Nicolas

Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Hernan Wilkinson-3
In reply to this post by Nicolas Passerini
oh, ok. Yeah, I like the idea, but I agree with stef that you need tool support... an environment like Self for example

On Thu, Feb 16, 2012 at 6:11 PM, Nicolas Passerini <[hidden email]> wrote:


On Thu, Feb 16, 2012 at 4:20 PM, Hernan Wilkinson <[hidden email]> wrote:
It looks interesting, but how this relates to the state issue?


 
It is not directly related to the state issue. Just to different trait models, I think that it would be a nice yet very simple enhancement, to be able add a trait directly to an object at instantiation time istead of always having to create a new class.

I apologise if my mail was confusing.

However mi little traits extension has also something to say about state. When I do:
myObject := (MyClass with: MyTrait) new

The class of myObject is created dynamically, so I can have MyTrait declaring its required state an then the instance variables are created automatically. It is also a little extension to declaring required methods.





--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Mobile: +54 - 911 - 4470 - 7207
email: [hidden email]
site: http://www.10Pines.com
Address: Paraguay 523, Floor 7 N, Buenos Aires, Argentina

Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Nicolas Passerini


On Thu, Feb 16, 2012 at 7:35 PM, Hernan Wilkinson <[hidden email]> wrote:
oh, ok. Yeah, I like the idea, but I agree with stef that you need tool support... an environment like Self for example

I agree, it would need some tool support, I didn't have time to work on it yet.

Which kind of tool support do you think we would need? 
(I love many of the ideas in Self, but the environment is not one of them.)

One thing I would like to put some work on is refactorings for traits (including some not necessarily related with the previous idea).

Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Stéphane Ducasse

>
>
> On Thu, Feb 16, 2012 at 7:35 PM, Hernan Wilkinson <[hidden email]> wrote:
> oh, ok. Yeah, I like the idea, but I agree with stef that you need tool support... an environment like Self for example
>
> I agree, it would need some tool support, I didn't have time to work on it yet.
>
> Which kind of tool support do you think we would need?
> (I love many of the ideas in Self, but the environment is not one of them.)
>
> One thing I would like to put some work on is refactorings for traits (including some not necessarily related with the previous idea).
Indeed.

I do not see why we would like to have object level trait. May be in ruby but not in class-based language or this is not a class based language
anymore.


Reply | Threaded
Open this post in threaded view
|

Re: Traits in PHP

Frank Shearar-3
Smalltalk _uses_ classes, but there's no "class" in "everything's an
object, and objects communicate by sending messages".

That aside, while Ruby _supports_ something like "object level trait"
in the form of eigenclasses, mixins seem much more like how Gilad
describes them, and "parameterised subclasses" - classes that take a
superclass as parameter.

That means that Array withTrait: IdentityHashed. Object withTrait:
IdentityHashed creates _classes_, something like this:

       Array                Object
         ^                    ^
         |                    |
  (IdentityHashed)     (IdentityHashed)

frank

On 17 February 2012 05:18, Stéphane Ducasse <[hidden email]> wrote:

>
>>
>>
>> On Thu, Feb 16, 2012 at 7:35 PM, Hernan Wilkinson <[hidden email]> wrote:
>> oh, ok. Yeah, I like the idea, but I agree with stef that you need tool support... an environment like Self for example
>>
>> I agree, it would need some tool support, I didn't have time to work on it yet.
>>
>> Which kind of tool support do you think we would need?
>> (I love many of the ideas in Self, but the environment is not one of them.)
>>
>> One thing I would like to put some work on is refactorings for traits (including some not necessarily related with the previous idea).
> Indeed.
>
> I do not see why we would like to have object level trait. May be in ruby but not in class-based language or this is not a class based language
> anymore.
>
>

12