Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
One of the more painful things: many bool fields with byte sized bools (twitter.com/mitchellh)
6 points by tosh on March 17, 2024 | hide | past | favorite | 6 comments


This is what I have open in my other tab: https://ferrilab.github.io/ferrilab/bitvec.html


> lang that uses byte sized bools

Isn’t that pretty much all of them? The langages where that’s not the case are usually those using pointer-sized bools.


They tried to make this convenient with std::vector<bool> in C++, which turned out to be a bad idea in general.

It should also be pointed out that storing those booleans as bits is not the only alternative. For a trivial example one could have millions of sorted bools and just store how many are true, then storage becomes constant.


It can be done for performance reason I assume. Numpy for instance does that:

https://numpy.org/doc/stable/user/basics.types.html


yes, exactly. Access/modification of a directly addressable byte is much faster than some bit of it. If I'm not mistaken, on Win32 `BOOL` data type is defined even worse to a 32bit int (this C API was devised way before `bool` has made it's way into C), so 8bits isn't even the worst case scenario :D


Can’t believe it’s 9 years old at this point, but I made this for a project a while ago to solve this problem in JS.

https://www.npmjs.com/package/bitflags




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: