• Excrubulent@slrpnk.net
    link
    fedilink
    English
    arrow-up
    7
    ·
    1 day ago

    Only if it’s performance sensitive. Otherwise you’re wasting programmer time both writing and reading the code, and you’ve made it less maintainable with more complexities where bugs can creep in.

    The vast majority of the time you can afford a few wasted bits.

    Honestly though I don’t quite understand why a compiler couldn’t optimise this process. Like it knows what a boolean is, surely it could reduce them down to bits.

    • calcopiritus@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      21 hours ago

      Well, to get a boolean out of a bit array you have to do some operations. So at first it doesn’t make it more performant. Compilers probably don’t automatically make them bitarrays because of that.

      However, the memory savings means less cache used. And a cache miss is way more expensive than those bit operations. So they should be more performant. I’m sure someone out there has done the actual research and there’s a good reason why compilers don’t make all booleans bitarrays.