Path: csiph.com!usenet.pasdenom.info!gegeweb.org!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'debug': 0.07; 'modified': 0.07; 'tool,': 0.07; 'enabled,': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'pgp': 0.09; 'python:': 0.09; '~ethan~': 0.09; "wouldn't": 0.14; '(gnu/linux)': 0.16; '----- begin': 0.16; '-----end': 0.16; 'bugs.': 0.16; 'gnupg': 0.16; 'hash:': 0.16; 'reminded': 0.16; 'sha1': 0.16; 'skip:0 60': 0.16; 'skip:d 60': 0.16; 'two,': 0.16; 'wrote:': 0.18; 'message-----': 0.19; 'normally': 0.19; 'skip:a 60': 0.19; 'written,': 0.19; 'written': 0.21; 'example': 0.22; 'programming': 0.22; 'tests': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; '(or': 0.24; 'second': 0.26; 'signed': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'correct': 0.29; 'on,': 0.29; 'am,': 0.29; 'code': 0.31; 'assert': 0.31; "d'aprano": 0.31; 'disabled': 0.31; 'skip:i 60': 0.31; 'steven': 0.31; 'run': 0.32; 'running': 0.33; 'agree': 0.35; 'test': 0.35; 'but': 0.35; 'tech': 0.36; 'version:': 0.36; 'charset:us-ascii': 0.36; 'similar': 0.36; 'url:org': 0.36; 'easily': 0.37; 'star': 0.38; 'handle': 0.38; 'to:addr:python- list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'space': 0.40; 'release': 0.40; 'new': 0.61; 'received:173': 0.61; 'course': 0.61; "you're": 0.61; 'here:': 0.62; 'save': 0.62; 'different': 0.65; 'unusual': 0.74; 'defensive': 0.84; 'episode': 0.84; 'fail.': 0.84; 'fails,': 0.84; 'remembering': 0.84; 'skip:4 60': 0.84; 'skip:w 60': 0.84; 'url:676': 0.84 Date: Fri, 14 Nov 2014 10:18:27 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: I love assert References: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> <87a93wqeq3.fsf@elektro.pacujo.net> <5465e887$0$12976$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <5465e887$0$12976$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit 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: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415989114 news.xs4all.nl 2833 [2001:888:2000:d::a6]:34782 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80777 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 11/14/2014 03:33 AM, Steven D'Aprano wrote: > > I agree with Marko in this case. Marko's example of defensive programming is very similar to the one I gave in my > essay here: > > http://import-that.dreamwidth.org/676.html > > You're correct of course that under the circumstances you describe the code will fail. But that is no different > from the scenario: > > "a new status is added, the code is not modified to handle it, no tests are written to check the code is correct > (or if the tests are written, the test suite is not run), and then the code is released at which point it fails" I am reminded of a Star Treck episode (Deep Space 9?) in which a Klingon is mocking the Federation tech for having three backups, instead of only two, to which the Federation tech replies, "When the second one fails, I wouldn't want to be without my tertiary backup!" My point being: a safety net that is so easily disabled does not count (IMHO) as a backup. > If your process is so poor that you release code without running it with asserts enabled, then assert will not save > you from bugs. This is one my very few complaints about Python: running it normally is the same as running with DEBUG turned on, so the unusual case is remembering to run with asserts turned /off/. > Assertions are just a tool, not a panacea. Right -- and using it is like using a rock when what you need is a ball-peen hammer. ;) - -- ~Ethan~ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJUZkdzAAoJENZ7D1rrH75Nl9YQALx9UIAxYzlzH04EoMlILErb 0wz5xNhTM2JmF3csJPi3pQSpEr1XpHhWjFZYsFoPB24I8bN7tGALb91+ME7ElHgw WP6Z+AVPuHCRxTG/oteK72+f5S+SN6zV1ECwrUuWxqIt5CHzYFtQjRKvEinNDtaT xKtEfYZdrZFeqo7ssV2gHprDd1QFIAygLMbIlwke6nT/TdMGmw/wG9LQtpfSnrQc 4BeFoeYM3OL+hxHUNfYJI9cGL7skykU3EHnuFqNbhA6QhGawvBqUhVDGoFFDkJ/e AX6AGk5Fu9cvjEFTzRQJzW4S5s6nD4dYM7Z93GfD9G9KBmfzQNM1pBA3yqxf0S8Q CWTWBs8pPkYe/G1Y/WOn7lzYQdMneIGUNnHR8fnABKPPf5IeTXabkWgtVnq1g5Ty DVcg/47G8gBMOTz5DD08iigu4f2bsNGowFoAkCDsbNmzjmxODGSUoj1ph/4xg6HP HbuEQZXwNZXmlP9ZcLoxjCKdBdRJo3JZ4hAf6kVj4VT4y438GL2dI0/KIUSDWgYE B0mCsQ7WYm80AvfpYR7fJoZsd/5jXe7RCLHanNLIZff3LupdFZri5E246KloUBj+ 3Jw3HgwME6wyDshiHtsS5tuDcANvow+PICA+wn2KmU9Mn2JNwsG3D98ZFJfXp0JR eG/Pg7cgQhrjhFqe6cgO =EoEX -----END PGP SIGNATURE-----