[Python-ideas] Control Flow - Never Executed Loop Body

Andrew Barnert abarnert at yahoo.com
Wed Mar 23 18:17:22 EDT 2016


On Mar 23, 2016, at 13:26, Sven R. Kunze <srkunze at mail.de> wrote:
> 
>> On 23.03.2016 16:53, Andrew Barnert via Python-ideas wrote:
>> On Mar 23, 2016, at 03:08, Michel Desmoulin <desmoulinmichel at gmail.com> wrote:
>> 
>>>> But I think it is a coherent proposal, even if it's not one I like. :)
>>> And what do you think about adding except clauses to if ? with ? while ?
>> Well, they don't have the problem that for has (for is already implicitly handling a specific exception in a specific way; none of them are), so they're coherent even without a solution to that problem.
> 
> Could you describe what you mean by coherent?

Someone earlier claimed that it's impossible to turn the vague proposal into any actual sensible semantics that could be implemented by Python. That would make it incoherent. But I don't believe it's true, so I tried to show how it could be defined well enough to be implementable. For the other three statements, I don't think that argument even comes up; I think the desired semantics are obvious enough that nobody can claim the proposal is incoherent.

>> (With has the additional problem that it may not be immediately obvious on first glance whether the exit gets calls before or after the except clause, but if so, people can read the docs the first time they come across it and remember it after that.)
>> 
>> But I also think they're even less necessary. They'd all be pure syntactic sugar for nesting the statement and a try/except, so we'd be making the language more complicated to learn and remember,
> 
> I completely disagree here.
> 
>> and encouraging more code that isn't backward compatible.
> 
> What exactly is the problem with that? Everything discussed on python-ideas would be 3.6+ anyway.

Yes, but it's still a cost, that has to be weighed against the benefits. Some new syntax (like "with" or "yield from") is so useful that it's worth encouraging new code to use the new features and not be backward compatible. But that doesn't mean every piece of syntax that might be nice in a brand-new language is so useful that it's worth doing that. It's a high bar, and just ignoring the bar doesn't help you meet it.

>>  That's not a huge cost, but the benefit isn't very big either. For _really_ short cases, I think we want except expressions (PEP 463); for longish code, there's nothing wrong with an explicit try; the range for which hiding an implicit try inside if and while would really improve things is small enough that I don't think the benefit outweighs the cost.
> 
> That's your opinion here. And I find it interesting that others already have thought of the merging of try and if, for and while. It would definitely come in handy.
> 
> But I understand from your previous responses that you'd rather use Assembler because it is has no unneeded syntactic sugar. ;-) Just kidding.

You clearly don't understand my precious responses. If you don't see the difference between good syntactic sugar and useless syntactic sugar, then I can't explain to you why Python is better than assembler. :P

>> But maybe some good examples of realistic 3-liners that are significantly improved by the change would convince me (and, more importantly, convince a majority of the others who are skeptical), so I'll keep an open mind.
> 
> From what I can see regarding the if-except proposal, the improvement would be constant. So, either you like it (as I do) or you don't see them as necessary (as you do).
> 
> There is nothing somebody can do to convince you that saving 1 line of code and 1 indentation level across 20 lines of code are good or bad.

So you're refusing to provide examples because you're sure that no examples would convince anyone? In that case, I'm pretty sure your proposal is dead in the water, so I might as well stop responding.



More information about the Python-ideas mailing list