[Python-ideas] 80 character line width vs. something wider

spir denis.spir at free.fr
Wed May 20 12:19:41 CEST 2009


Le Wed, 20 May 2009 19:40:31 +1000,
Ben Finney <ben+python at benfinney.id.au> s'exprima ainsi:

> spir <denis.spir at free.fr> writes:
> 
> >             try:
> >                 my_final_result =
> > finalResultComputer(arg1_from_abunch_of_args, args_should_align_properly,
> >                                                       [so, what, if,
> > they, re, compound]) except AttributeError, error:
> >                 raise computeError( "foo .........         bar"
> >                                     "<--All message text lines should
> > start here." %(String, interpolation, argument, list, as, well) )
> 
> It's for this reason that I advocate indenting continued lines *one*
> level, and not this hideously large increase in indentation for a single
> step.
> 
> Simply break at the opening container character, and indent a single
> level to make all the contents line up::
> 
>     try:
>         my_final_result = finalResultComputer(
>             arg1_from_abunch_of_args,
>             args_should_align_properly,
>             [so, what, if, they, re, compound])
>     except AttributeError, error:
>         raise computeError(
>             "foo .........         bar"
>             "<--All message text lines should start here."
>             % (String, interpolation, argument, list, as, well))

Yes, I partially agree with you indentation mode. But to my eyes (maybe it's only me) the result (1) seems to suggest ordinary python indentation, which it is not and (2) does not make obvious what continuation lines belong to.
This can be a bit improved (again, to my eyes) using
~ double indentation for continuation lines
~ closing sings (parens, etc) on their own line
Which gives:

    try:
        my_final_result = finalResultComputer(
                arg1_from_abunch_of_args,
                args_should_align_properly,
                [so, what, if, they, re, compound]
                )
    except AttributeError, error:
        raise computeError(
                "foo .........         bar"
                "<--All message text lines should start here."
                % (String, interpolation, argument, list, as, well)
                )

This looks acceptable -- even if 2 more lines are spent vertically (another relevant point). For any reason, while in general I really do not support C-like style, in these precise cases I find the final closing mark on its own really helpful (esp. where I placed it here).

Denis
------
la vita e estrany



More information about the Python-ideas mailing list