Charlie Marsh, Astral founder, shares a Rust code review proposing enums over booleans to improve function clarity
The change replaces an initialize_globals boolean parameter.
Many users praised the Ruff CEO's suggestion to prefer enums over booleans in code because it improves long-term maintainability and code quality.
No Digg Deeper questions have been answered for this story yet.
Most Activity
@charliermarsh Bro reads code in big 2026 wtf
(based and quality pilled)
I'm not kidding

@charliermarsh I first learned this from the proto devs https://protobuf.dev/best-practices/dos-donts/#bad-bools
@xeophon They said it couldn’t be done!
@charliermarsh Bro reads code in big 2026 wtf
(based and quality pilled)

@charliermarsh python deals with this well by allowing kwargs to be declared as non positional

@charliermarsh languages shouldn't have bools, just make it all enums but also allow enums to be anonymous/inline like typescript's unions

@charliermarsh enum InitializeGlobalBool { InitializeGlobalTrue; InitializeGlobalFalse }
so much better

@charliermarsh enum GlobalsState { Initialized, NonInitialized, Maybe, AskingForAFriend, }

@charliermarsh Rust reviewers can smell a future enum from 10 PRs away. 👀

@charliermarsh could it be a static var that `run` keeps track of though

@charliermarsh How about drop initialize argument completely, make a struct, impl it and store the flag? No need to have weird comments for the method. Abstract that stuff from the method caller

@charliermarsh Inits should never be a single bool. Enum is okay. Or a set of delegates that lets you orchestrate your boot process correctly.

@charliermarsh Only when you can have union type as enums tho. But man rust get some basic things so right

@charliermarsh Globals, evil! More params needed

@charliermarsh I definitely agree

@charliermarsh The world is thanking you since it knows that the future migration will burn enough tokens, electricity, and humans to fix the boolean.
Thank you sir!

@charliermarsh run(cli, true) doesn't read right :^)

@charliermarsh This argument is bad taste regardless

@charliermarsh this is particularly done a lot in serenity/ladybird C++ code:
```cpp enum class DoOptionalThing { Yes, No };
class MyClass { public: int frobnicate(DoOptionalThing do_optional_thing = DoOptionalThing::No); }; ```

@charliermarsh Tbh var isn’t prefixed with “is” or “should”
Enum would be more descriptive imo

@charliermarsh for stuff like this, I personally use http://bon-rs.com and the callsite becomes run(cli).initialize_globals(true), rather than defining an enum for everything. I prefer this over an enum for every choice, as there's no new type you define manually. But I can see why enum