Skip to content

Comment on Don’t Use Booleans

Comments

Surprisingly sensible. I wonder if compiler magic could, in theory, reduce enums that have only two options down to a single bit, but still provide all the type safety guarantees. Or maybe provide another primitive just for that purpose.

Particularly with a new primitive, you could literally have a language that just doesn't allow you to define generic booleans.

luuioOP

At the bare metal layer, most booleans are actually transported around as `int` (or WORD size), so there's no real performance benefit to compressing things down to one bit, other than if you really need to save 7 bits in physical storage.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.