Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'explicitly': 0.05; 'debugging': 0.07; 'plenty': 0.07; 'session.': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'will,': 0.09; 'worse': 0.09; 'python': 0.11; 'language.': 0.14; 'finney': 0.16; 'imo,': 0.16; 'materially': 0.16; 'no-op,': 0.16; 'preserve': 0.16; 'rather,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'unexpected': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'small,': 0.19; 'code,': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; 'statement': 0.30; 'code': 0.31; 'software,': 0.31; 'argue': 0.31; 'clever': 0.31; 'implied': 0.31; 'writes:': 0.31; 'this.': 0.32; 'languages': 0.32; 'says': 0.33; 'maybe': 0.34; "i'd": 0.34; 'but': 0.35; 'opposed': 0.36; 'should': 0.36; 'sometimes': 0.38; 'ben': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'does': 0.39; '12,': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'valuable': 0.63; 'our': 0.64; 'more': 0.64; 'different': 0.65; 'stated': 0.69; 'secure': 0.71; 'industry': 0.73; 'glad': 0.83; 'drm': 0.84; 'expressive': 0.84; 'received:125': 0.84; 'reminders': 0.84; 'treating': 0.84; 'trick,': 0.84; 'favour': 0.91; '\xe2\x80\x9cthe': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: I love assert Date: Wed, 12 Nov 2014 13:35:53 +1100 References: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> <85389pcxn5.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:n6oQcBf1XdooaisTKewm/A4+xRo= 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415759768 news.xs4all.nl 2843 [2001:888:2000:d::a6]:41084 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 2150588492 X-Received-Bytes: 5137 Xref: csiph.com comp.lang.python:80588 Chris Angelico writes: > On Wed, Nov 12, 2014 at 7:03 AM, Ben Finney wrote: > > An ‘assert’ statement in the code will sometimes be active, and > > sometimes be a no-op, for *exactly* the same code under different > > circumstances. That's a trap for the reader, and I'd rather not set > > it. > > This is no worse than other forms of preprocessor magic. That other languages do it doesn't argue in favour of it. It argues, rather, that we should be glad not to have it in our Python code. > Again, not materially different from assert, and plenty of projects > have this. Maybe people just need to understand "assert == DEBUG" and > all's clear? The more things people need to keep in mind when reading my code that isn't stated explicitly in the code, the worse I consider the code to be. Python is a small, clear, expressive language. It has the valuable property that one does not need to keep in mind a lot of reminders of unexpected behaviour; good Python code behaves as it explicitly says it will, with very few implied surprises. To preserve this valuable but fragile property, I recommend treating ‘assert’ as a clever but obfuscatory trick, opposed to that property of Python. So an ‘assert’ statement should, IMO, not remain in the code past a debugging session. -- \ “The entertainment industry calls DRM "security" software, | `\ because it makes them secure from their customers.” —Cory | _o__) Doctorow, 2014-02-05 | Ben Finney