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 09:23:12 +1100 Lines: 37 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> <56F1A071.1000506@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de zVQk9V40BJeE0ONyq3Zu7wJ3wxON6fOSByUqMI2NsvLg== 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; 'raises': 0.07; 'cc:addr:python-list': 0.09; 'appropriate.': 0.09; 'argument,': 0.09; 'deletion': 0.09; 'raised,': 0.09; 'subject:which': 0.09; 'wrong,': 0.09; 'python': 0.10; 'exception': 0.13; 'appropriate': 0.14; 'wed,': 0.15; 'explicitly': 0.15; '2016': 0.16; '23,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imo.': 0.16; 'invalid.': 0.16; 'name).': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'wrote:': 0.16; 'deleted.': 0.18; 'found,': 0.18; "shouldn't": 0.18; 'why.': 0.18; 'library': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'java': 0.22; 'exceptions': 0.22; 'am,': 0.23; 'errors': 0.23; "python's": 0.23; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'error': 0.27; 'arising': 0.27; 'message-id:@mail.gmail.com': 0.27; 'disk': 0.27; 'tend': 0.27; 'function': 0.28; 'exists,': 0.29; 'raise': 0.29; 'classes': 0.30; "we're": 0.30; 'code': 0.30; 'checks': 0.30; 'certain': 0.31; "can't": 0.32; 'says': 0.32; 'michael': 0.33; 'impression': 0.33; 'suddenly': 0.33; 'open': 0.33; 'file': 0.34; 'this?': 0.34; 'that,': 0.34; 'list': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'could': 0.35; 'done': 0.35; 'attempt': 0.35; 'library.': 0.35; 'something': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'things': 0.38; 'itself': 0.38; 'received:209': 0.38; 'does': 0.39; 'where': 0.40; 'some': 0.40; 'your': 0.60; 'subject:The': 0.61; 'times': 0.63; 'mar': 0.65; 'soon': 0.65; 'remember,': 0.66; 'talking': 0.67; 'worth': 0.67; 'chrisa': 0.84; 'enforces': 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=NB1h0CTcHK5ZmeD/yrfdGKKQKEwuC81SZQHZlhTBD6M=; b=qbhbQHagjvym8iVejuGjYvq+zhhTAHJfXBHMLeGlMJ6l4/L94CBdqYXYTOCNsbnlzl H6sFViUhG4bkVoxEZ2S1I7mAPPLtQX3KJin8vc68kA4z1B0pHoGAcrqBXx8zAZ4AuJUw IxvpgrjzlOfxxAF7y1R5T8ziNDNwDJKRcY0XVVgFO2GXjEFHzXVTJqEg1lsXO8QUFtWw Kg8vpLzQbhS4+Y1ZSErLNPyRzqTaTNDsE/tzW1UdVSrbX7I52lieLwMQYcr7OKm637yL 3nBgnYbeUXb7p5L1BKTzxQlUn5DxIKrmY6YzE0VRMH5v8gu54mrIr1EZNsZohTbS5wJr G9lg== 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=NB1h0CTcHK5ZmeD/yrfdGKKQKEwuC81SZQHZlhTBD6M=; b=kjKDKrX3UKrdD1EwQn30oXMAZcsPihhLa5nWlOz4avXHQVW3xCeym5kYM2sHtmPtn7 EIqSQjFpB6Px/F3BUcZHnTf2VyuVk5O7EzBjXYJDiPqY3MMKg72XNKGQ0Y6JH4BXnr37 nBjWaUUk6lwIu5/9unliUIJ+MP3gPcuSk8y0tdSd6HeGex5tQ79E2GDU5apoNNrIr4nW GzpG8X4+G+7yrug8v4ssQ4xl76WBD1kbqOeNODPEEBeN1ern4DuZmS70wcvwyKSUeKro qJ9QaCrqeyXptxaq7ShE0///1C4G+Cxs5mpcyWGiWIcabEG2dXA4dyRo+/pAPwd8BzAS u0kQ== X-Gm-Message-State: AD7BkJLlpYMiJnfmAvh4Hh9eqTJXdncT077FIzJJsWL8+JtjHMvKKD38Hy8Yiu+hpi+XuHM+lk8QZH427vMKDg== X-Received: by 10.25.156.196 with SMTP id f187mr14317049lfe.150.1458685392697; Tue, 22 Mar 2016 15:23:12 -0700 (PDT) In-Reply-To: <56F1A071.1000506@gmail.com> 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:105503 On Wed, Mar 23, 2016 at 6:43 AM, Michael Torrie wrote: > And despite the impression you may have gotten, it is appropriate to > look before you leap. Using os.exists() and other pre-flight checks are > appropriate. Hmm, can you justify this? Remember, as soon as any other process has done anything, your LBYL is invalid. You check that the file exists, then it gets deleted. Or you check that it doesn't, and bam, suddenly it does. The only way to be certain is to do an operation that enforces it on the hard disk itself - either open the file (after that, deletion can't affect you - on some OSes, deletion can't happen), or create it and hold it open exclusively (nobody else can create a file with that name). >> (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. > > Good documentation should describe exactly what exceptions a function or > library raises and why. I tend to try to follow the example of Python's > standard library. I keep my exception classes few, and raise a good > error message with it. > > But often times the exceptions we're talking about are standard Python > exceptions arising from things like I/O, not custom library classes. If you have documentation like this, it should list only the exceptions that you explicitly raise, not those that can bubble up through it - this is where Java gets it wrong, IMO. If you attempt to read from a file that gets passed in as an argument, AttributeError could get raised, but you shouldn't document that; but if you have a line of code that says "raise InconsistentDNSRecordError", then yes, that's something worth documenting. ChrisA