News for hackers. Stuff that matters.
Re:What's Coming in Python 3.8 by toxik on Wednesday July 17, 2019 @08:40PM (#20465540)
This completely contradicts the rest of Python grammar, and indeed many languages’ grammars. The consistent way would then be `while x < 10` but that too looks ridiculous. The issue is that you can’t have post-clause syntax in Python due to its infamous spacing-is-syntax idea.
Re:What's Coming in Python 3.8 by ben509 on Wednesday July 17, 2019 @10:24PM (#20466148)
I'm not sure why the consistent way looks ridiculous.

    do:
        body()
        body()
    while x < 10
It's just a compound statement consumes the trailing while clause.

Decorators already precede a function (or class) definition[2], and one alternative for the ill-fated switch statement[1] was to have switch precede the case blocks to avoid excessive indentation.

So there's plenty of precedent in the other direction.

[1]: https://www.python.org/dev/peps/pep-3103/#alternative-3

[2]: https://docs.python.org/3/reference/grammar.html

Re:What's Coming in Python 3.8 by toxik on Thursday July 18, 2019 @11:21AM (#20470737)
I think you're really stretching it when you say "there's plenty of precedent," arguably there is none as the decorator syntax is pre-clause and thus poses no indentation reading issues. So too for the proposed switch statement syntax. Then there is the fact that the decorator syntax is perhaps the most alien of all Python syntax, sometimes criticized for being Perlesque, perish the thought (on account of it being introduced by creative interpretation of a single special character though, so perhaps unrelated.)

My main gripe is the indentation. Your code reads as if the while condition is tested after the loop finishes. What if the while statement was part of the loop and could be placed arbitrarily?

    do:
        body1()
        body2()
        while x < 10
        body3()
IOW `do:` translates to `while True:` and `while x` to `if not x: break`.

Addendum: I would also entertain forcing the `while` to be at the end of the loop -- as I'm not sure what this would do

    do:
        if foo():
            while x < 10
Re:What's Coming in Python 3.8 by ben509 on Thursday July 18, 2019 @03:21PM (#20473086)
I think it's precedent because it's just a line after a block instead of before it. It certainly is a break from Python's "big outline" look.

> What if the while statement was part of the loop and could be placed arbitrarily?

If you're open to that, I had thought this was a bridge too far, but:

    do:
        body1()
        break if some_condition
        body2()
        continue if some_other_condition
Under that scheme, the semantics translate to:

    while True:
        do_body
        break
And, of course, the `break if` and `continue if` syntax would be general.
Re:What's Coming in Python 3.8 by mkl on Wednesday July 17, 2019 @09:38PM (#20465892)
Of course you can have post-clause syntax: if...else, try...except, for...else, etc.

(Edit: Actually, I think I know what you were saying now, and those aren't quite the same thing as they need a line after them.)

I do think the condition on the next line isn't the way to do solve this problem though (and I don't think it needs solving, while True: ... if ...: break does the job).

Re:What's Coming in Python 3.8 by krferriter on Wednesday July 17, 2019 @09:16PM (#20465731)
Why does `while x < 10` look ridiculous? It looks exactly like the syntax for regular while loops, just in this case it's after a `do:` block. And the example above yours looks like try/catch syntax, but tbh I like the one you suggested a bit more.
Re:What's Coming in Python 3.8 by nerdponx on Wednesday July 17, 2019 @09:21PM (#20465759)
You're right, it would be pretty weird to rely on implicitly "returning" a value from an expression like that.

But I don't think having it all on one line would be that bad.