3 ms·
Even optionals with bad 'is null / get' assessors are better than nulls, because they come with nullsafe operators like map / flatMap and the 'get' call usually
by blacksmithgu 4y ago
Even optionals with bad 'is null / get' assessors are better than nulls, because they come with nullsafe operators like map / flatMap and the 'get' call usually always errors or panics on failure.
- deltaonefour 4y agoIt's the same thing right? flatMap or Map must call the has_value method to work without crashing.
- masklinn 4y agoIt's not because (I assume) even the shitty optional gives you a signal that the value is nullable and that you have to check. The important part is moving `null` out of every type in the language, and into its own little box that the compiler can tell you about. It's nice if you can make it a "library" utility without holes, but it's also fine if it's not perfect, or even if you have to make it a builtin magic thing, like C# &co. > flatMap or Map must call the has_value method to work without crashing. The implementation details don't really matter to the caller, what matters is that they're always operating in a safe environment without being bothered.
- deltaonefour 4y ago>The implementation details don't really matter to the caller, what matters is that they're always operating in a safe environment without being bothered. It matters because it's not true safety. flatMap is a higher level operation, I can make >=> or >>= work for values with null but that's not true safety. True safety as you said, is no null. But an optional that still generates a runtime error is basically isomorphic to a null. The point of getting rid of null is not null itself, but the associated runtime error that comes with it.