Is it ever acceptable to use a negative name for a boolean variable? For example, I have a few user forms that have a checkbox for “N/A” or “Not Assessed”. These aren’t going to be used as a part of any query, nor are they going to be used in any complex application logic. These checkboxes exist solely so clinicians can acknowledge that they know they didn’t fill something out.
I normally wouldn’t drag a work disagreement onto the web, but I feel like I unfortunately need backup on this one. I work with a contractor that often gets deferential treatment because of how much more his time costs. He has decided to go through and mark all of my instances of “isNotApplicable” and “isNotAssessed” as “bad code needing revision”. I explained the scenario to him only to be informed that negative variable names are always bad, and that if he sees it, he will change it. It doesn’t sound like the biggest deal now, but there are a few forms coming up where changing a single word could cost people things like Medicare funding, and forcing the form to use the opposite of the stored value seems like a much bigger recipe for problems.
There are countless blogs and guides talking about how bad negative boolean naming is, but many of them acknowledge that there are exceptions. Unfortunately there isn’t much out there to help argue that maintaining clarity between the UI and the model is more important than preventing the possibility of double negatives appearing in your code, maybe because it seems too obvious, or maybe because I am just wrong. The strongest example I could find was a line from the Dart docs. Dart: Prefer Positive Names