binary dreams

a world of 1s and 0s

Positive statements

Whenever I see variable names like FeatureDisabled or IgnoreFeature or FeatureNotActive it frustrate

Whenever I see variable names like FeatureDisabled or IgnoreFeature or FeatureNotActive it frustrates me because these can confuse you when trying to understand mysterious code. What would you expect the value of that variable to be? true or false? When you look at the word true what do you see? I see something is "on" and false will mean "off".

A variable like FeatureDisabled could appear as true and reading that means you need to revert your thinking while understanding the code. We naturally see true as something active or on. You see it on light switches, any IT equipment, you name it, on is true and off is false.

A boolean variable name should be like IsFeatureEnabled or HasSpecificValue - all positive verbs. It makes it so much easier to read and understand. The Is, Has, Was verbs all indicate this is a boolean statement and then just had something like Active or Enabled to indicate the status.

What if you are using code from something you don't have control of like the ones above? Just invert it so it looks positive from your side. Don't let that bad practice infect your good code!

Good luck and keep your statements positive!
Loading