Le 16 février 2012 22:09, Stéphane Ducasse <stephane.ducasse@inria.fr> 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