Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Wed, 23 Mar 2016 00:13:48 +1100 Lines: 46 Message-ID: References: <56e44258$0$1598$c3e8da3$5496439d@news.astraweb.com> <8737rvxs89.fsf@elektro.pacujo.net> <56e7483d$0$1608$c3e8da3$5496439d@news.astraweb.com> <56f09973$0$1601$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de 4ugjtQdz/IuLds3aCelW2Q4sL8Oup3JeHWoyvo5IwocA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'classes.': 0.07; 'clause': 0.07; 'exception.': 0.07; 'cc:addr:python-list': 0.09; '22,': 0.09; 'ignoring': 0.09; 'php,': 0.09; 'subject:which': 0.09; 'python': 0.10; 'language,': 0.11; 'exception': 0.13; '11:59': 0.16; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'handle,': 0.16; 'handling.': 0.16; 'macro': 0.16; 'on)': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'vanishingly': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'found,': 0.18; 'language': 0.19; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'first,': 0.20; 'default,': 0.22; 'exceptions': 0.22; 'level,': 0.22; 'libraries': 0.22; 'pass': 0.22; 'bit': 0.23; 'errors': 0.23; 'second': 0.24; 'import': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'figure': 0.27; 'error': 0.27; 'message-id:@mail.gmail.com': 0.27; 'skip:f 40': 0.27; 'function': 0.28; 'crash': 0.29; 'prints': 0.29; 'testing.': 0.29; 'understand,': 0.29; 'raise': 0.29; 'print': 0.30; 'code': 0.30; 'supposed': 0.31; 'certain': 0.31; "can't": 0.32; 'knows': 0.32; '[1]': 0.32; 'though,': 0.32; 'getting': 0.33; 'usually': 0.33; 'tue,': 0.34; 'file': 0.34; 'except': 0.34; 'received:google.com': 0.35; 'ones': 0.35; 'step': 0.36; 'but': 0.36; 'should': 0.36; 'possible.': 0.36; 'received:209.85': 0.36; '(3)': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; '(2)': 0.37; 'received:209': 0.38; '(1)': 0.38; 'end': 0.39; 'means': 0.39; 'does': 0.39; 'called': 0.40; 'some': 0.40; 'your': 0.60; 'subject:The': 0.61; 'skip:u 10': 0.61; 'information': 0.63; 'times': 0.63; 'mar': 0.65; 'fall': 0.66; '"oh,': 0.84; 'chrisa': 0.84; 'console,': 0.84; 'to:none': 0.91 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:cc; bh=oD9hwTZRPIjLNakFBzHNXXaLQ84LYHpE3I7M4HlGzc0=; b=qHLhFVplf/9Gr5dhcL09tBK3SOMQ45J+Qkil1zn4nZG/YBnmMD28Pkn8925gFH8/Qq Wb6CjGK8OJl1YZYsqF3BIQKhxhrQFvpyfuz06xTIyDKz/KlAJceRtmIZ/eAgNRfvLYeo j4ZuOYrV2nXtBKzvQRCh9zaq2FPpSWK+GaAZWAwzR7jMzdU2cj6RUluF68Nr8wIl9PBR fRDwIvDL/sdI3G9wiIxfyCTiO6Na8Bow4tmz9hKemFEcW7egDSe/eR2BjUsRMVuIEbQn fu7igUkIMm8OyW28+Dx6x7e75rS6SUGYd2PElVSYiW4YogMETgJH2J90P8s2OGWEDFeE pIHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=oD9hwTZRPIjLNakFBzHNXXaLQ84LYHpE3I7M4HlGzc0=; b=mvQc6YMrdPuWQHqK+e37v2GXwIR0l97dZXzAvNcvKQ6fla3g0sszx60E19rR+5h5GJ F6+Fzj2cMxXnAkSsD0D7ScXDOLID6zbi671dsnMoOxCtopsq0g2sQI69g2cA6/aqchyM O5DmBylDGbMGPMa5vRFsZ2a/0zznFBcntJHXX1fbEwhxECXb3iZzFsImb03tCoMtBBT8 UPo14sd7paNgFNSXTxGW9RJZd/h37anFjOUI1XNxpo8/mCNJtYmDyN7KnTeuB7bD+anA ovlAwQtJzCohd7q2/9+BfdFKUHpQYY0qBtdmW9V90NU7If6JoFemhWUdlko/PSRiP3PF rHhw== X-Gm-Message-State: AD7BkJLlB9jKOylCn1+1rSpxKPyazUL+KQvPS6LvVtq1AEqeDwHukbQ2bqPsdhRHTgLrYv5yodCB6Iccm8UPng== X-Received: by 10.112.130.74 with SMTP id oc10mr5077915lbb.14.1458652428436; Tue, 22 Mar 2016 06:13:48 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105479 On Tue, Mar 22, 2016 at 11:59 PM, BartC wrote: > (1) Not bother with exceptions at all inside the function > > (2) Not bother with them in the user code either > > (3) Let any errors just crash out (raise a Python system error) (just like I > did in my original jpeg program which I was called out on) > > (4) Or if the user code does want to check for certain errors (like, File > Not Found, by far the most likely, and so that it can deal with that and > continue executing), it now has to go and dig out docs for ... what? The > user code needs to know what is going on inside the supposedly opaque > function it's calling. Yes, yes, at first, and try it. The first step in any program is to write it in the very simplest way possible. That usually means ignoring all error handling. And yes, this is true in EVERY language - C, PHP, Pike, DeScribe Macro Language, you name it. Then you try it, and you find one of two things: 1) The code you've written is encountering error conditions that it can't handle, and has to pass upstream; or 2) The code you've written is getting passed error conditions that it knows how to deal with. The first one is a time to raise an exception. The second is a time to catch one. And since, by default, Python prints those exceptions to the console, you should [1] have all the information you need to catch the ones you understand, because you've seen them in testing. Note, though, that "deal with" really means "deal with", and NOT "print oops to the console and terminate". If all you're going to do with an exception is print and terminate, *let it go*, unless it's a user-triggered failure, in which case you catch it right at the very highest level, and basically fall off the end of your program. The number of times you have sys.exit() in an except clause should be vanishingly small. ChrisA [1] Some libraries force you to dig around a bit to figure out how you're supposed to import those exception classes. But that's usually *one* thing to look up in the docs - "oh, so I import foobarbletch.exceptions.OutOfBeerException".