Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-08-02 Thread tbrunz
Maybe more to the point: You do not want to *code a dependency on* what the implementing class may do as far as the returned result. :^) "Brittle code" will eventually break. Murphy's Law says that it will break at the worst possible time for you to have to deal with it. :^D -- Sent from: ht

Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-08-02 Thread Stéphane Ducasse
ted basically > Dog class>>newWhite > "Returns a new white instance of receiver." > ^self new >color: Color white; >yourself is equivalent to > Dog class>>newWhite >"Returns a new white instance of receiver.” > | instance | instance := self new. i

Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-08-02 Thread Stéphane Ducasse
+1 > On 2 Aug 2020, at 19:37, Richard Sargent wrote: > > > > On August 2, 2020 10:16:54 AM PDT, tbrunz wrote: >> Thanks, Richard. >> >> So adding #yourself is mostly needed for cases where you send #add: to >> an >> OrderedCollection (because that returns the added element instead of >>

Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-08-02 Thread tbrunz
Got it. Seems like an important point for those who are trying to understand the difference between instances and classes. I've gotten strange results myself until I learned that #yourself is an essential thing... -t -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-08-02 Thread Richard Sargent
On August 2, 2020 10:16:54 AM PDT, tbrunz wrote: >Thanks, Richard. > >So adding #yourself is mostly needed for cases where you send #add: to >an >OrderedCollection (because that returns the added element instead of >returning the collection as most expect it would)? No. It is used when you

Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-08-02 Thread tbrunz
Thanks, Richard. So adding #yourself is mostly needed for cases where you send #add: to an OrderedCollection (because that returns the added element instead of returning the collection as most expect it would)? I've been adding it in all cases, which I guess does no harm. -t -- Sent from: h

Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-08-02 Thread Richard Sargent
On August 2, 2020 9:25:32 AM PDT, tbrunz wrote: >Shouldn't this code > >> So if you implement a #newWhite method in the "class side" of Dog, it >> would be something like this. >> >> Dog class>>newWhite >> "Returns a new white instance of receiver." >> ^self new color: Color white > >be t

Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-08-02 Thread tbrunz
Shouldn't this code > So if you implement a #newWhite method in the "class side" of Dog, it > would be something like this. > > Dog class>>newWhite > "Returns a new white instance of receiver." > ^self new color: Color white be this instead? > Dog class>>newWhite > "Returns a new white i

Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-08-02 Thread Stéphane Ducasse
Hello patrick Welcome > > Subject: Class side vs instance side (variables and methods) > Date: 29 July 2020 at 01:34:22 CEST > To: Any Question About Pharo Is Welcome > > > Being new not only to Smalltalk, but OOP in general, I think I finally am > understanding things. Did you read my lear

Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-07-28 Thread Esteban Maringolo
Hi, The "class vs instance" side is one of the most confusing things for newcomers, I remember struggling with it when I learnt Smalltalk (and also was a novice in OOP). It helps you thinking it this way: the instance side is everything that will affect all instances of such class, and you can th

Re: [Pharo-users] Class side vs instance side (variables and methods)

2020-07-28 Thread Richard Sargent
On Tue, Jul 28, 2020 at 4:35 PM G B via Pharo-users < pharo-users@lists.pharo.org> wrote: > Being new not only to Smalltalk, but OOP in general, I think I finally am > understanding things. One area I am still unsure about is the class side > versus the instance side. Does one usually use the clas

[Pharo-users] Class side vs instance side (variables and methods)

2020-07-28 Thread G B via Pharo-users
--- Begin Message --- Being new not only to Smalltalk, but OOP in general, I think I finally am understanding things. One area I am still unsure about is the class side versus the instance side. Does one usually use the class side when they want those inherited in every subclass, which frees one

Re: [Pharo-users] Class side vs instance side

2015-07-24 Thread stepharo
What I like with having class is that you can attach behavior aTop opposite -> aBottom Le 23/7/15 02:40, Peter Uhnak a écrit : Hi, I am trying to figure out where to best place some mapping/data/stable methods. For example imagine method ~ MyRectangle>>oppositeSides

Re: [Pharo-users] Class side vs instance side

2015-07-23 Thread Nicolai Hess
2015-07-23 14:33 GMT+02:00 Peter Uhnák : > Cache of the mapping is just an implementation detail. > > I was referring to the instance of the ==MyRectangle== object; > so I am more interested in this from outside perspective --- other objects > that will have to use the API... > > So whether I woul

Re: [Pharo-users] Class side vs instance side

2015-07-23 Thread Peter Uhnák
Cache of the mapping is just an implementation detail. I was referring to the instance of the ==MyRectangle== object; so I am more interested in this from outside perspective --- other objects that will have to use the API... So whether I would call [[[ "class-side methods" MyRectangle oppositeSi

Re: [Pharo-users] Class side vs instance side

2015-07-23 Thread Ben Coman
Even if you put the method on the class-side, you would still be creating an new instance each time. Maybe you can store it in a class variable... MyRectangle>>oppositeSides ^ oppositeSides ifNil: [ oppositeSidesCache := { #top -> #bottom. #bottom -> #top. #topLeft -> #bottomR

[Pharo-users] Class side vs instance side

2015-07-22 Thread Peter Uhnak
Hi, I am trying to figure out where to best place some mapping/data/stable methods. For example imagine method ~ MyRectangle>>oppositeSides ^ { #top -> #bottom. #bottom -> #top. #topLeft -> #bottomRight } asDictionary And then the class might hav