Which of these ways is more readable for Boolean Method in Python?
document.is_editable
document.editable
document.has_editable
document.can_be_editable
document.can_edit
The usual convention to name methods that return boolean is to prefix verbs such as 'is' or 'has' to the predicate as a question, or use the predicate as an assertion. For example, to check if a user is active, you would say user. isActive() or to check if the user exists, you would say user. exists().
There is no standard naming convention specific to boolean-returning methods. However, PEP8 does have a guide for naming functions. Function names should be lowercase, with words separated by underscores as necessary to improve readability.
When naming booleans, you should avoid choosing variable names that include negations. It's better to name the variable without the negation and flip the value. If you absolutely can't (see Guideline 2 below), then try to find an already-negated form of the concept you are trying to express.
I would choose the first one (from the point of view of a Java developer).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With