[Python-ideas] Multi Statement Lambdas

Andreas Winschu andrej.wins at gmail.com
Sun Oct 21 12:06:21 EDT 2018


There was an extensive discussion about this in the past.

https://www.artima.com/weblogs/viewpost.jsp?thread=147358

In the end Guido felt that his effort seems to him like building a Rube
Goldberg machine.

By looking at the amount of people still stumbling on this issue
we definitely feel, that it is not
the. Such a machine is a useful one.

"Naming things" was from the beginning one the two hardest things in
programming. Good naming is important for understandable code. The balance
of extracted, named functions, as most of things in programming, is
subjective though.

The python style guide itself encourages people to use simple data
transformations like `map`, `filter`, `reduce` for expressiveness. Those
transformations can still be simple with 2 or 3 statements and will not
require naming. Naming the transformation becomes harder, than reading the
actual code.

Coffeescript, which is another indent based language, handles multi
statement lambdas
without curly braces.

*arr = []*
*arr.map((x)-> *
*  y = x+1*
*  y * 2*
*)*

There is also an argument in this discussion, that just using curly braces
for lambdas (which is easier to implement) would be pretty unpythonic.

I really agree that python curly braces free block style is really helpful
for readability in contrast to javascript for example. However using curly
braces for lambdas in ruby is not hurting the eyes that much. Normally
blocks in ruby  use `do .. end` notation. Thus lambdas are clearly visible
and also people try not to nest multiple levels of lamda transfromations.
We strive to keep such a chain flat.


*def transform   arr*
*     .map {  ... }*

*     .filter  { ... }     .reduce { ... }*

In the end curly branes for lambdas is also a mathematical notation.

Guido had a hard opinion on this, but i hope the python community does not.
A powerful general purpose language should not limit itself to one
statement in a closure.
Lets add mutli-statement lambdas to python either with just curly braces or
with an indent based machine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181021/b18ea6e3/attachment.html>


More information about the Python-ideas mailing list