[squeak-dev] MNU for ifNil: to preserve quick returns? :-)

tim Rowledge tim at rowledge.org
Tue Jul 21 17:08:44 UTC 2020



> On 2020-07-21, at 1:36 AM, Marcel Taeumel <marcel.taeumel at hpi.de> wrote:
> 
> I can choose to initialize an instVar eagerly in #initialize or lazily in its accessor via #ifNil:. Yet, the latter requires me to change that accessor to something not being a quick return.

I've always been a bit ambivalent about the lazy initialisation stuff; not that it doesn't have uses. The problematic bit in my experience is tied to the lack of properly private messages and the disappointing propensity of people to treat Smalltalk as C code.

To explain: one decides to have lazy init for an instvar and so creates a methods named as the instvar that does the nil check and init dance. Great - now you can write
`self foobleDong`
and guarantee to get a useful answer. The problem now is that you have made your class into little more than a C struct. Any old Thomas, Richard or Harold can send #foobleDong and get at the internal state of your object. I don't like that.
*If* we had private methods one could mark foobleDong as private and thereby safely use it internally. 

I see far too much 'Cmalltalk' where messages are being sent as if they were C struct accessor operators. I really hate seeing
`myThing foo fum bar baz bing: myThing foo fum bar baz bing + 1`



tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
"Bother!" said Pooh, as he stood up to his waist in a cow pat.




More information about the Squeak-dev mailing list