[vwnc] VW object Identity

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

[vwnc] VW object Identity

Mark Pirogovsky-3
I have a question about object identity.

Is there any way to the application to see object unique internal ID ?

Here is the problem I came across recently:

I do have Hierarchy of Classes such a
...
ColorPresenter
        ColorPresenterLight
        ColorPresenterDark

Two leaf classes are identical in terms of the class structure, however
they do differ in some aspects of how they handle user inputs and
present themselves on the UI.

They also are used as Keys for some Dictionaries.

In the past I did use the construct like follow

        someCondition ifTrue:[ aColorPresenerLight
changeClassTo:ColorPresenerDark].

to quickly change the behavior and presentation.  Now it seems that
after I switch the class, The Identity of the object is changing as well  .

Does anybody have any information on what is happening with the objects
Identity when  changeClassTo: being used.



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] VW object Identity

Dennis smith-4
changeClassTo:  (and changeClassToThatOf:) should not change the identity.

You should be able to use "identityHash" to identity an object, at least
in 32-bit
VW.  I don't know that this is guaranteed across releases or anything
like that,
but its what is used in IdentityXxx's collections.  I use it during
debugging
(I added it to the inspector display for all classes) so I can easily
see if I am looking
at the same object from place to place.


Mark Pirogovsky wrote:

> I have a question about object identity.
>
> Is there any way to the application to see object unique internal ID ?
>
> Here is the problem I came across recently:
>
> I do have Hierarchy of Classes such a
> ...
> ColorPresenter
> ColorPresenterLight
> ColorPresenterDark
>
> Two leaf classes are identical in terms of the class structure, however
> they do differ in some aspects of how they handle user inputs and
> present themselves on the UI.
>
> They also are used as Keys for some Dictionaries.
>
> In the past I did use the construct like follow
>
> someCondition ifTrue:[ aColorPresenerLight
> changeClassTo:ColorPresenerDark].
>
> to quickly change the behavior and presentation.  Now it seems that
> after I switch the class, The Identity of the object is changing as well  .
>
> Does anybody have any information on what is happening with the objects
> Identity when  changeClassTo: being used.
>
>
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>  

--
Dennis Smith                         +1 416.798.7948
Cherniak Software Development Corporation   Fax: +1 416.798.0948
509-2001 Sheppard Avenue East        [hidden email]
Toronto, ON M2J 4Z8              sip:[hidden email]
Canada         http://www.CherniakSoftware.com
Entrance off Yorkland Blvd south of Sheppard Ave east of the DVP

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] VW object Identity

Eliot Miranda-2
In reply to this post by Mark Pirogovsky-3
Mark,

    as Dennis points out the identityHash shouldn't change.  You should confirm this.  e.g.

    | myObject oldObject oldHash |
    myObject := oldObject := ColorPresenterLight new.
    oldHash := myObject identityHash.
    myObject changeClassTo: ColorPresenterDark.
    self assert: oldObject == newObject.
    self assert: myObject identityHash = oldHash

If the identityHash isn't changing, are you perhaps causing the hash to change by virtue of different definitions in the two classes and the object being in some non-identity Set or Dictionary?

On Wed, Feb 25, 2009 at 9:17 AM, Mark Pirogovsky <[hidden email]> wrote:
I have a question about object identity.

Is there any way to the application to see object unique internal ID ?

Here is the problem I came across recently:

I do have Hierarchy of Classes such a
...
ColorPresenter
       ColorPresenterLight
       ColorPresenterDark

Two leaf classes are identical in terms of the class structure, however
they do differ in some aspects of how they handle user inputs and
present themselves on the UI.

They also are used as Keys for some Dictionaries.

In the past I did use the construct like follow

       someCondition ifTrue:[ aColorPresenerLight
changeClassTo:ColorPresenerDark].

to quickly change the behavior and presentation.  Now it seems that
after I switch the class, The Identity of the object is changing as well  .

Does anybody have any information on what is happening with the objects
Identity when  changeClassTo: being used.



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] VW object Identity and identityHash

Mark Pirogovsky-3
In reply to this post by Dennis smith-4
I just run simple experiment with the identityHash
in my image


Metaclass allInstances  asSet size -- 6998
(Metaclass allInstances  asSet collect:[:ea |ea identityHash])size --5919

There are plenty of classes in the Image which are different classes,
but their identityHash is the same.

So it appears that identityHash is not very reliable identity for an object.

All of the IdentityXX collections do use #== along with the
#identityHash   to uniquely identify objects.

Here is the method comment

"Answer a SmallInteger that is equal to the identityHash of
        any object that is == to the receiver.
        When two objects are not ==, their identityHash values may or may not
        be the same. The identityHash value does not change across the life
        of the object."



Dennis Smith wrote:

> changeClassTo:  (and changeClassToThatOf:) should not change the identity.
>
> You should be able to use "identityHash" to identity an object, at least
> in 32-bit
> VW.  I don't know that this is guaranteed across releases or anything
> like that,
> but its what is used in IdentityXxx's collections.  I use it during
> debugging
> (I added it to the inspector display for all classes) so I can easily
> see if I am looking
> at the same object from place to place.
>
>
> Mark Pirogovsky wrote:
>> I have a question about object identity.
>>
>> Is there any way to the application to see object unique internal ID ?
>>
>> Here is the problem I came across recently:
>>
>> I do have Hierarchy of Classes such a
>> ...
>> ColorPresenter  
>>     ColorPresenterLight
>>     ColorPresenterDark
>>
>> Two leaf classes are identical in terms of the class structure,
>> however they do differ in some aspects of how they handle user inputs
>> and present themselves on the UI.
>>
>> They also are used as Keys for some Dictionaries.
>>
>> In the past I did use the construct like follow
>>
>>     someCondition ifTrue:[ aColorPresenerLight
>> changeClassTo:ColorPresenerDark].
>>
>> to quickly change the behavior and presentation.  Now it seems that
>> after I switch the class, The Identity of the object is changing as
>> well  .
>>
>> Does anybody have any information on what is happening with the
>> objects Identity when  changeClassTo: being used.
>>
>>
>>
>> _______________________________________________
>> vwnc mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>  
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] VW object Identity and identityHash

Andres Valloud-6
On the other hand, the odds that two objects picked at random will have
the same identityHash is 1/16383 in a 32 bit image.  What Dennis is
doing is (I think) using identityHash in an inspector or equivalent to
quickly determine if the two objects are being inspected are the same or
not.  In this case, the identityHash method would be reasonably accurate
--- although one still has to rule out false positives.

Andres.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On
Behalf Of Mark Pirogovsky
Sent: Wednesday, February 25, 2009 11:49 AM
To: Dennis Smith
Cc: VW NC
Subject: Re: [vwnc] VW object Identity and identityHash

I just run simple experiment with the identityHash in my image


Metaclass allInstances  asSet size -- 6998 (Metaclass allInstances
asSet collect:[:ea |ea identityHash])size --5919

There are plenty of classes in the Image which are different classes,
but their identityHash is the same.

So it appears that identityHash is not very reliable identity for an
object.

All of the IdentityXX collections do use #== along with the
#identityHash   to uniquely identify objects.

Here is the method comment

"Answer a SmallInteger that is equal to the identityHash of
        any object that is == to the receiver.
        When two objects are not ==, their identityHash values may or
may not
        be the same. The identityHash value does not change across the
life
        of the object."



Dennis Smith wrote:
> changeClassTo:  (and changeClassToThatOf:) should not change the
identity.

>
> You should be able to use "identityHash" to identity an object, at
> least in 32-bit VW.  I don't know that this is guaranteed across
> releases or anything like that, but its what is used in IdentityXxx's
> collections.  I use it during debugging (I added it to the inspector
> display for all classes) so I can easily see if I am looking at the
> same object from place to place.
>
>
> Mark Pirogovsky wrote:
>> I have a question about object identity.
>>
>> Is there any way to the application to see object unique internal ID
?

>>
>> Here is the problem I came across recently:
>>
>> I do have Hierarchy of Classes such a ...
>> ColorPresenter  
>>     ColorPresenterLight
>>     ColorPresenterDark
>>
>> Two leaf classes are identical in terms of the class structure,
>> however they do differ in some aspects of how they handle user inputs

>> and present themselves on the UI.
>>
>> They also are used as Keys for some Dictionaries.
>>
>> In the past I did use the construct like follow
>>
>>     someCondition ifTrue:[ aColorPresenerLight
>> changeClassTo:ColorPresenerDark].
>>
>> to quickly change the behavior and presentation.  Now it seems that
>> after I switch the class, The Identity of the object is changing as
>> well  .
>>
>> Does anybody have any information on what is happening with the
>> objects Identity when  changeClassTo: being used.
>>
>>
>>
>> _______________________________________________
>> vwnc mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>  
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc