A desperate lunge for on-topic-ness

Tim Chase python.list at tim.thechases.com
Thu Oct 18 07:05:34 EDT 2012


On 10/18/12 04:33, wxjmfauth at gmail.com wrote:
> I use a "double indentation".
> 
>>>> if 'asdf' and 'asdf' and 'asdf' \
> ...         'asdf' and 'asdf' and \
> ...         'asdf' and 'asdf':
> ...     print('do if')
> ...     s = 'asdf'
> ...     ss = 'asdf'
> ...     
> do if
>>>> if looks_like_it_might_be_spam(
> ...         some_longer_variables,
> ...         here_and_here, and_here_also):
> ...     logger.notice("might be spam")
> ...     move_to_spam_folder(some_longer_variables)
> ...     update_spam_statistics(here_and_here)

I lean towards double-indent as well, though I favor parens/brackets
vs. trailing backslashes.  My conditions usually go one-per-line,
too.  I also tend to put my closing paren+colon on a stand-alone line:

    if (
            something
            or something_else
            or yet_other_stuff
            ):
        do_thing1()
        do_thing2()

It's not quite as nice with pure parens, working better with
function-calls.  However, it makes my git/svn diffs easier to read
when conditions get added/removed because only that line (usually)
changes, rather than having the noise of the paren moving around.

In 2.5 and later, I like to write that as

    if any([
            something,
            something_else,
            yet_other_stuff,
            ]):
        do_thing1()
        do_thing2()

where each item is uniform (one trailing comma, rather than one item
being special without a comma/or/and) so I don't have the diff noise
for "or"/"and" bouncing around either.

Making my diffs easy to read is pretty important to me.

-tkc

PS: and in such cases, yes, I often alphabetize my conditions too as
long as the order doesn't matter.  Just a little CDO.  That's OCD,
but in alphabetical order the way the letters should be :-)









More information about the Python-list mailing list