Re: Proposal: Complex comprehensions containing statements

I am disliking this proposal at all, more from a gut-feel than anything. But then I just did `import this` and pasted bellow the parts I think this violates. While we all have to keep in mind that the "zen of Python" are more guidelines than absolute standards, they still are _good_ guidelines that have brought the language to where it is. So, these are the zen violations that stroke me on first sight: Simple is better than complex. Flat is better than nested. Sparse is better than dense. Readability counts. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. -------- Other than that, I am having trouble to understand how proper indentation of blocks would work under this proposal. Does opening a `[{(` and having any `:` statements inside just imply one more indentation level? Or can the statements inside be validly less indented than the line containing the `= [...` opening bracket? And, just for general, objective feedback, "I am -1 on this". On Fri, 21 Feb 2020 at 11:32, Dominik Vilsmeier <Dominik.Vilsmeier@gmx.de> wrote:

OK, I think the verdict is in and I will not try to debate it.
I think this is a fun question. I can't think of any good reason to allow indenting less than the containing statement, but I'm also wondering if there's edge cases I might be missing. If not, then maybe we can indeed just require adding another indentation level. And maybe that means that statements inside expressions wouldn't require a Rube Goldberg machine ;) If anyone is curious, I initially wrote [a much larger proposal with several overlapping subproposals in which `if`, `try`, and `def` could all be used as expressions](https://www.reddit.com/r/Python/comments/f5wm1d/proposal_compound_statement_...). I figured that was hopelessly ambitious and just submitted the part I liked best.

I'll lend a supportive voice here: I like the proposal and would probably make use of this kind of syntax quite a bit, but I think the requirement of yield is definitely a necessity. Too much ambiguity without it. And adding the yield, IMO, doesn't clutter things up too badly. Using one of the code examples, it looks pretty good to me: [ for row in matrix: [ for cell in row: yield f(cell) ] ] Of course, anything that does not contain a yield statement would need to be a syntax error or it could cause problems when refactoring from "regular" looping code, and forgetting to add the yield. --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler On Fri, Feb 21, 2020 at 3:40 PM Alex Hall <alex.mojaki@gmail.com> wrote:

Thanks Ricky :) Technically, if yield is always required, it would have to look like this: [ for row in matrix: yield [ for cell in row: yield f(cell) ] ]

I am disliking this proposal at all, more from a gut-feel than anything. But then I just did `import this` and pasted bellow the parts I think this violates. While we all have to keep in mind that the "zen of Python" are more guidelines than absolute standards, they still are _good_ guidelines that have brought the language to where it is. So, these are the zen violations that stroke me on first sight: Simple is better than complex. Flat is better than nested. Sparse is better than dense. Readability counts. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. -------- Other than that, I am having trouble to understand how proper indentation of blocks would work under this proposal. Does opening a `[{(` and having any `:` statements inside just imply one more indentation level? Or can the statements inside be validly less indented than the line containing the `= [...` opening bracket? And, just for general, objective feedback, "I am -1 on this". On Fri, 21 Feb 2020 at 11:32, Dominik Vilsmeier <Dominik.Vilsmeier@gmx.de> wrote:

OK, I think the verdict is in and I will not try to debate it.
I think this is a fun question. I can't think of any good reason to allow indenting less than the containing statement, but I'm also wondering if there's edge cases I might be missing. If not, then maybe we can indeed just require adding another indentation level. And maybe that means that statements inside expressions wouldn't require a Rube Goldberg machine ;) If anyone is curious, I initially wrote [a much larger proposal with several overlapping subproposals in which `if`, `try`, and `def` could all be used as expressions](https://www.reddit.com/r/Python/comments/f5wm1d/proposal_compound_statement_...). I figured that was hopelessly ambitious and just submitted the part I liked best.

I'll lend a supportive voice here: I like the proposal and would probably make use of this kind of syntax quite a bit, but I think the requirement of yield is definitely a necessity. Too much ambiguity without it. And adding the yield, IMO, doesn't clutter things up too badly. Using one of the code examples, it looks pretty good to me: [ for row in matrix: [ for cell in row: yield f(cell) ] ] Of course, anything that does not contain a yield statement would need to be a syntax error or it could cause problems when refactoring from "regular" looping code, and forgetting to add the yield. --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler On Fri, Feb 21, 2020 at 3:40 PM Alex Hall <alex.mojaki@gmail.com> wrote:

Thanks Ricky :) Technically, if yield is always required, it would have to look like this: [ for row in matrix: yield [ for cell in row: yield f(cell) ] ]
participants (4)
-
Alex Hall
-
Dominik Vilsmeier
-
Joao S. O. Bueno
-
Ricky Teachey