[squeak-dev] Repeating pattern in system code: "process ifNotNil: [process terminate]"

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Fri Dec 17 19:44:52 UTC 2021

Hi Jaromir,

you're basically describing the Null Object pattern [1]. You can find some other implementations of this pattern by browsing for classes whose name starts with "Null" (I think that NullCanvas and NullMutex serve as the best examples). The problem with your proposed refactoring would be that UndefinedObject is not a domain-specific null object but rather a general-purpose class for a language concern, and that overloading it with definitions from multiple domains would a) make it very chaotic and b) earlier or later lead to naming clashes between multiple domains. Imagine a different domain came up with some kind of Resource class that understands #terminate to and wanted to apply the same pattern. Depending on the intended behavior for both "null implementations" (such as: do nothing, show an error, forward the request to a singleton), you suddenly have a problem!

IMHO our current protocol on UndefinedObject is already too overcrowded and we should eliminate the "bottom context" protocol (#handleSignal: and #canHandleSignal:) in the long term by using #ifNil:ifNotNil: in their senders instead. Same for the "class hierarchy" protocol which should be obsolete since we have ProtoObject as a null object for "almost empty classes" (but I did not check this).

To summarize, I think that every domain which is in the need of a null object should either come with its own implementation or at least only add unique selectors to UndefinedObject (which would be the case for #handleSignal: & Co.). However, #terminate is not even an exclusive part of the domain-specific vocabulary for processes. However, this is only my own impression and I'm looking forward to corrections. Thank you for the interesting question!



PS: Also check out Object >> #handles: which looks even worse and maybe really should be pushed down to UndefinedObject. :-)

[1] https://refactoring.guru/introduce-null-object

Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von mail at jaromir.net <mail at jaromir.net>
Gesendet: Freitag, 17. Dezember 2021 20:14:06
An: squeak-dev at lists.squeakfoundation.org
Betreff: [squeak-dev] Repeating pattern in system code: "process ifNotNil: [process terminate]"

Hi all,

I have noticed this recurring theme in many system methods:

        process ifNotNil: [process terminate]

Correct me if I'm wrong but it looks to me as an ugly non-OO pattern which could be elegantly replaced with a simple:

        process terminate

if we implemented:

UndefinedObject >> #terminate
        "return nil"

Is this right or am I missing something?

^[^    Jaromir

Sent from Squeak Inbox Talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211217/8baae044/attachment.html>

More information about the Squeak-dev mailing list