[Python-ideas] A more readable way to nest functions
Ethan Furman
ethan at stoneleaf.us
Fri Jan 27 16:28:54 EST 2017
On 01/27/2017 01:07 PM, Brent Brinkley wrote:
> I’m relatively new to the world of python
Welcome!
> but in my short time here I’ve
> fallen in love with how readable this language is. One issue that I’ve
> seen in a lot of languages struggle with is nested function calls.
> Parenthesis when nested inherently create readability issues. I stumbled
> upon what I believe is an elegant solution within the elm platform in
> their use of the backward pipe operator <|.
Please use text -- it save responders from having to reenter the non-text content>
> Suggested structure:
>
> print() <| some_func() <| another_func("Hello")
My first question is what does this look like when print() and some_func() have other parameters? In other words, what would this look like?
print('hello', name, some_func('whatsit', another_func('good-bye')), sep=' .-. ')
Currently, I would format that as:
print(
'hello',
name,
some_func(
'whatsit',
another_func(
'good-bye')
),
),
sep=' .-. ',
)
Okay, maybe a few more new-lines than such a short example requires, but that's the idea.
--
~Ethan~
More information about the Python-ideas
mailing list