On Tue, Jun 25, 2013 at 1:21 AM, Chris Angelico <ros...@gmail.com> wrote: > On Tue, Jun 25, 2013 at 2:20 PM, Benjamin Kaplan > <benjamin.kap...@case.edu> wrote: >> The reason I was given (which I promptly ignored, of course) is that >> it's "best practice" to only have one exit point for a block of code. >> Only one way of terminating your loop, only one "return" per function, >> never use exceptions, etc. I think it originally came about as a way >> to make sure that your clean-up code was called (and to make it easier >> for code reviewers to make sure your clean up code was called) and >> then started being passed around as a rule among programming teachers >> who didn't have any experience outside the classroom. > > I've heard that "one exit point" rule before, too, but never any > justification for it. Your explanation does at least make sense > (albeit only in a language without even RAII), but I don't like silly > rules like that :)
In my experience the sorts of people who preach "one exit point" are also all about defining preconditions and postconditions and proving that the postconditions follow from the preconditions. I think that the two are linked, because the "one exit point" rule makes those sorts of proofs simpler. -- http://mail.python.org/mailman/listinfo/python-list