[Python-ideas] A more readable way to nest functions

Mikhail V mikhailwas at gmail.com
Mon Jan 30 14:52:10 EST 2017


On 27 January 2017 at 22:07, Brent Brinkley <brentbrinkley at gmail.com> wrote:

> HI Everyone,
>
> One issue that I’ve seen in a lot of languages struggle with is nested
> function calls.
>
Parenthesis when nested inherently create readability issues.
>
>
Yes there is such issue. I don't see however that a radical
change to nested notation can be a solution here.
Not because it is too hard to find a consensus about how it
should be, but also because in some sense
the parenthesis nesting is sort of optimal for general case.

It is hard to explain in simple words, but some of the answers
gave hints already -- if you try some more complex nesting
with your proposed example, it will end up with even *worse*
schemas than parenthesis notation.

One important note about parenthesis itself: often it looks so
bad simply because in monospaced font, e.g. Courier, parenthesis
is sort of "slightly bent letter I"  which results in really bad look,
and the *correct* parenthesis character is a rounded bracket,
which extends to bottom ant top much further than letters.
It has thin endpoints and thicker middle. And it should be given
some space from left and right.
So a big part of the problem lies in the font.

As for the problem of long equations. Here could be many proposals.
My opinion: nested equations must be broken into series of smaller ones,
but unfortunately
Python does not provide a standard solution here.

*Theoretically* I see a solution by 'inlined' statements.
Take a long example:

    print ( merge (a, b, merge ( long_variable2, long_variable2 ) )

Now just split it in 2 lines:

    tmp <> merge ( long_variable2, long_variable2 )
    print ( merge (a, b, tmp )  )


So I'd for example invent a special sign which just marks
statements that will be first collected as inline text, sort of macros.
But as always, in such cases there is little chance to find
any consensus due to many reasons.
One of the reasons that there are too few good looking
characters out there, and same applies for any possible improvement.


Mikhail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170130/2c1227ee/attachment.html>


More information about the Python-ideas mailing list