What “truthy” values do you expect to be understood in boolean environment variable flags? “true”, “yes”, “on”, “1” … any others?

13 comments

  1. @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

  2. @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.

  3. @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”

    1. 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.

  4. @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

  5. @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.

Leave a Reply

Your email address will not be published. Required fields are marked *