-
Notifications
You must be signed in to change notification settings - Fork 9
Description
I've been using a library I wrote for nearly a decade now where I implemented protocols as one of it's central premises, because I find them so useful in how I think about writing programs.
Since null doesn't actually inherit from a class and is its own thing, it was not possible to implement protocols on null in the same way as on types, but I did it. I basically have an exception (a loophole in my protocol processing) that recognizes null as a special circumstance and then defers to a Nil type I defined. On that custom type I implement the protocols null uses.
I can tell you firsthand that nil-punning (treating null as a type) is incredibly useful if you don't want to have to continually code around null (or use the Maybe monad), especially in situations where it doesn't matter, and from my experience that's often the case.