3 ms·
> If you forbid illegal states you end up with fake objects taking the place of non-existent real ones. You don't use a fake object, you use a real one of a di
by lmm 4y ago
> If you forbid illegal states you end up with fake objects taking the place of non-existent real ones.
You don't use a fake object, you use a real one of a different type. In the cases where what you want is "maybe this thing, maybe nothing" you can use an option/maybe type. In the cases where you want something else (e.g. "either this thing or an error message") you can use a type that represents that.
> Yeah, well implemented nullable and not-nullable types are good but the compilers didn't have that kind of smarts in the old days.
ML had well typed optionals back in the '70s. There's no excuse for using a language that needs null today.
- GoblinSlayer 4y agoIn C++ std::optional<T>::value throws an std::bad_optional_access exception when the value is missing. How is this different from a NullPointerException?
- lmm 4y ago> How is this different from a NullPointerException? It's different because most things can't throw it. The problem isn't that your language has a way to implement a value that might be absent, the problem is that your language does't have a way to implement a (heap) value that won't be absent, except by convention.
- GoblinSlayer 4y agoIf the value won't be absent, then it won't throw.
- lmm 4y agoI'd like to know that the value won't be absent when I build the code rather than when I execute it.