3 ms·
Fascinating read. I have often found myself using an enum in Java to present truth output as true, false and null where null means unknown. Not ideal but keeps
by gauravphoenix 7y ago
Fascinating read. I have often found myself using an enum in Java to present truth output as true, false and null where null means unknown. Not ideal but keeps things simple.
- timClicks 7y agoHow is that not ideal? Isn't that a perfectly valid mechanism to implement a 3-valued logic? Perhaps some people would prefer to wrap a standard bool. In Rust, a type of Option(bool) would work. An equivalent in Go would be *bool. But I don't know how the CPU would distinguish between a null pointer and falsehood in that case.
- gauravphoenix 7y agoI said not ideal because of null. I wish there was a better way. Null is way too overloaded in Java.
- AnimalMuppet 7y agoThen don't use null. Use { false, true, 2 } or { false, true, SomeNewEnumerationLabel }.
- gauravphoenix 7y agoyeah, I just wish there was a first class citizen support to represent this. I think Optional<Boolean> should suffice.