Rendered at 17:52:47 GMT+0000 (Coordinated Universal Time) with Cloudflare Workers.
ralferoo 16 minutes ago [-]
True | False | FileNotFound was a meme about 2 decades ago, and even that was a reference to MSDOS from another 2 decades earlier. I guess things never change, only the language.
Even now, I still find myself using true/false/null on occasions, but I'm usually smart enough to replace it with an enum at that point. The only time I don't is when it's an optional parameter to a function to override some default/existing value, at which point it then makes sense to keep it as an optional bool.
gizmo686 10 minutes ago [-]
I'm surprised that trinary logic has not become a standard part of standard libraries yet. Almost every project I have worked on ends up with some form of a yes/no/maybe abstraction.
hinkley 8 minutes ago [-]
With privacy coming back into vogue, it’s useful to distinguish “we didn’t ask” from “they wouldn’t answer”
For some vector logic the distinction could matter.
hinkley 9 minutes ago [-]
I did a govt contract early on and learned that yes/no/unanswered/unasked was a common quad. I see that in disclosures when applying for jobs as well.
pavon 1 hours ago [-]
Neat. Even knowing about niche optimization I would have guessed that you could fit 7 Options - one bit for each. But the developers were smart enough to take advantage of the fact that you can't have a Some nested below a None, so you only need to represent how many Somes there are before you reach None (or the data), allowing 254 possibilities.
shagie 24 minutes ago [-]
For Java developers... you can use Optional<Boolean> to store the elusive four possible booleans.
nine_k 1 hours ago [-]
The scoop: a boolean can't be smaller than a byte. Full 254 level of nested Option<bool> fit into it. (C++ needs much more for even a single level.)
RobotToaster 33 minutes ago [-]
>and that it takes up one byte of memory
You can make them smaller using bitfields in C.
AlotOfReading 15 minutes ago [-]
The object it's inside will still take up at least one byte.
sizeof(struct {bool a:1;}) == sizeof(char);
hinkley 6 minutes ago [-]
Amortization.
If one Boolean must be a byte then 8 must be eight bytes. Which is not true. A boolean can be 1/8th of a byte which is a meaningful distinction.
russdill 20 minutes ago [-]
Um, no. Please show me how you can fit 255 possible states in something smaller than a byte by using bitfields.
RobotToaster 14 minutes ago [-]
I was quoting the first paragraph, where it says a single normal bool takes a byte.
priowise 1 hours ago [-]
This question always reminds me that we often compress far more nuance into binary decisions than reality allows.
In practice most systems end up inventing “soft booleans” (flags, states, priorities) to deal with that.
mock-possum 1 hours ago [-]
> looking at Rust … it turns out that `Option<bool>` takes up exactly one byte of memory, the same as bool! The same is true for `Option<Option<bool>>`, all the way up to 254 nested options.
Ah how many of those options fit into that boolean. Word games!
Even now, I still find myself using true/false/null on occasions, but I'm usually smart enough to replace it with an enum at that point. The only time I don't is when it's an optional parameter to a function to override some default/existing value, at which point it then makes sense to keep it as an optional bool.
For some vector logic the distinction could matter.
You can make them smaller using bitfields in C.
If one Boolean must be a byte then 8 must be eight bytes. Which is not true. A boolean can be 1/8th of a byte which is a meaningful distinction.
Ah how many of those options fit into that boolean. Word games!