[Python-ideas] Boolean parameters guidelines

Joseph Martinot-Lagarde contrebasse at gmail.com
Tue May 10 19:59:47 EDT 2016

> I meant that I disagreed in several cases with whether an example was Good
or Bad and I couldn't figure out what rule you were using in your head to
decide on Good/Bad, IOW what rule you were illustrating with these examples.

Alright, I'll add some explanation. I took an example already used in this
thread to be more clear.

    # Bad: no indication on what the boolean argument does.
    process(data, True)

    # Good: the boolean is used to indicate that errors are raised.
    process(data, raise_errors=True)

    # Good: the variable name is used to indicate what the argument means.
    process(data, raise_errors)

    # Meh: both the keyword and the variable name are used to indicate what
the argument means. It's not really bad, but it adds no information while
adding redundancy. This would happend if the keyword is required.
    process(data, raise_errors=raise_errors)

    # Bad: a variable name is used but it doesn't indicate anything on its
    process(data, w)

More information about the Python-ideas mailing list