This bool could've been an enum
Mitchell Hashimoto jokes about packing boolean flags into a single byte after Astral founder Charlie Marsh advocates for enums
The exchange contrasts code readability with low-level memory optimization.
Positive users welcome replacing bools with enums in code design because it brings functional programming benefits and avoids harmful bools, while negative users mock the idea as over-abstraction that risks silly extra values.
No Digg Deeper questions have been answered for this story yet.
Most Activity
@charliermarsh These 8 flags could’ve been a byte, but instead you used 8 bytes like a fool.
(Obv not you, specifically)
This bool could've been an enum

@charliermarsh ENUM bool { TRUE = "false" FALSE = "true" }

@charliermarsh true | false | "i-didnt-think-the-first-time-round"

@charliermarsh @alpha_convert Almost always should’ve been https://existentialtype.wordpress.com/2011/03/15/boolean-blindness/

@charliermarsh Been fighting this fight for years
@mitchellh Lol
@charliermarsh These 8 flags could’ve been a byte, but instead you used 8 bytes like a fool.
(Obv not you, specifically)

@charliermarsh You start with TRUE, FALSE and later you can add NOT_NOT_FALSE, ALMOST_TRUE and other helpful values.

@charliermarsh This enum could have been an ADT

@mitchellh @charliermarsh tired: 8 bools wired: single enum with 8 states inspired: 8 enums each with two states: FLAG_X_ON | FLAG_X_OFF

@charliermarsh OG

@charliermarsh The ones that go "isAdmin (true, false), isClient(true, false) ?

@nicbarkeragain @charliermarsh Well, an enum with 8 states isn't equivalent to 8 bools...

@charliermarsh I pitty the bool

@charliermarsh this abstraction could have been inlined, this code could have been non-existant, this product could have been an email, this computer could have been a rock

@charliermarsh - FALSE - TRUE - FILE_NOT_FOUND

@charliermarsh

@charliermarsh This enum could’ve been a bool

@charliermarsh booleans are enums btw

@charliermarsh I love seeing more fp ideas leaking out into the rest of the ecosystem.

@TheButterThief @charliermarsh This one is a classic. https://thedailywtf.com/articles/Classic-WTF-What-Is-Truth