Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Boolean method naming readability [closed]

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
like image 709
Luiz Carvalho Avatar asked Apr 25 '13 12:04

Luiz Carvalho


People also ask

How do you name a method that returns a boolean?

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().

How do you name Booleans in Python?

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.

What should I name my Booleans?

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.


1 Answers

I would choose the first one (from the point of view of a Java developer).

like image 174
Osvaldo Costa Avatar answered Nov 15 '22 13:11

Osvaldo Costa