Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103933 > unrolled thread

Re: Continuing indentation

Started byTim Chase <python.list@tim.thechases.com>
First post2016-03-02 17:00 -0600
Last post2016-03-02 17:00 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Continuing indentation Tim Chase <python.list@tim.thechases.com> - 2016-03-02 17:00 -0600

#103933 — Re: Continuing indentation

FromTim Chase <python.list@tim.thechases.com>
Date2016-03-02 17:00 -0600
SubjectRe: Continuing indentation
Message-ID<mailman.135.1456976094.20602.python-list@python.org>
On 2016-03-03 08:29, Ben Finney wrote:
> Skip Montanaro <skip.montanaro@gmail.com> writes:
>> Running flake8 over some code which has if statements with
>> multiple conditions like this:
>>
>>     if (some_condition and
>>         some_other_condition and
>>         some_final_condition):
>>         play_bingo()
> 
> For this reason I prefer to indent all continuation lines 8 spaces::
> 
>     if (
>             some_condition and
>             some_other_condition and
>             some_final_condition):
>         play_bingo()

This is generally what I do with two modifications, (1) putting
the conjunction at the beginning makes it easier for me to
read, and (2) putting the close-paren and colon on their own line to
make diffs cleaner when adding/removing conditions:

    if (
            some_condition
            and some_other_condition
            and some_additional_condition
            ):
        play_bingo()

making my diffs look like

     if (
             some_condition
             and some_other_condition
             and some_additional_condition
+            and some_new_condition
             ):
         play_bingo()

instead of

     if (
             some_condition
             and some_other_condition
-            and some_additional_condition):
+            and some_additional_condition
+            and some_new_condition):
         play_bingo()

which is harder to follow, IMHO.

Though, as a side note, if I have lots of "and" or "or" conjunctions,
I tend to use any() or all() on a list of them:

     if all([
             some_condition,
             some_other_condition,
             some_additional_condition,
+            some_new_condition,
             ]):
         play_bingo()

which I happen to find even tidier (though it might come at a minor
performance penalty, having not tested it since it's never mattered
in my code)

-tkc



[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web