[squeak-dev] MNU for ifNil: to preserve quick returns? :-)
karlramberg at gmail.com
Tue Jul 21 18:36:47 UTC 2020
You can discourage non private use if you write them like this:
foo ifNil:[foo := OrderedCollection new].
On Tue, Jul 21, 2020 at 7:08 PM tim Rowledge <tim at rowledge.org> wrote:
> > 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 Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> "Bother!" said Pooh, as he stood up to his waist in a cow pat.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev