Goto (Posting On Python-List Prohibited)

Chris Angelico rosuav at gmail.com
Mon Jan 1 16:34:45 EST 2018


On Tue, Jan 2, 2018 at 7:16 AM, Chris Green <cl at isbd.net> wrote:
> Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>>
>>         Well... "break" does bypass the rest of the block, but it still exits
>> via the end of the block. I have a tendency to try for one "return" per
>> procedure (so I'm more likely to have an "if ...: break" then "if ...:
>> return").
>
> I have always tried to enforce 'only one return per function'.  If
> there are multiple returns it makes maintenance very difficult as
> 'clear up' code can get bypassed.
>

Isn't that why try/finally exists? No matter how many 'return'
statements you have, there's always exceptions to bypass any naive
cleanup code; and no matter how many returns you have, 'finally'
blocks still execute before return.

ChrisA



More information about the Python-list mailing list