BlogPost_BooleanNames #22

Merged
jeff merged 12 commits from BlogPost_BooleanNames into master 2020-07-30 22:44:26 +00:00
Showing only changes of commit b0c63765d1 - Show all commits

View File

@ -20,7 +20,7 @@ Variable names for booleans: avoid names that are already a negation (notReady,
find examples in OSS (Gitea notify) find examples in OSS (Gitea notify)
The book, _The Elements of Style_<sup>1</sup>, is a concise guide to writing. Some rules can be used as a guide for writing code as well. For example, rule 11, "Put statements in positive form," can be applied to naming boolean variables. Keep boolean names in the positive as well, with one additional requirement: do not use the positive form of a negative statement. `enabled` is in the positive form and a positive statement. `disabled` is in the positive form, but is a negative statement. `notEnabled` is both in the negative form and a negative statement. In writing, it is best to use enabled or disabled, and to avoid "not enabled"; they are more concise and stay in the positive form. The extra requirement of using a positive statement for names is because boolean variables' negations have meaning as well; in writing "not disabled" is a double negative and is discouraged. In code, `!disabled`, is also a double negative. The book, _The Elements of Style_<sup>1</sup>, is a concise guide to writing. Some rules can be used as a guide for writing code as well. For example, rule 11, "Put statements in positive form," can be applied to naming boolean variables. Keep boolean names in the positive as well, with one additional requirement: do not use the positive form of a negative statement. `enabled` is in the positive form and a positive statement. `disabled` is in the positive form, but is a negative statement. `notEnabled` is both in the negative form and a negative statement. In writing, it is best to use enabled or disabled, and to avoid "not enabled"; they are more concise and stay in the positive form. The extra requirement of using a positive statement for names is because boolean variables' negations have meaning as well; in writing "not disabled" is a double negative and is discouraged. In code, `!disabled`, is also a double negative, and should be avoided.
Read PoP and PoSD for bool blog post Read PoP and PoSD for bool blog post