Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- Here are some rules to follow when you're naming Boolean variables:
- Use a prefix that clearly denotes it as a Boolean. Some developers prefer to use "can", "is", "has", or "should" as a prefix.
- 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.
- Make it clear what true and false mean for the variable.
- Here are some examples:
- isAvailable instead of Availability
- hasCompleted instead of CompletionStatus
- canEdit instead of Editability
- shouldUpdate instead of UpdateStatus
- 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