Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.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.047 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'debug': 0.07; 'run,': 0.09; 'bug': 0.12; 'before.': 0.16; 'buggy': 0.16; 'called,': 0.16; 'called.': 0.16; 'exhibiting.': 0.16; 'inclined': 0.16; 'roy': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'stick': 0.24; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'leave': 0.29; 'on,': 0.29; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'easier': 0.31; 'becoming': 0.31; 'piece': 0.31; 'received:192.168.1.3': 0.31; 'bugs': 0.33; 'not.': 0.33; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'in.': 0.36; 'next': 0.36; "i'll": 0.36; 'should': 0.36; 'so,': 0.37; 'being': 0.38; 'message-id:@gmail.com': 0.38; 'to:addr :python-list': 0.38; 'track': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'remove': 0.60; 'more': 0.64; 'situation': 0.65; 'smith': 0.68; 'behavior': 0.77; 'case?': 0.84; 'one).': 0.84; 'exhibiting': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=VT/PZT0cZDVZ8MgdNLNFXludXnVt1WAIyLa1ofI9zE0=; b=sAilR/EeQtNKQIRGS/c6RTC6C4UuLuQ0Mz8vUb8rutqcK0ouoA1/CA1MvT8phDQO/F mG6Ps6mF17njgS/hbnLjAqEohvepS+bkTO/e85XiHMWRFMtgpTfXZfLq3eXIESDRJ44X gVcTKKd99/M7fyBXAO6UIfCqEA6FwQbxg5imAeJNmbaDe69hfwwcNMidxy+ULwmBJwg+ UnWmrczrZIwH6ImDH+3QSBz57DaMicT/u5Hm5c7vCWnjEYNHeBDg8wqTODbAyoofn7dD 3VII45YiM62Enonz1v13nK2ou2OVgwRVsgIJk2UmBk4Ll++5fZNNCQl0ZPWOxgYb+zRV 3PmA== X-Received: by 10.194.110.138 with SMTP id ia10mr16072781wjb.3.1384762834857; Mon, 18 Nov 2013 00:20:34 -0800 (PST) Date: Mon, 18 Nov 2013 08:20:33 +0000 From: Robert Day User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: When to use assert References: <528871d5$0$29975$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 1384763164 news.xs4all.nl 15897 [2001:888:2000:d::a6]:37088 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59838 On 17/11/13 13:33, Roy Smith wrote: > Every once in a while, I'll get into a situation where something is > happening that I just can't understand. If a given pice of code is > being called, there's NO WAY the program should be exhibiting the > behavior it's exhibiting. But, there's also NO WAY that piece of code > can't be getting called. So, I stick "assert 0" in the code an re-run > the program to see if I get an AssertionError. If I do, then I know > the code is being run. If I don't then I know it's not. Either way, I > know more about what's going on than I did before. Once I know what's > going on, I remove the assert. Are assertions the right thing in that case? I'm becoming more and more inclined to the idea that if you want to know whether code is getting run, you should put a debug log in, and leave it in. That way it's easier to track down the next bug (I don't know about others, but when I write buggy code I go all-out and put lots of bugs in rather than just one). Rob