RE: [croquet] get a handle to an object

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

RE: [croquet] get a handle to an object

Rappaz
THX to stop those mailing !!

-----Message d'origine-----
De : [hidden email]
[mailto:[hidden email]] De la part de haggai
Envoyé : samedi, 27. janvier 2007 16:16
À : [hidden email]
Objet : Re:[croquet] get a handle to an object

Anyone out there could shed light on this?

I just used the DMU code tutorial example to create a "Nevigator" world:

nm:= NavigatorMaster new  openInWorld .
win:=   SystemWindow new.
lf:= LayoutFrame new.
lf leftFraction:0.
lf rightFraction:1.
lf topFraction:0.
lf bottomFraction:1.
win setLabel: 'close the 2nd halo NAVIGATOR'.
win addMorph: nm fullFrame:lf.
win openInWorldExtent: 600@450.

then after creating the "Hoster" the same way, I connected the nevigator to
the hoster and was trying Andreas suggestion:

frame := win future windowFrame.
frame future colorize: Color red.

but nothing happened. and my best guess is that I am still not addressing
the right window. So how again I would reference / get-a-handle / point-to,
the ID of the 2d portal I just created?

h




Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

Howard Stearns
[I remember it being quite a challenge to figure out how to ask a  
Croquet question, and now I find it quite a challenge to figure out  
what people are asking! Fortunately, both challenges are stimulating...]

There are several context you might have in mind. I'm going to try to  
illustrate this with some inspectors. I'm going to START by taking  
you through the WRONG way to get to stuff, but it fits the Squeak and  
Pre-Croquet view of things, so I'm guessing that it fits with the  
question you THINK you're asking.

1. Open a Croquet(Master). Do a cmd/alt-click on the Morphic window  
to get the Morphic halo. There is a small gray button on the right  
hand side of the halo, second from the top, with an icon of a wrench.  
Click it to get a Morphic menu, and choose 'explore morph' to get a  
Morphic inspector.

2. Drill down through the tree using the triangles: root->harness-
 >islandsByName->'Master'->myValue->globals->#masterSpace-
 >frameChildren->6 (the first TWindow). Click on '6: a TWindow
[5]:'aTWindow''. We're now inside that object, with 'self' bound to it.

3. In the lower pane of the explorer, type
   self colorize: Color red
and press cmd/alt-d to 'do it'.  You've just made Allen turn red!

We've just gone behind the scenes, barging our way through proxy  
objects. If we were collaborating with others in the same world, they  
would not see Allen turn red.  We did all this in a Morphic process  
outside of the Croquet island process that takes care of  
collaboration. We broke Croquet.

You want to write things so that most stuff happens as normal  
programming within the simulation. We call this being "on-island."  
We're going to do an example of that now.

1. Let's break some TWindows. Leaving everything open, bring up a  
class browser. (Click on the grey desktop to get the Morphic world  
menu and select open->class browser.)  Click the tiny little black  
square at the top of the scroll bar for the upper left pane of the  
browser. (Hey, I didn't design it.) Select 'find class...'. Type in  
'twin' and select TWindow. We're going to add to and then modify the  
Croquet class that Allen is in an instance of.

2. Click on --all-- in the second pane from the right. Move your  
mouse to the code pane at the bottom without clicking.  Type
   frob
      self colorize: Color white.
Click the tiny black square above the scroll bar for the code pane  
and select 'accept'. You've just added the #frob method.  Check this  
out by going back to the explorer and replacing the old code with
   self frob.
'Do it' again. It works!

3. Now we've made a normal method that works from off island, and now  
we're going to show that it works on-island, too.  Edit the method  
definition to say 'Color red' instead of 'Color white' and accept it  
again. Now click on --all-- at the top of that second-from-the right  
pane again, and in the rightmost pane, scroll down to pointerDown:.

4. We're going to change pointerDown: to use our #frob method.  
#pointerDown: is part of the UI for Croquet, which carefully arranges  
#pointerDown: to be executed from WITHIN the island (meaning that  
every participant executes the same method at the same "time"), not  
from within Morphic.  Highlight everything in the #pointerdown:  
method except for the method name and arguments, and replace them  
with just
   self frob.
just like we did in the explorer. Accept it.

5. Now move your mouse over the window FRAME and left-click. Allen  
turns red. When the mouse button is released back up you also get an  
error because we've broken the little dance that TWindow does with  
#pointerDown: and #pointerUp:, but that's ok. Just press the 'x' in  
the debugger window frame -- or examine the stack and see if you can  
figure out the dance!

Most of you application programming will be to just define normal  
methods like #frob. They refer to instance variables of the classes  
that methods are defined on. (Sometimes it's convenient to refer to  
self parent or self frameChildren, but this is often the path to hell  
compared with explicitly maintained instance variables. But that's a  
programming issue that isn't specific to Croquet.)  Then you use your  
methods (e.g., #frob) to event handlers (e.g., #pointerDown:).  Not a  
#future in sight.

How do you get objects into the world in the first place? Either your  
application framework has operations for users to interactively add  
stuff (e.g. as the KAT code does), or the stuff is created when the  
island is first created. See the #initialize method of the various  
subclasses of BaseWorld.  Note that such world initialization is also  
done on-island.

There is also opportunity to create stuff from off-island as though  
you were creating a new kind of event. That is, ONE participant  
executes some code from Squeak/Morphic (e.g., with the inspectors  
like we were doing), or perhaps from some user interface mechanism  
that they've built (e.g., Tweak application menus).  This is where  
you deal with proxy objects called TFarRefs, using the #future  
message like Andreas showed.  There are several threads on this, like  
https://lists.duke.edu/sympa/arc/croquet-dev/2006-12/msg00000.html,  
but the chances good that this is NOT really what you want to do.  
Here's how to relate those other discussions to the stuff we were  
doing in the explorer, above. You'll notice that some of the stuff in  
the explorer is a TFarRef.  A Kosher way to interactively get a  
TFarRef to the current space is as follows. I hope you'll use this to  
explore and begin to understand on-island vs off-island and to debug,  
but not as the principle way to be thinking about constructing  
applications!

1. Explore the Morph as we did before, and just click on root.

2. Type
         harness activeSpace explore
and 'do it'.

3. click on the TFarRef in the new explorer.  Now you can do stuff like
   self future addChild: (self island future new: TCube)

On Jan 27, 2007, at 6:36 AM, haggai wrote:

> Andreas,
>
> thank you for the answer but I am still not getting it.  I have a  
> reference to the outside window (some demo world) How do I get a  
> reference to a window inside, another words: How do I find a 2d  
> portal id. (and I may have more than one)
>
> h

On Jan 27, 2007, at 12:16 AM, Andreas Raab wrote:

> Just send a future message, e.g., assuming you have a reference to  
> the window just do:
>
>   frame := window future windowFrame.
>   frame future colorize: Color red.
>
> Cheers,
>   - Andreas
>
> haggai wrote:
>> How can I get a handle to an existing object? Say for example I  
>> would like to change a parameter on the window frame of a 2d  
>> portal such as changing the color of the frame. My guess is that  
>> it would have to happened with the method "colorize:" in the  
>> "TWindowFrame".  but How do I access the ID of the portal, which  
>> its frame I want to colorize, and what is the sequence of events  
>> that need to happened for the frame to be rendered with the new  
>> color?  Can anyone give me a little example?
>> h



Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

Howard Stearns
In reply to this post by Rappaz
You certainly can and should pass objects around.

But be wary of long referencing chains. This isn't a Croquet issue,  
but it is a (debatable) object-oriented style issue. There's nothing  
wrong with a short referencing chain. Here's an example of a longish  
chain. Suppose:

class A has an instance variable 'b', and reader method #b. E.g.:
A>>b
   "answer with the value of the 'b' instance variable."
   ^b.

class B has instance variable 'c', and reader method #c.
class C has a method #foo.

You might write code like this:
D>>someMethod: anA
   anA b c foo.

But long referencing chains are fragile. There's rule of thumb  
favored by some programmers called 'The Law of Demeter', that says  
you should only send messages to your own objects (including those  
given to you).

So we might have:
D>>someMethod: anA
    anA foo

B>>foo
    c foo

I don't get too hung up on this, as it is quite often just trading  
"noun" chains" for "verb" chains.  But in the absence of more  
information, I think Demeter is not a bad thing to keep in mind.

I do get concerned about vague referencing chains that depend on  
object history. Things like:
    foo parent parent frameChildren first frameChildren third

I also do get concerned about relying on "global" names (which is  
sort of the same thing).

On Jan 27, 2007, at 5:29 PM, haggai Goldfarb wrote:

> Howard,
>
> Thank you for the wonderful answer!  I went no problem through the  
> lesson and was able to manipulate the frame colors as you suggested.
>
> It is probably because I am coming from a "different school" that I  
> am still having troubles with it:  Am I getting this right that  
> there is no passing around of objects IDs in Squeak???  Some  
> article I glanced through in the context of 'teatime' called it an  
> 'old habbit'  and not real object oriented.   Hmmm. I think I have  
> a lot to learn here. I'm having hard time seeing how I can program  
> serious code without dynamic referencing. In both your examples we  
> had to resort to selecting the object in order to manipulate it.  
> But what if you want to manipulate more than one object at the same  
> time? What if you want to automate certain things? surely you can't  
> rely on just selecting things interactively?  there was a  
> mentioning of 'query strings' but I haven't quite figured it out.
>
> Ok, I am hoping to not stir things in  a wrong way here - the  
> momentum is too important!!!
> Buy really looking forward to your comments.
>
> (If you like to keep the thread continuity please feel free to copy  
> this email to the group until I manage to log-in)
>
> Again, thank you for your great input!
>
> h
>
>
> Haggai Goldfarb
> LiquidBits
> office: 617.401.2225
> cell: 818.648.5158
> [hidden email]
>
>
> ----- Original Message ----
> From: Howard Stearns <[hidden email]>
> To: [hidden email]; haggai <[hidden email]>
> Sent: Saturday, January 27, 2007 11:44:53 AM
> Subject: Re: [croquet] get a handle to an object
>
> [I remember it being quite a challenge to figure out how to ask a
> Croquet question, and now I find it quite a challenge to figure out
> what people are asking! Fortunately, both challenges are  
> stimulating...]
>
> There are several context you might have in mind. I'm going to try to
> illustrate this with some inspectors. I'm going to START by taking
> you through the WRONG way to get to stuff, but it fits the Squeak and
> Pre-Croquet view of things, so I'm guessing that it fits with the
> question you THINK you're asking.
>
> 1. Open a Croquet(Master). Do a cmd/alt-click on the Morphic window
> to get the Morphic halo. There is a small gray button on the right
> hand side of the halo, second from the top, with an icon of a wrench.
> Click it to get a Morphic menu, and choose 'explore morph' to get a
> Morphic inspector.
>
> 2. Drill down through the tree using the triangles: root->harness-
> >islandsByName->'Master'->myValue->globals->#masterSpace-
> >frameChildren->6 (the first TWindow). Click on '6: a TWindow
> [5]:'aTWindow''. We're now inside that object, with 'self' bound to  
> it.
>
> 3. In the lower pane of the explorer, type
>    self colorize: Color red
> and press cmd/alt-d to 'do it'.  You've just made Allen turn red!
>
> We've just gone behind the scenes, barging our way through proxy
> objects. If we were collaborating with others in the same world, they
> would not see Allen turn red.  We did all this in a Morphic process
> outside of the Croquet island process that takes care of
> collaboration. We broke Croquet.
>
> You want to write things so that most stuff happens as normal
> programming within the simulation. We call this being "on-island."
> We're going to do an example of that now.
>
> 1. Let's break some TWindows. Leaving everything open, bring up a
> class browser. (Click on the grey desktop to get the Morphic world
> menu and select open->class browser.)  Click the tiny little black
> square at the top of the scroll bar for the upper left pane of the
> browser. (Hey, I didn't design it.) Select 'find class...'. Type in
> 'twin' and select TWindow. We're going to add to and then modify the
> Croquet class that Allen is in an instance of.
>
> 2. Click on --all-- in the second pane from the right. Move your
> mouse to the code pane at the bottom without clicking.  Type
>    frob
>       self colorize: Color white.
> Click the tiny black square above the scroll bar for the code pane
> and select 'accept'. You've just added the #frob method.  Check this
> out by going back to the explorer and replacing the old code with
>    self frob.
> 'Do it' again. It works!
>
> 3. Now we've made a normal method that works from off island, and now
> we're going to show that it works on-island, too.  Edit the method
> definition to say 'Color red' instead of 'Color white' and accept it
> again. Now click on --all-- at the top of that second-from-the right
> pane again, and in the rightmost pane, scroll down to pointerDown:.
>
> 4. We're going to change pointerDown: to use our #frob method.
> #pointerDown: is part of the UI for Croquet, which carefully arranges
> #pointerDown: to be executed from WITHIN the island (meaning that
> every participant executes the same method at the same "time"), not
> from within Morphic.  Highlight everything in the #pointerdown:
> method except for the method name and arguments, and replace them
> with just
>    self frob.
> just like we did in the explorer. Accept it.
>
> 5. Now move your mouse over the window FRAME and left-click. Allen
> turns red. When the mouse button is released back up you also get an
> error because we've broken the little dance that TWindow does with
> #pointerDown: and #pointerUp:, but that's ok. Just press the 'x' in
> the debugger window frame -- or examine the stack and see if you can
> figure out the dance!
>
> Most of you application programming will be to just define normal
> methods like #frob. They refer to instance variables of the classes
> that methods are defined on. (Sometimes it's convenient to refer to
> self parent or self frameChildren, but this is often the path to hell
> compared with explicitly maintained instance variables. But that's a
> programming issue that isn't specific to Croquet.)  Then you use your
> methods (e.g., #frob) to event handlers (e.g., #pointerDown:).  Not a
> #future in sight.
>
> How do you get objects into the world in the first place? Either your
> application framework has operations for users to interactively add
> stuff (e.g. as the KAT code does), or the stuff is created when the
> island is first created. See the #initialize method of the various
> subclasses of BaseWorld.  Note that such world initialization is also
> done on-island.
>
> There is also opportunity to create stuff from off-island as though
> you were creating a new kind of event. That is, ONE participant
> executes some code from Squeak/Morphic (e.g., with the inspectors
> like we were doing), or perhaps from some user interface mechanism
> that they've built (e.g., Tweak application menus).  This is where
> you deal with proxy objects called TFarRefs, using the #future
> message like Andreas showed.  There are several threads on this, like
> https://lists.duke.edu/sympa/arc/croquet-dev/2006-12/msg00000.html,
> but the chances good that this is NOT really what you want to do.
> Here's how to relate those other discussions to the stuff we were
> doing in the explorer, above. You'll notice that some of the stuff in
> the explorer is a TFarRef.  A Kosher way to interactively get a
> TFarRef to the current space is as follows. I hope you'll use this to
> explore and begin to understand on-island vs off-island and to debug,
> but not as the principle way to be thinking about constructing
> applications!
>
> 1. Explore the Morph as we did before, and just click on root.
>
> 2. Type
>          harness activeSpace explore
> and 'do it'.
>
> 3. click on the TFarRef in the new explorer.  Now you can do stuff  
> like
>    self future addChild: (self island future new: TCube)
>
> On Jan 27, 2007, at 6:36 AM, haggai wrote:
>
> > Andreas,
> >
> > thank you for the answer but I am still not getting it.  I have a
> > reference to the outside window (some demo world) How do I get a
> > reference to a window inside, another words: How do I find a 2d
> > portal id. (and I may have more than one)
> >
> > h
>
> On Jan 27, 2007, at 12:16 AM, Andreas Raab wrote:
> > Just send a future message, e.g., assuming you have a reference to
> > the window just do:
> >
> >   frame := window future windowFrame.
> >   frame future colorize: Color red.
> >
> > Cheers,
> >   - Andreas
> >
> > haggai wrote:
> >> How can I get a handle to an existing object? Say for example I
> >> would like to change a parameter on the window frame of a 2d
> >> portal such as changing the color of the frame. My guess is that
> >> it would have to happened with the method "colorize:" in the
> >> "TWindowFrame".  but How do I access the ID of the portal, which
> >> its frame I want to colorize, and what is the sequence of events
> >> that need to happened for the frame to be rendered with the new
> >> color?  Can anyone give me a little example?
> >> h
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

haggai
Howard,

will it be possible for you to take what you just told me (bit shifting?) and
show how you would apply it onto the example of coloring the frame from before?

I hope its not too much to ask. I think it will give me a good head-start to
understand the mechanism and better insight of squeak.

so assuming we now have two windows, how can we color the one at the center
screen white and the one on the right as red, all done using direct
manipulation of the window frames IDs, (rather then using the inspector and
selecting the frames)

(sorry, I realize that you have a lot of requests coming your way)

h

Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

Bert Freudenberg
On Jan 28, 2007, at 5:53 , haggai wrote:

> so assuming we now have two windows, how can we color the one at  
> the center
> screen white and the one on the right as red, all done using direct
> manipulation of the window frames IDs, (rather then using the  
> inspector and
> selecting the frames)

Perhaps it would help us to know what you actually want to do. See

http://www.catb.org/~esr/faqs/smart-questions.html#goal

If that document is still unknown to somebody, go read it in its  
entirety, it might help you getting helped.

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

haggai
Hi bert,

I am sorry if I addressed the group in a wrong way. I agree that communicating
the questions in the right way makes all the difference.

Please allow me to try again:

my objectives is to understand, by way of an example, how to manipulate objects
(or change attributes) procedurally.

I gave an example of changing a color of a 2d portal frame which should be easy
to do and visualize and if I saw an example of how it is done, I will
understand how to do it.

The solution needs to identify one window/2d portal (by name or ID) from a
possible set of a few windows. The only constraint i have - you can't do it by
selecting the object since this won't be procedural.

(one can claim that you can write a method that procedurally selects objects -
but I wouldn't consider this as good solution in this case, as going through
selection lists is usually slow - indeed, occasionally it does have important
uses...)



h

Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

Howard Stearns
re: identifying the problem

The idea is convey what you want to accomplish, not how you want to  
do it.

In this case, it sounds like you're dismissing the idea of already  
having the correct object in a variable, but claiming that you do  
somehow have the correct object's "name". I'm having trouble  
rectifying that, but I'm probably misunderstanding something.

You also mentioned wanting to manipulate the object "in the center"  
as opposed to the one "on the right".  You can certainly do that.  
But before we go into a whole discussion of scene graphs, root,  
parent, frameChildren, matrix math, and coordinate systems, I suspect  
that such a discussion would be taking you down the wrong path.

Let's try it this way:  Are you trying to write a script to  
programmatically create an initial world full of objects (i.e., so  
that your users don't have to do it), or are you trying to have the  
system react to some event? What sort of event? (i.e., what causes  
the thing to happen? A user doing something?)

Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

haggai
For the sake of discussion let's say that what I am trying to accomplish is
writing a script to modify a world full of objects. I am assuming though that
there will be events that the system will have to react to. for example: an
animation rig.

Obviously you always have to set the name somehow before you can get it. I can
see in the explorer that every object has already some attributes and
"objectName" is one of them. I guess since no one is setting it at
initialization time it is set to nil. (I think this is what I am missing here.
We usually name everything remotely important at creation time.)  There is also
"objectID". I suspect that objectID is generated automatically by incrementing
its value each time a new object is added. It is harder to do the same thing
with names since they have to be unique and "make sense".

Now I am not saying that finding who is the object you want to deal with is
trivial but I have seen a few ways of doing it.

In this case we want to first find a specific window (say "the one on the
right")

1. using IDs

a) get a list of all windows IDs in my scene
b) traverse the list and check for a type of windows.
c) test: if the type of window matches some criteria - get its ID
d) with this ID, get an ID of the child who is the frame...
e) with this ID of the child change the color of the frame (or whatever)

2. using Names

a) set the names of all windows at their creation time. (could be some default
names based on their types)

b) same as 1. above only use names instead of IDs
   the advantage here is that it is very easy to inspect/debug - you   always
know who you are dealing with...
   
in Maya for example, once you named an object (or dag-node) , it becomes sort
of a "global" variable in the scope of the session. (and in this case its OK to
use global vars...)

so you could say:

(create 3 cubes:)
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -tx 1 -ch 1;
// Result: pCube1 polyCube1 //
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -tx 1 -ch 1;
// Result: pCube2 polyCube2 //
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -tx 1 -ch 1;
// Result: pCube3 polyCube3 //

noticed they were named automatically (pCube1, pCube2, pCube3)

(now to translate the second cube up by 5 units:)

setAttr pCube2.translateY 5;
 
There is probably a better way in Croquet-Squeak to do this which is what I
hoping to learn here.

I hope this isn't annoying everyone. Thank you for taking the time.

h

Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

Bert Freudenberg
On Jan 28, 2007, at 20:15 , haggai wrote:

> For the sake of discussion let's say that what I am trying to  
> accomplish is
> writing a script to modify a world full of objects. I am assuming  
> though that
> there will be events that the system will have to react to. for  
> example: an
> animation rig.
>
> Obviously you always have to set the name somehow before you can  
> get it.
> [...snip...]

Okay, so this is where your problem is. You have to grok the concept  
of "objects" first. There is no need whatsoever to *name* an object  
to be able to refer to it. You just refer to the object itself.

For example, when you want to let the user pick an object from a  
textual list, what is *displayed* might be some String property like  
the object's name or its ID, but what is actually *selected* is the  
object itself. And then you can just start sending messages to the  
object.

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

Howard Stearns
I think Bert is on to something here.

Haggai, it sounds like you're imagining that everything we tell the  
system is executed only for effect. But in fact, every time we send  
an object a message, the execution answers with a value.  Sometimes  
we don't care what the value is, but there always is a value.

Part of the confusion is that there are languages that have this  
bizarre distinction between "expressions" and "statements." In such  
languages, there is a subset of the language that is allowed in  
expressions. Expressions produce an answering value (also known as  
"returning a value") and may be composed together to form other  
expressions. Statements are executed only for their effect and do not  
answer a value. (Personally, I have the hardest time trying to  
understand which things are allowed as expressions and which must be  
in statements. It always seems so arbitrary to me.)  Squeak doesn't  
have this problem.(1)

Also, some languages can't represent everything as a value that can  
be passed around from one place to another. Sometimes such languages  
have concepts that are understood by the compiler, but can't be  
understood by your program. These are called "second-class" objects.  
Examples might include types, files, and tables. In such languages,  
the best you can do, if you're lucky, is to maybe refer to the "name"  
of an object (e.g., as a string) and pass that round instead.  Again,  
in Squeak, everything is a first-class object.

It's also possible that we're having a disconnect about the concept  
of variables -- including instance variables and parameters to a method.

All these things are kind of wrapped up together.  In case it seems  
like this is on the right track, I'll put in another plug for the  
Squeak tutorials listing at http://wiki.squeak.org/squeak/792

Cheers,
-H

---------
(1) For this discussion, I don't want to get into what class and  
method definitions are and what their value is.

On Jan 28, 2007, at 2:14 PM, Bert Freudenberg wrote:

> On Jan 28, 2007, at 20:15 , haggai wrote:
>
>> For the sake of discussion let's say that what I am trying to  
>> accomplish is
>> writing a script to modify a world full of objects. I am assuming  
>> though that
>> there will be events that the system will have to react to. for  
>> example: an
>> animation rig.
>>
>> Obviously you always have to set the name somehow before you can  
>> get it.
>> [...snip...]
>
> Okay, so this is where your problem is. You have to grok the  
> concept of "objects" first. There is no need whatsoever to *name*  
> an object to be able to refer to it. You just refer to the object  
> itself.
>
> For example, when you want to let the user pick an object from a  
> textual list, what is *displayed* might be some String property  
> like the object's name or its ID, but what is actually *selected*  
> is the object itself. And then you can just start sending messages  
> to the object.
>
> - Bert -
>
>


Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

haggai
In reply to this post by Bert Freudenberg
Bert,

I absolutely agree with you that "what is actually *selected* is the  
object itself". Its the same case in every language I know and it is
fundamental to object-oriented programming. Its possible though, that the
objects are defined slightly different in Squeak.
I'm going to spend some time thinking about what you guys are saying and get
back to you. More Squeak exercises won't hurt me either...
And I am not looking to hangup on this issue - just understand and move
quickly.

Thank you for your input!

h

Reply | Threaded
Open this post in threaded view
|

Re: [croquet] get a handle to an object

Bert Freudenberg
In reply to this post by Rappaz
On Jan 29, 2007, at 12:51 , kiran wrote:

>        As far as C++ goes( same with Squeak) you need to inherit  
> two squares as descendants of some base square.

No. You only need to do that in C++ to convince the compiler you know  
what you're doing. It's a poor form of static typing.

In Squeak you just implement the method you want to be able to send  
it to some object, this is totally independent of inheritence. It's  
called dynamic typing (or, nowadays, duck typing http://
en.wikipedia.org/wiki/Duck_typing)

On a related note, Squeak uses strong typing (an object is always  
what it is) and not weak typing like C++ (you can override an  
object's type by casting, and do terrible things to it).

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: [unclassified] Re: [croquet] get a handle to an object

David P. Reed
Just a terminology correction.   "Strong typing" in the literature means
that an object has a type that is enforced at "compile time".  Weak
typing implies that enforcement is not done at compile time.

Squeak doesn't enforce anything at compile time.   While not as extreme
as Self, one can indeed change the set of protocols that an object
accepts in Squeak at run time.   In particular, you can add methods to
an object by, for example, patching its class object reference
(carefully), or augmenting its class object's methods in a way that only
affects that object (check for the object id in the method you add).

It would be bad to confuse the world by saying that Squeak or Smalltalk
is "strongly typed".

Bert Freudenberg wrote:

> On Jan 29, 2007, at 12:51 , kiran wrote:
>
>>        As far as C++ goes( same with Squeak) you need to inherit two
>> squares as descendants of some base square.
>
> No. You only need to do that in C++ to convince the compiler you know
> what you're doing. It's a poor form of static typing.
>
> In Squeak you just implement the method you want to be able to send it
> to some object, this is totally independent of inheritence. It's
> called dynamic typing (or, nowadays, duck typing
> http://en.wikipedia.org/wiki/Duck_typing)
>
> On a related note, Squeak uses strong typing (an object is always what
> it is) and not weak typing like C++ (you can override an object's type
> by casting, and do terrible things to it).
>
> - Bert -
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: [unclassified] Re: [croquet] get a handle to an object

Bert Freudenberg
Well, I'd rather say there are a variety of concepts that people  
label as "strong typing", and not all restrict this to "compile  
time". For one taxonomy supporting my usage of the word, see

        http://eli.thegreenplace.net/2006/11/25/a-taxonomy-of-typing-systems/

For a list of implied meanings, see

        http://en.wikipedia.org/wiki/Strong_typing

However, you might be right that people could easily be confused, the  
more important thing is that Squeak is type-safe, i.e.,  you cannot  
forge types.

- Bert -

On Jan 29, 2007, at 16:17 , David P. Reed wrote:

> Just a terminology correction.   "Strong typing" in the literature  
> means that an object has a type that is enforced at "compile  
> time".  Weak typing implies that enforcement is not done at compile  
> time.
>
> Squeak doesn't enforce anything at compile time.   While not as  
> extreme as Self, one can indeed change the set of protocols that an  
> object accepts in Squeak at run time.   In particular, you can add  
> methods to an object by, for example, patching its class object  
> reference (carefully), or augmenting its class object's methods in  
> a way that only affects that object (check for the object id in the  
> method you add).
>
> It would be bad to confuse the world by saying that Squeak or  
> Smalltalk is "strongly typed".
>
> Bert Freudenberg wrote:
>> On Jan 29, 2007, at 12:51 , kiran wrote:
>>
>>>        As far as C++ goes( same with Squeak) you need to inherit  
>>> two squares as descendants of some base square.
>>
>> No. You only need to do that in C++ to convince the compiler you  
>> know what you're doing. It's a poor form of static typing.
>>
>> In Squeak you just implement the method you want to be able to  
>> send it to some object, this is totally independent of  
>> inheritence. It's called dynamic typing (or, nowadays, duck typing  
>> http://en.wikipedia.org/wiki/Duck_typing)
>>
>> On a related note, Squeak uses strong typing (an object is always  
>> what it is) and not weak typing like C++ (you can override an  
>> object's type by casting, and do terrible things to it).
>>
>> - Bert -





Reply | Threaded
Open this post in threaded view
|

Re: [unclassified] Re: [croquet] get a handle to an object

Jecel Assumpcao Jr
In reply to this post by David P. Reed
David P. Reed wrote:
> Just a terminology correction.   "Strong typing" in the literature means
> that an object has a type that is enforced at "compile time".  Weak
> typing implies that enforcement is not done at compile time.

In the literature I read the terms used are "static typing" when it is
done at compile time and "dynamic typing" when the run time uses tags in
the objects themselves to deal with types. The strong/weak/none
dimension is a totally separate issue.

I do see blog entries and stuff like that which use the terms as you
said, so there is a real possibility that eventually conference papers
will adopt this use as well. But it hasn't happened yet. Is this a
losing battle (like trying to hold on to the original meaning of
"hacker" back in the 1980s, for example)? I don't think so, and think
that for now it is best to try to educate people.
 
> Squeak doesn't enforce anything at compile time.   While not as extreme
> as Self, one can indeed change the set of protocols that an object
> accepts in Squeak at run time.   In particular, you can add methods to
> an object by, for example, patching its class object reference
> (carefully), or augmenting its class object's methods in a way that only
> affects that object (check for the object id in the method you add).

Right, that goes a bit beyond the usual definition of dynamic typing.
Let's call that "very dynamic" since it is still in the same dimension.

> It would be bad to confuse the world by saying that Squeak or Smalltalk
> is "strongly typed".

The world is already confused. Very much so. Agreeing with people who
have mixed up ideas won't help.

Just to reinforce my viewpoint, we can classify types along three
orthogonal axis:

- strong / weak / none
- static / dynamic
- concrete / abstract

So I claim that Squeak's types are very dynamic, strong and abstract.

-- Jecel

Reply | Threaded
Open this post in threaded view
|

Re: [unclassified] Re: [croquet] get a handle to an object

David P. Reed
I don't want to get into a fruitless debate.   But traditionally in the
programming language community, strong typing is an attribute of
*variables* or names.   It is the association of types with variables
that allows type checking at compile time to work.   It is this
attribute that programmers I know use to argue that strongly typed
languages are less prone to errors.

Now it may be that the terminology has become a mess.   The existence of
a mess doesn't suggest that terms should be rendered meaningless or
ideas confused with each other.

But there are two key ideas here.   One is about what you can tell from
the name that appears in program text.   The other is whether an
"object" satisfies any invariants in terms of its range and the set of
verbs that can be applied to it.

Squeak doesn't associate typing with names.   Any name can refer to any
object in the system, which by definition means the union of all classes
or types.

Squeak also doesn't associate typing with objects.   Any object can
exhibit any behavior over time, because Squeak allows you to change
dynamically  the particular behavior of an object that is exhibited in
response to sending it a message.

C's objects are memory contents, and its names are strongly typed.   The
casting that C allows too freely merely prevents compile time reasoning
about the objects' *representations*.  THat's not weak typing, that's
weak semantics.

Jecel Assumpcao Jr wrote:

> David P. Reed wrote:
>  
>> Just a terminology correction.   "Strong typing" in the literature means
>> that an object has a type that is enforced at "compile time".  Weak
>> typing implies that enforcement is not done at compile time.
>>    
>
> In the literature I read the terms used are "static typing" when it is
> done at compile time and "dynamic typing" when the run time uses tags in
> the objects themselves to deal with types. The strong/weak/none
> dimension is a totally separate issue.
>
> I do see blog entries and stuff like that which use the terms as you
> said, so there is a real possibility that eventually conference papers
> will adopt this use as well. But it hasn't happened yet. Is this a
> losing battle (like trying to hold on to the original meaning of
> "hacker" back in the 1980s, for example)? I don't think so, and think
> that for now it is best to try to educate people.
>  
>  
>> Squeak doesn't enforce anything at compile time.   While not as extreme
>> as Self, one can indeed change the set of protocols that an object
>> accepts in Squeak at run time.   In particular, you can add methods to
>> an object by, for example, patching its class object reference
>> (carefully), or augmenting its class object's methods in a way that only
>> affects that object (check for the object id in the method you add).
>>    
>
> Right, that goes a bit beyond the usual definition of dynamic typing.
> Let's call that "very dynamic" since it is still in the same dimension.
>
>  
>> It would be bad to confuse the world by saying that Squeak or Smalltalk
>> is "strongly typed".
>>    
>
> The world is already confused. Very much so. Agreeing with people who
> have mixed up ideas won't help.
>
> Just to reinforce my viewpoint, we can classify types along three
> orthogonal axis:
>
> - strong / weak / none
> - static / dynamic
> - concrete / abstract
>
> So I claim that Squeak's types are very dynamic, strong and abstract.
>
> -- Jecel
>
>
>