What “truthy” values do you expect to be understood in boolean environment variable flags? “true”, “yes”, “on”, “1” … any others?
Avdi Grimm, Code Cleric
What “truthy” values do you expect to be understood in boolean environment variable flags? “true”, “yes”, “on”, “1” … any others?
@avdi "active", " enabled "
@avdi
probably would add "enabled"/"disabled" and "active"/"inactive"
@avdi in environment variables, anything other than the empty string. And if its a setting.that defaults enabled with an environment var to disable it, choose a negative name. DISABLE_THE_THING=1 ./exe
@avdi enabled, maybe?
@avdi "y". Maybe "t". And upper/mixed case versions of them all.
@avdi Non-empty lists and other objects/structures with a definition of empty including non-empty strings.
@avdi I was reading a story the other day about two databases that had to be merged, one Norwegian and one English. The English one used “Y” an “N” as a text field, and the Norwegian one used “Ja” and “Nei” as a text field. But sometimes J and N.
It sounded like a right mess.
@avdi To answer your question I don’t know what you mean by expect. I would try “true” first but not be surprised at any variation on capitalization on “true”
Then it depends on the flag name, I might not be surprised by Y or Yes (any caps)
I would be surprised by 0 and 1 in an environment variable. “On”, again it depends on the name of the variable
Part of me wants to answer “anything other than false, 0, or null would be true”
That’s funny because IME 0/1 are the most historically expected values – even yes/true might not be respected in older programs, but “1” should always be respected as an enable value.
@avdi I typically just use :present?—unless it's a dangerous option, in which case I make it something annoyingly long and worrying, like:
BYPASS_SAFETY_CHECKS=if-this-is-used-in-prod-somebody-is-getting-fired
@avdi "y"
@avdi Often, any non-blank value is considered thruthy when it comes from environment variables
@avdi: For me, it depends on how the prompt is phrased. Make it conversational.
Prompt: Enable {feature name}? -> Yes/No
Prompt: {feature name}? -> On/Off
That sort of thing.