[Python-ideas] breaking out of module execution

Ronald Oussoren ronaldoussoren at mac.com
Wed Apr 25 14:37:56 CEST 2012

On 25 Apr, 2012, at 14:11, Mark Shannon wrote:

> Steven D'Aprano wrote:
> [snip]
>> Unless you address the disadvantages and costs of top level return, you won't convince me, and I doubt you will convince many others.
> What costs?

Harder to understand code is one disadvantage. The "return" that ends execution can easily be hidden in a list of definitions, such as

... some definitions ...

if sys.platform != 'win32': return

... more definitions for win32 specific functionality ...

That's easy to read with a 10 line module, but not when the module gets significantly larger.

Also, why use the proposed module-scope return instead of an if-statement with nested definitions, this works just fine:

: def foo(): pass
: if sys.platform == 'linux':
:    def linux_bar(): pass

> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4788 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120425/9f65dd8f/attachment.bin>

More information about the Python-ideas mailing list