Message Eating Null (2000)
wiki.squeak.org
wiki.squeak.org
So the author's example:
lastNumber := person office phone lastNumberDialed asString.
Could maybe look something like lastNumber := person? office? phone? lastNumberDialed? asString.
Now you have neither "message eating" nor "exception throwing" nil. And the programmer is in control of what happens if other behavior is desired.Is that a modifier on existing messages (requires altering the entire language, and I don't see how it's going to work with keyword messages), or is that a binary message returning a "message-eating" proxy object?
Subsidiary question for (2), how do you handle Pharo apparently already having a `?` operator?
That aside, I think an interesting path would be to leverage conditions, assuming `#doesNotUnderstand:` can get a restart for that. Though obviously it has stack depth implication, and I've not played with conditions enough to remember whether you can get that information from a handler.
That's something that can work also in Smalltalk: Add a class `MessageEatingNil` that returns `nil` to everything except `isNil` and maybe `ifFalse`. Add a method `?` to the root class that returns self. Override that method in the Nil class to return a MessageEatingNil object.
lastNumber := person ? office ? phone ? lastNumberDialed ? asString.I totally get it, when you've only ever seen DB responses via the command prompt which promotes null/nil fields to words, without any symbols to show its a textual reference, not the literal DB state.
And yes, we wound up with DB rows having the word 'null' written back into previously nil/null values.
I came across this while looking for a Smalltalk connection to Objective-C's behavior with nil, which is being discussed here: https://news.ycombinator.com/item?id=31202292
func (t MyType*) process(a int, b int) { ... }
...
var example *MyType
example.process(1,2)
Will call the process method, even though the receiver is nil!I'm not sure my brain is quite wired to cope with it yet though.