3 ms·
null in languages (or None in Python) is one of the few criticisms I hear from pure-functional minded evangelists that I have come around to. Projects started b
by reggieband 8y ago
null in languages (or None in Python) is one of the few criticisms I hear from pure-functional minded evangelists that I have come around to. Projects started by novices tend to start with no null checks at all with lines like:
some.object.other.method();
Then at some point after months/years of null pointer exceptions you get a code base littered with:
if (some && some.object && some.object.other && some.object.other.method) {
some.object.other.method();
}
Or variants like assertions / try-catch blocks / etc.
This is even more cumbersome/ugly when needing to assign the result to a constant:
const foo = some && some.method && some.method();
I would very much like to do away with null. There is some half-formed idea in my mind that this problem is related to how we allocate memory and the concept of the heap. I don't think syntax can solve this issue.
My main issue with syntax like:
const foo = some?.object?.other?.method();
Is that it encourages sloppy error handling by making the conditional branches in the code implicit. I don't condone the (a && a.b && a.b.c) pattern so I don't really want a shorthand for it.