Two-Dimensional Expression Layout

Terry Reedy tjreedy at udel.edu
Fri Aug 19 13:52:57 EDT 2016


On 8/19/2016 4:56 AM, Lawrence D’Oliveiro wrote:
> It is handy to be able to keep complex expressions together sometimes, when breaking them up would simply obscure their structure. To avoid lines getting long, why not take advantage of the two available screen/page dimensions to make their structure clearer? As a bonus, spacing out parentheses makes them look less of a clutter.
>
> Examples from <https://github.com/ldo/qahirah_examples/blob/master/operators>:

To me, putting parens and '+' and 'or' on separate lines emphasizes them 
too much and makes the layout more, not less, cluttered.  But I won't 
argue with what you do in your own private code.

> A function call with complex arguments (specifying arguments by keywords is highly recommended here):
>
>     rect_1_pattern = \
>         qah.Pattern.create_linear \
>           (
>             p0 = (0, 0),
>             p1 = (major_dim, 0),
>             colour_stops =
>                 (
>                     (0, rect_1_colour),
>                     (1, complement(rect_1_colour)),
>                 )
>           )
>
> Computing a variable value (using redundant parentheses to avoid backslash-continuations):
>
>     dest_rect = \
>         (
>             draw_bounds
>         +
>             Vector(col, row) * draw_bounds.dimensions
>         +
>             Vector(0, top_extra)
>         )
>
> From <https://github.com/ldo/python_pixman/blob/master/pixman.py>, a complex condition (with redundant parentheses again):
>
>     if (
>             not isinstance(src, Image)
>         or
>             mask != None and not isinstance(mask, Image)
>         or
>             not isinstance(dest, Image)
>     ) :
>         raise TypeError("image args must be Image objects")
>     #end if
>


-- 
Terry Jan Reedy





More information about the Python-list mailing list