Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subsequent': 0.05; 'nested': 0.07; 'subject:PEP': 0.07; 'exit': 0.09; 'explanation': 0.09; 'function,': 0.09; 'imho.': 0.09; "'break'": 0.16; '(note:': 0.16; '24,': 0.16; 'benjamin': 0.16; 'cleaner': 0.16; 'exceptions,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ignored,': 0.16; 'linear,': 0.16; 'reviewers': 0.16; 'silly': 0.16; 'whatever,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'pointed': 0.19; 'seems': 0.21; '>>>': 0.22; 'programming': 0.22; 'rules': 0.22; 'error': 0.23; 'tend': 0.24; 'mon,': 0.24; "i've": 0.25; 'least': 0.26; 'header :In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'originally': 0.30; 'message- id:@mail.gmail.com': 0.30; '(which': 0.31; 'code': 0.31; 'easier': 0.31; 'that.': 0.31; '(on': 0.31; '25,': 0.31; '>>>>': 0.31; 'continues': 0.31; 'run': 0.32; 'screen': 0.34; 'sense': 0.34; 'maybe': 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'earth': 0.36; 'edge': 0.36; "didn't": 0.36; 'should': 0.36; 'too': 0.37; 'being': 0.38; 'checks': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'heard': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'even': 0.60; 'middle': 0.60; 'subject:? ': 0.60; 'break': 0.61; "you've": 0.63; 'hand': 0.80; 'subject:this': 0.83; '"best': 0.84; '"one': 0.84; 'goto': 0.84; 'promptly': 0.84; 'rusi': 0.91; 'why?': 0.91; 'taught': 0.96; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=76Kb+Q5DWy8asWpC79BhnYFD2kGnxlX5xoH8e35PB+I=; b=Wmjlz7NsweOJqnSOm4MM+CcJmaHYGmeOQHQ7YvT0spj9ywWOl6n0MGN0I5qrCiQgIf IYxzwEzuFi67pvxfduAOiUcekzcb49HJ8FaR10/El6yhAwb+kjgY0XbSEOUrIl4vGTLw tfESpAZWoypEUZIqGbUusgeQkTHcaK7QFrXmCuBdEiL/0Vd77akewJsGqaEOOZLWBjY7 ko3422i9yo1c9YMiMs66XBp998J7J8Y/6uJcQUSvIVKSdb+ptrPjoleAIror9CG7YMvf ADxi1YxaxfNzr7zYtP1AaPOFZCCgXEStHEo85LzwOarABHUpii3BrFfF5ESGFXtJi9v4 q80g== MIME-Version: 1.0 X-Received: by 10.221.4.4 with SMTP id oa4mr13183121vcb.70.1372144895311; Tue, 25 Jun 2013 00:21:35 -0700 (PDT) In-Reply-To: References: <8D03F2B8CF0E7BE-1864-1796B@webmail-m103.sysops.aol.com> <8f813b85-9a4e-4612-82b1-dd58f9bfd497@googlegroups.com> Date: Tue, 25 Jun 2013 17:21:35 +1000 Subject: Re: Is this PEP-able? fwhile From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372144898 news.xs4all.nl 16006 [2001:888:2000:d::a6]:55797 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49133 On Tue, Jun 25, 2013 at 2:20 PM, Benjamin Kaplan wrote: > On Mon, Jun 24, 2013 at 8:54 PM, Chris Angelico wrote: >> On Tue, Jun 25, 2013 at 12:01 PM, rusi 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