Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'args': 0.07; 'debug': 0.07; 'debugging': 0.07; 'plenty': 0.07; '#define': 0.09; '#endif': 0.09; 'code"': 0.09; 'worse': 0.09; 'cc:addr:python- list': 0.11; '#else': 0.16; '#ifdef': 0.16; 'evaluated.': 0.16; 'finney': 0.16; 'foo,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'materially': 0.16; 'mode,': 0.16; 'no-op,': 0.16; 'projects:': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; "i've": 0.25; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'this.': 0.32; 'maybe': 0.34; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'sometimes': 0.38; 'ben': 0.38; 'nov': 0.38; 'rather': 0.38; '12,': 0.39; "you're": 0.61; 'further': 0.61; 'here:': 0.62; 'kind': 0.63; 'different': 0.65; 'to,': 0.72; '"active': 0.84; 'to:none': 0.92 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 :content-type:content-transfer-encoding; bh=eqNnVCRNpCo94XpAixdVYXPUT3V2+S8L79OTRQcubyc=; b=G49R3pOUGXrdEwwFJNzrQLGlbmjj8+TGJmXG/Sp3jaT5MLYj1XZlnc9JFIn8izo122 SbWHXoZoJjI08+9alcuN7wOGZM5gA2C+uhYO1h8/uj8NvUvYN7jGFOpXl1zYQhYpTKpS Hh/1HSi6R46ggFfqWOPsrikxpXMSS7VYwjkR47IIoByqwD6aMXjq0WLAiX+/OfxBcd1H u9COfHiS1UyPK62eGZlnvsKpH96MuXtbqwDZOwpNeeQOQqb79ENCgWr3oVI4LBlGZXCY medv3pBZmE7aoPd14o4sxeYVnSjTsa7gKITgkwLz8St8uqHyCYjP5WigltzOw9TdyvqM jCnQ== MIME-Version: 1.0 X-Received: by 10.50.136.133 with SMTP id qa5mr37028595igb.2.1415758903020; Tue, 11 Nov 2014 18:21:43 -0800 (PST) In-Reply-To: <85389pcxn5.fsf@benfinney.id.au> References: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> <85389pcxn5.fsf@benfinney.id.au> Date: Wed, 12 Nov 2014 13:21:42 +1100 Subject: Re: I love assert From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415758912 news.xs4all.nl 2881 [2001:888:2000:d::a6]:35732 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80586 On Wed, Nov 12, 2014 at 7:03 AM, Ben Finney wr= ote: > An =E2=80=98assert=E2=80=99 statement in the code will sometimes be activ= e, 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. I've seen this kind of thing in plenty of C projects: #ifdef DEBUG_MODE #define DEBUG print #else #define DEBUG(...) #endif ... further down ... DEBUG("We're here: %d:%d", foo, bar); If you're not in debug mode, this won't be evaluated. You can have "active code" inside its args if you want to, but only if it's exclusively part of the debugging output: DEBUG("We've hit this line %d times", ++hitcount); Again, not materially different from assert, and plenty of projects have this. Maybe people just need to understand "assert =3D=3D DEBUG" and all's clear? ChrisA