return in loop for ?

Neil Hodgson nyamatongwe+thunder at gmail.com
Thu Nov 24 05:10:09 EST 2005


Steve Holden:

> What are the claimed advantages for a single exit point? I'd have 
> thought it was pretty obvious the eight-line version you gave is far 
> more likely to contain errors than Mike's three-line version, wouldn't 
> you agree?

    Single exit point is an ancient Dijkstraism. It was one of the 
constraints that were thought to be useful in the early days of 
structured programming. Having function flow always terminate at the end 
of the function does make analysis simpler. It helps with, for example, 
managing resource lifetimes: its easy to forget to release something 
when you add a return statement.

    Yes, the rule has obvious shortcomings, but OTOH if it had enabled 
reasonable formal verification...

http://en.wikipedia.org/wiki/Structured_programming#Multiple_points_of_exit

    Neil



More information about the Python-list mailing list