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

Marcel Taeumel marcel.taeumel at hpi.de
Wed Jul 22 07:40:12 UTC 2020


Hi Tim.

> *If* we had private methods one could mark foobleDong as private and thereby safely use it internally.

As long as programmers cannot make their intent clear with a "private" category or "pvt"-prefix in selectors or just by intentionally (!) using instVars without accessors, having extra annotations for lookup visibility (e.g. public/private/protected) will not make things any better as they are now. We have idioms and patterns for this already.

Sure, programmers that keep on ignoring an interface's intent would be punished if such lookup visibility would be enforced. However, I don't think that's a good way to move forward with Squeak/Smalltalk. ;-) It would lock up the system in a way that might impair liveness and exploration.

Instead, tools can help programmers discover and correct their mistakes. Code critiques, linting tools, code browsers w/ embedded run-time information, ...

Best,
Marcel
Am 21.07.2020 19:08:55 schrieb tim Rowledge <tim at rowledge.org>:


> On 2020-07-21, at 1:36 AM, Marcel Taeumel 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.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200722/01c12e0d/attachment.html>


More information about the Squeak-dev mailing list