More additions based on comments from Tim Peters, Neal Norwitz,

Gerhard Haring, and Guido van Rossum.
This commit is contained in:
Barry Warsaw 2002-05-24 19:39:47 +00:00
parent 7c91cd266a
commit a086f6d04f
1 changed files with 16 additions and 2 deletions

View File

@ -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