Is this PEP-able? fwhile

Chris Angelico rosuav at gmail.com
Tue Jun 25 03:21:35 EDT 2013


On Tue, Jun 25, 2013 at 2:20 PM, Benjamin Kaplan
<benjamin.kaplan at case.edu> wrote:
> On Mon, Jun 24, 2013 at 8:54 PM, Chris Angelico <rosuav at gmail.com> wrote:
>> On Tue, Jun 25, 2013 at 12:01 PM, rusi <rustompmody at gmail.com> wrote:
>>> On Tuesday, June 25, 2013 3:08:57 AM UTC+5:30, Chris Angelico wrote:
>>>> On Tue, Jun 25, 2013 at 5:52 AM,  <> wrote:
>>>>
>>>> > (NOTE:  Many people are being taught to avoid 'break' and 'continue' at all
>>>> > costs...
>>>>
>>>> Why? Why on earth should break/continue be avoided?
>>>
>>> Because breaks and continues are just goto-in-disguise?
>>>
>>> [Well so is while and if and function-call and... Who is to say that?]
>>
>> And that's still not a reason imho. You've just pointed out that
>> they're all control-flow. :)
>>
>> ChrisA
>
> 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 :)

I tend to write code on the principle of "fail and bail" (on finding a
problem, 'return' or goto or break or whatever, rather than indenting
all the subsequent code). It just seems cleaner that way than having
the middle of your function run off the right hand edge of the screen
for no reason :) Also, I consider error checks to be linear, not
nested - if something could fail in three ways, that's three checks
down in parallel, not one check with one check inside it with one
check inside that.

But maybe I just like C and assembly too much :)

ChrisA



More information about the Python-list mailing list