Allow multiline conditions and the like

Chris Rebert clp2 at
Thu Nov 4 22:00:56 CET 2010

On Thu, Nov 4, 2010 at 11:09 AM, Mark Wooding <mdw at> wrote:
> Chris Rebert <clp2 at> writes:
>> Or, if possible, refactor the conditional into a function (call) so
>> it's no longer multiline in the first place.
> No!  This /increases/ cognitive load for readers, because they have to
> deal with the indirection through the name.

If it's well-named, then the reader can delay having to read the definition.

> If you actually use the
> function multiple times, the mental overhead of forming the abstraction
> and associating it with the function name is shared across the various
> call sites and it's probably worth it.  If it's only called once, leave
> it inline.

I'd say it's a judgment call. If the condition is sufficiently
complicated and can be well-named, then I see justifying refactoring
it into a function even if it's only used once.
However, this is admittedly not a common situation.


More information about the Python-list mailing list