Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103933
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Continuing indentation |
| Date | 2016-03-02 17:00 -0600 |
| Message-ID | <mailman.135.1456976094.20602.python-list@python.org> (permalink) |
| References | <CANc-5Uz=mG6r9uw94tizxUh7eT=ftB1+z6d5nwzhDC=8+6YV1w@mail.gmail.com> <85egbsvaa0.fsf@benfinney.id.au> |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Continuing indentation Tim Chase <python.list@tim.thechases.com> - 2016-03-02 17:00 -0600
csiph-web