miss-used become: ???

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

miss-used become: ???

Nicolas Cellier
UnscriptedPlayer>>assureUniClass
        "Create a uniclass and become the receiver into it"

        | anInstance |
        anInstance := self rootClassForUniclasses instanceOfUniqueClass.
        anInstance initializeCostumesFrom: self.
        self become: anInstance.
        ^ anInstance

As I understand it, after the become: self is anInstance and anInstance is self.
So this would answer the original UnscriptedPlayer before the become...
Is this really the intention?
Otherwise, becomeForward: would work better.

Nicolas

Reply | Threaded
Open this post in threaded view
|

Re: miss-used become: ???

Chris Muller-3
Does become: swap the references in the currently executing MethodContext too?


On Fri, Jun 8, 2012 at 4:34 PM, Nicolas Cellier
<[hidden email]> wrote:

> UnscriptedPlayer>>assureUniClass
>        "Create a uniclass and become the receiver into it"
>
>        | anInstance |
>        anInstance := self rootClassForUniclasses instanceOfUniqueClass.
>        anInstance initializeCostumesFrom: self.
>        self become: anInstance.
>        ^ anInstance
>
> As I understand it, after the become: self is anInstance and anInstance is self.
> So this would answer the original UnscriptedPlayer before the become...
> Is this really the intention?
> Otherwise, becomeForward: would work better.
>
> Nicolas
>

Reply | Threaded
Open this post in threaded view
|

Re: miss-used become: ???

Nicolas Cellier
Try this

String>>becomeB
    self become: 'b'.
    ^self first

^'a' becomeB

Nicolas

2012/6/9 Chris Muller <[hidden email]>:

> Does become: swap the references in the currently executing MethodContext too?
>
>
> On Fri, Jun 8, 2012 at 4:34 PM, Nicolas Cellier
> <[hidden email]> wrote:
>> UnscriptedPlayer>>assureUniClass
>>        "Create a uniclass and become the receiver into it"
>>
>>        | anInstance |
>>        anInstance := self rootClassForUniclasses instanceOfUniqueClass.
>>        anInstance initializeCostumesFrom: self.
>>        self become: anInstance.
>>        ^ anInstance
>>
>> As I understand it, after the become: self is anInstance and anInstance is self.
>> So this would answer the original UnscriptedPlayer before the become...
>> Is this really the intention?
>> Otherwise, becomeForward: would work better.
>>
>> Nicolas
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: miss-used become: ???

Chris Muller-3
So the whole method would seem to be useless then..

On Sat, Jun 9, 2012 at 10:17 AM, Nicolas Cellier
<[hidden email]> wrote:

> Try this
>
> String>>becomeB
>    self become: 'b'.
>    ^self first
>
> ^'a' becomeB
>
> Nicolas
>
> 2012/6/9 Chris Muller <[hidden email]>:
>> Does become: swap the references in the currently executing MethodContext too?
>>
>>
>> On Fri, Jun 8, 2012 at 4:34 PM, Nicolas Cellier
>> <[hidden email]> wrote:
>>> UnscriptedPlayer>>assureUniClass
>>>        "Create a uniclass and become the receiver into it"
>>>
>>>        | anInstance |
>>>        anInstance := self rootClassForUniclasses instanceOfUniqueClass.
>>>        anInstance initializeCostumesFrom: self.
>>>        self become: anInstance.
>>>        ^ anInstance
>>>
>>> As I understand it, after the become: self is anInstance and anInstance is self.
>>> So this would answer the original UnscriptedPlayer before the become...
>>> Is this really the intention?
>>> Otherwise, becomeForward: would work better.
>>>
>>> Nicolas
>>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: miss-used become: ???

Andreas.Raab
Chris Muller-3 wrote
So the whole method would seem to be useless then..
To the contrary. First of all, the obvious use here is along the lines of:

  foo := Unscripted Player new.
  foo assureUniClass.

This makes good sense as it converts foo from an UnscriptedPlayer
into a PlayerXYZ (usually attached to some morph). Returning the
'original' foo is a good idea too if one considers that assureUniclass
is an inplace modification and if the client of that code would need
a reference to the original the *only* way to obtain it is via returning
it from the method. I don't know if the original reference is ever used,
but it makes sense to give the client some way to keep a reference
to the original in case that is needed for some other purpose (undo
perhaps?).

Cheers,
  - Andreas
Reply | Threaded
Open this post in threaded view
|

Re: miss-used become: ???

Bert Freudenberg
In reply to this post by Chris Muller-3
On 2012-06-09, at 17:33, Chris Muller wrote:

> So the whole method would seem to be useless then..

No. It changes the player from an unscripted one into one that can have scripts.

The return value of assureUniClass is not used in the system, so it doesn't really matter.

However, I agree with Nicolas that becomeForward: would be more appropriate. In particular since the code reads like returning the new instance was the intention.

- Bert -



> On Sat, Jun 9, 2012 at 10:17 AM, Nicolas Cellier
> <[hidden email]> wrote:
>> Try this
>>
>> String>>becomeB
>>    self become: 'b'.
>>    ^self first
>>
>> ^'a' becomeB
>>
>> Nicolas
>>
>> 2012/6/9 Chris Muller <[hidden email]>:
>>> Does become: swap the references in the currently executing MethodContext too?
>>>
>>>
>>> On Fri, Jun 8, 2012 at 4:34 PM, Nicolas Cellier
>>> <[hidden email]> wrote:
>>>> UnscriptedPlayer>>assureUniClass
>>>>        "Create a uniclass and become the receiver into it"
>>>>
>>>>        | anInstance |
>>>>        anInstance := self rootClassForUniclasses instanceOfUniqueClass.
>>>>        anInstance initializeCostumesFrom: self.
>>>>        self become: anInstance.
>>>>        ^ anInstance
>>>>
>>>> As I understand it, after the become: self is anInstance and anInstance is self.
>>>> So this would answer the original UnscriptedPlayer before the become...
>>>> Is this really the intention?
>>>> Otherwise, becomeForward: would work better.
>>>>
>>>> Nicolas
>>>>
>>>
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: miss-used become: ???

Bert Freudenberg

On 2012-06-09, at 17:53, Bert Freudenberg wrote:

> However, I agree with Nicolas that becomeForward: would be more appropriate. In particular since the code reads like returning the new instance was the intention.


OTOH, Andreas has a point too ;)

- Bert -