More additions based on comments from Tim Peters, Neal Norwitz,
Gerhard Haring, and Guido van Rossum.
This commit is contained in:
parent
7c91cd266a
commit
a086f6d04f
18
pep-0008.txt
18
pep-0008.txt
|
@ -500,9 +500,15 @@ Naming Conventions
|
|||
over class_ then just be consistent. :).
|
||||
|
||||
|
||||
Optimization and Other Programming Recommendations
|
||||
Programming Recommendations
|
||||
|
||||
- class-based exceptions are always preferred over string-based
|
||||
- Comparisons to singletons like None should always be done with
|
||||
'is' or 'is not'. Also, beware of writing "if x" when you
|
||||
really mean "if x is not None" -- e.g. when testing whether a
|
||||
variable or argument that defaults to None was set to some other
|
||||
value.
|
||||
|
||||
- Class-based exceptions are always preferred over string-based
|
||||
exceptions. Modules or packages should define their own
|
||||
domain-specific base exception class, which should be subclassed
|
||||
from the built-in Exception class. Always include a class
|
||||
|
@ -542,6 +548,14 @@ Optimization and Other Programming Recommendations
|
|||
sequences are false, so "if not seq" or "if seq" is preferable
|
||||
to "if len(seq)" or "if not len(seq)".
|
||||
|
||||
- Don't write string literals that rely on significant trailing
|
||||
whitespace. Such trailing whitespace is visually
|
||||
indistinguishable and some editors (or more recently,
|
||||
reindent.py) will trim them.
|
||||
|
||||
- Don't compare boolean values to True or False using == (bool
|
||||
types are new in Python 2.3).
|
||||
|
||||
|
||||
References
|
||||
|
||||
|
|
Loading…
Reference in New Issue