Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!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.046 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'statements': 0.09; 'tests,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'cc:name:python list': 0.16; 'pythonistas': 0.16; 'substitute': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'pfxlen:0': 0.19; 'not,': 0.20; 'coding': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'removed.': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; 'assert': 0.31; 'run': 0.32; 'bugs': 0.33; 'guess': 0.33; 'could': 0.34; 'basic': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'impression': 0.36; 'done': 0.36; 'useful': 0.36; 'should': 0.36; 'unit': 0.37; 'nov': 0.38; 'truly': 0.60; 'most': 0.60; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'targeted': 0.69; '"active': 0.84; 'action.': 0.84; 'am.': 0.91; 'passive': 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:to :cc:content-type:content-transfer-encoding; bh=8f4Uvfjpul3L0ys8tIyj7Y1tAXegOXlNDVx1dERKQ4M=; b=dW87nMPVnSNslzkPHpryMBbmx0K3mXKTySEWEXsnsMKArm/nGbrGfqn9Ckd6fjYAxg ftZLs2p+DsM0ExtZ6QTvAEgMIgOP7m22XV+8p3E93y78aB+MhnZ9LxKgPXaUxCtEX5Rp ulpHx/27MfCpI2mOvj8xbf+3C0bjjGr5wLbzz2QRAzElBTG9NBCb2g2VwXH3xwMAStVR bpsCdxZGqcoDeFJZ5ACHD2EYPoOv8uZtYOx9dY1IkXLO9RDuNGmkHBPV82WX8iGIq8VT FmJuPsSjrwM8NqHA0bmY/d0BUzDwpAufVuIwq4Th0IGCmofJgnH9QowGzAoeolQj3Vq9 DxpQ== MIME-Version: 1.0 X-Received: by 10.152.26.226 with SMTP id o2mr39830446lag.50.1415757378573; Tue, 11 Nov 2014 17:56:18 -0800 (PST) In-Reply-To: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> References: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> Date: Tue, 11 Nov 2014 17:56:18 -0800 Subject: Re: I love assert From: Dan Stromberg To: Peter Cacioppi Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Python List 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415757386 news.xs4all.nl 2856 [2001:888:2000:d::a6]:60857 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80585 On Tue, Nov 11, 2014 at 11:40 AM, Peter Cacioppi wrote: > I get the impression that most Pythonistas aren't as habituated with asse= rt statements as I am. Is that just a misimpression on my part? If not, is = there a good reason to assert less with Python than other languages? > > As far as I can tell, Python supports assert perfectly well. When run wit= h the optimization flagging, the asserts are truly removed. > > I think one needs to take care with some basic assert coding - it's not a= substitute for unit tests, it doesn't absolve you of normal exception resp= onsibilities, and, most of all, it should be used for passive inspection an= d not action. But given these guidelines, I still find it very useful as "a= ctive comments". assert is terrific (stops bugs in their tracks), though many things should be done with more targeted exceptions. I guess you could do a survey.