Changes between Version 14 and Version 15 of CodingStandards


Ignore:
Timestamp:
2011-09-26T22:29:40Z (13 years ago)
Author:
davidsarah
Comment:

dispute implicit conversion to boolean

Legend:

Unmodified
Added
Removed
Modified
  • CodingStandards

    v14 v15  
    4343
    4444 * Don't use the literals {{{True}}} or {{{False}}} in conditional expressions -- instead just write the expression which will evaluate to true or false. For example, write {{{if expr:}}} instead of {{{if expr == True:}}} and {{{if not expr:}}} instead of {{{if expr == False:}}}.
    45  * Use the fact that empty sequences, empty strings, empty dicts, {{{0}}}, and {{{None}}} all evaluate to false. Write {{{if not items:}}} instead of {{{if len(items) == 0:}}}.
     45 * ''Disputed'': Use the fact that empty sequences, empty strings, empty dicts, {{{0}}}, and {{{None}}} all evaluate to false. Write {{{if not items:}}} instead of {{{if len(items) == 0:}}}.
     46   * I disagree with relying on implicit conversion to boolean; I think it's error-prone (and we have had real bugs because of it). -- David-Sarah
    4647 * But if your intent is to test for {{{None}}} instead of to test for "any false thing", then write it out as {{{if thing is None:}}}.
    4748