Advertisement
ivandrofly

name suggestion for boolean expression in c#

Aug 4th, 2023
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. In C#, when you're naming variables representing Boolean values, the advice is to use names that directly reflect the state that they represent. This improves code readability, making it more understandable to whoever reads your code next.
  2. Here are some rules to follow when you're naming Boolean variables:
  3.  
  4. Use a prefix that clearly denotes it as a Boolean. Some developers prefer to use "can", "is", "has", or "should" as a prefix.
  5. Avoid negative words in the name. If you use a negative word in the name (like "isNotAvailable"), it might lead to confusing double negatives when the variable's value is false.
  6. Make it clear what true and false mean for the variable.
  7. Here are some examples:
  8.  
  9. isAvailable instead of Availability
  10. hasCompleted instead of CompletionStatus
  11. canEdit instead of Editability
  12. shouldUpdate instead of UpdateStatus
  13.  
  14. These are better because it is clear that a true value for isAvailable means the item is available, whereas a true value for Availability is ambiguous. The same clarity applies to the other examples. By naming your variables well, you make your code easier to read and maintain.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement