[Python-ideas] Nudging beginners towards a more accurate mental model for loop else clauses
steve at pearwood.info
Sun Jun 10 14:04:09 CEST 2012
Devin Jeanpierre wrote:
> On Sat, Jun 9, 2012 at 11:03 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> There is no evidence that users somehow get the impression that for/else
>> behaves like try/finally, and I find it completely implausible that they
>> will do so in the future. If I'm wrong, the docs can be revised, but until
>> then, in my opinion worrying about this is a documentation case of YAGNI.
>> The current documentation for for/else is already specific and correct. The
>> real-life problem Nick is trying to solve is that many people think that the
>> else clause implies that it behaves like if/else, and Nick is trying to
>> nudge users to think of try/else instead. I think that's a worthy goal.
>> Worrying about users reading the tutorial and concluding that for/else will
>> run when you exit with a return, not so much.
> You are confused.
Perhaps I am.
> A) I was arguing in favor of the current documentation, written by
> Nick Coghlan. You were arguing in favor of Yuval's thing. You appear
> to have forgotten this, and are now agreeing with me.
The context which has been lost is that Terry Reedy objected to Yuval's
description of for/else. I replied to Terry's objection, disagreeing, and you
replied to me, (apparently) disagreeing with my reply. Do you blame me for
thinking you were agreeing with Terry?
I think that our positions are probably closer than our disagreements might
> B) Obviously there is no empirical evidence for anything, because
> Yuval's thing is unpublished, and the current documentation was added
> two days ago to the dev branch of the docs.
We have anecdotal evidence that many people expect that for/else will execute
the else clause when the for loop is empty.
We have no anecdotal evidence, or any other evidence, that anyone excepts that
the else clause runs if you return out of the loop.
More information about the Python-ideas