4 ms·
There isn't really a meaningful distinction in a dynamically typed language. Null is a value that indicates the absence of something else that could be there i
by adrusi 10y ago
There isn't really a meaningful distinction in a dynamically typed language.
Null is a value that indicates the absence of something else that could be there instead, Unit is essentially the lack of any value. So when a python function implicitly returns None whenever it's called, that's semantically more similar to Unit than Null.
- kazagistar 10y agoThe difference is methods. A Result or Option has methods like map that let you transform it regardless of which case it is in, while a null will always crash unless you match on it first.
- adrusi 10y agoIn that case, do you condsider Go's nil to not be a null, since you can call methods on it that can do whatever? Or how about objective C's nil, where any messages sent to it are simply ignored? Edit: I see now that you're talking about the difference between null and Result/Option, not the difference between null/Option and Unit, so we're talking about different things. Semantically, a value that could be data or null is equivalent to an option type. Option types have methods, yes, but that's just a superficial convenience facility, you could implement the same thing for nullable types by writing a function: public static <A, B> B map(A object, Function<A, B> f) { if (object == null) return null; return f.apply(object); }