osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

style: single and multiple lines


ram at zedat.fu-berlin.de (Stefan Ram):

> def f(x): return 2*x
>
>   . So this single-line style should not be that bad.

I very rarely allow myself to write single-line complex statements. It
is usually when defining exceptions:

   class SyntaxError(Exception): pass

if even then.

> def f(x):
>     return 2*x

Despite PEP 8, I always separate binary operators from operands with
spaces:

    def f(x):
        return 2 * x

I have made myself abide by PEP 8 wrt named arguments (no space around
'='):

    def f(x=7):
        return 2 * x

    y = f(x=3)


>   ? And is
>
> def f(x):
>     y = x*2
>     return y
>
>   better than
>
> def f(x):
>     y = x*2; return y

Yes. Semicolons can be defended only in single-line shell command
trickery.

>   PS: The most difficult part for me is to write
>
> f(x)
>
>   instead of
>
> f( x )

For whatever reason, I find it clearest to put separate braces and
brackets with spaces:

    vip = [ employee in faculty
            for employee.pay_grade >= BOSS.pay_grade ]

    return { "name" : "length", "value" : 17 }


Marko