Make Sure Boolean Names Imply True or False [VD6]
Tip VD6
Boolean variables hold logical “true” and “false” values. In the spirit of making sure variable names sufficiently and accurately communicate to a reader, ensure boolean names imply “true” or “false” when read.
Names like the following are poor boolean variable names since they don’t necessarily imply “true” or “false”:
conditionflagmodestatestatusvalue
Several examples are below:
There are plenty of other common words that can be part of boolean names. Many of them end in “-ed”. For example, state_changed would be an appropriate boolean variable name.
Depending on the scope/context, it may be appropriate to add additional words to disambiguate such variables from similar concepts. In short scopes, a name like file_readmay be fine, but in larger scopes, it’s possible that file_read could be confused for some actual “file” object that was read. If necessary, you can add other prefixes or suffixes to make the name more clearly boolean:
was_file_readfile_read_successfully