Why do you not just do something like [ âcomplicated code that might fail somewhere in hereâ ] on: Error do: [:error | nil] Use the on:do: exception handling to stay safe. Result := [anObject long chain of messages that might return a nilValue ] on: Error do: [:e | nil].
On Mar 15, 2022, at 11:16 AM, sean@clipperadams.com wrote:
I had some chaining that was getting too complex due to many nil checks, so I started to refactor using a Null Object.
However, Iâm struggling a bit with the refactor due to inlining. Since #ifNil: variants might be inlined, it seems that something like:
anObject with a long chain of messages ifNotNil: [ :result | ââ¦â ]
must be changed into something like:
anObject with a long chain of messages isNil ifFalse: [ anObject with a long chain of messages ââ¦â ].
Obviously, I can use a temp to have:
result := anObject with a long chain of messages.
result isNil ifFalse: [ result ââ¦â ].
But both seem ugly and make me question using this pattern.
What am I missing?
After 40+ years of Mooreâs Law, can we turn off these inlines by default?