Message Eating Null - article

Igor Stasenko siguctua at gmail.com
Wed Jul 25 17:31:03 UTC 2007


One thing, what i like about null pattern is having an info, where
first was null object created, so this potentialy helps track down
errors.

And this is not so easy with nils, because exceptions can be throwed
in places which far far away from code which was originally returned
nil.

assume some message returns nil or object.

a := b someMessage.

later 'a' used to put somewhere in dictionary:

dict at: #someKey put: a.

and only after some more assignments, some code needs to send a
message which was first returned by 'b someMessage'.
So, finding the original source of object makes big difference between
using nil, or null.

And i think nil and null can coexist fine in smalltalk.
For those who wants try: To make null working , we simply need to
slightly modify interpreter and bytecode, in such way, that everytime
parser sees a #null symbol in method code, it generates a special
bytecode, which tells the interpreter to create a new instance of Null
class and fill its ivars with current receiver and method name.
So. every time i write something like:

myMethod
^ null.

this will be equivalent to:

myMethod
^ Null receiver: self method: thisContext method.



More information about the Squeak-dev mailing list