"Richard A. O'Keefe" ok@atlas.otago.ac.nz wrote:
raymondasselin@sympatico.ca wrote:
pt _ Point new. pt _ 25@125.
-There is lots of examples in Smalltalk which suggest something like Morph new, or Foo new, so for me this was not linked to the use of declaring the type of a variable. -I know that when you try to define new for a Class you defined, Squeak answer a caution 'new is used in the existing class system......' I usually ignore it and go forward.
Your remark is intriguing to me...did this means that it's not a good way to go to define a 'new' as a 'builder' Class method in Squeak ? I'm a little bit 'confus' because before your note I was pretty sure that pt_ Point new. was the way to go !!!
John's point was that in "1" pt _ Point new. "2" pt _ 25@125. the first step is superfluous. In optimising compiler terms, the value it constructs is "dead", it can never be used. The code that creates a new Point has no side effects, so it doesn't accomplish anything useful to create a new point and then throw it away. The second step does not modify the Point created in line "1", it constructs a whole new Point & just rebinds the variable pt.
#new is indeed the usual selector for creating new objects. It's not the only one. In this case,
"3" pt _ Point x: 25 y: 125.
would have had the same effect as step "2".
There is actually a problem with using Point new. We normally think of a Point as an object having some kind of number for an x coordinate and some kind of number for a y coordinate (and possibly other stuff it is belongs to a subclass of Point), but "1" pt _ Point new returns a new point such that pt x is nil and pt y is nil. Another way to come up with a suitable point would be
"4" pt _ Point new x: 25; y: 125.
or "1'" pt _ Point new. "2'" pt x: 25; y: 125.
Hi Richard thank for your reply. The point for me is now so clear that I'm feeling stupid to didn't perceive it sooner. 25@125 create a point, it is not only an assignation of values to x and y part of a point.
Raymond
squeak-dev@lists.squeakfoundation.org