Remix.run Logo
superxpro12 4 days ago

We added a clause in our coding standard to make all booleans reference the positive frame of reference only. This happened after I got fed up with dealing with too many if !(!not_has_missing_field) operators. Just.... make everything positive: if (is_field_present)

4 days ago | parent | next [-]
[deleted]
dspillett 4 days ago | parent | prev | next [-]

I try to keep to that, but sometimes the flag is turning on a negative feature, disabling that which is the default and will remain so for compatibility reasons.

Sometimes it is worth the effort of going through and changing the logic elsewhere to keep the boolean positive, sometimes that would be too much effort to retest at the time.

Another option I like, when I have a config object interpreting things so I'm reading doing `if (config.IsWhateverThatThingIsEnabled)` then I can just have paired properties to pick from when I want to check IsEnabled or IsDisabled.

I've come across code where there is an overide for an option to disable something and the naming plus the logical not really make you think about what is happening…

    if (!OverrideDisabledOptionToBlockAction) {}
layer8 4 days ago | parent | prev [-]

However, if all tests happen to be of the form `if (!isValid)`, one might reconsider and use `isInvalid` instead.