Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'needed,': 0.07; 'test,': 0.07; 'dan': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:test': 0.09; 'boolean': 0.16; 'finney': 0.16; 'hint': 0.16; 're-written': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'code.': 0.18; 'options.': 0.19; 'written': 0.21; 'command': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'skip:e 30': 0.24; 'header:X-Complaints-To:1': 0.27; 'testing': 0.29; 'gives': 0.31; 'code': 0.31; 'writes:': 0.31; "we're": 0.32; 'comment': 0.34; "i'd": 0.34; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'false': 0.36; 'leads': 0.36; "i'll": 0.36; 'should': 0.36; 'operating': 0.37; 'ben': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'tracking': 0.61; 'more': 0.64; 'obvious': 0.74; 'yourself': 0.78; 'exclusive': 0.81; 'obvious.': 0.84; 'received:125': 0.84; 'subject::': 0.85; 'bears': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: (test) ? a:b Date: Sun, 26 Oct 2014 10:53:52 +1100 References: <54476af8$0$21651$426a74cc@news.free.fr> <7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com> <7d2ea3c1-504e-4f5c-8338-501b1483df38@googlegroups.com> <878uk6x5nd.fsf@elektro.pacujo.net> <544a1016$0$13000$c3e8da3$5496439d@news.astraweb.com> <544b2f15$0$12978$c3e8da3$5496439d@news.astraweb.com> <85y4s33ml1.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.3 (gnu/linux) Cancel-Lock: sha1:u5ZNI8k8y4Ob+V9efLVjRPrAgkU= 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414281248 news.xs4all.nl 2945 [2001:888:2000:d::a6]:33539 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79692 Dan Stromberg writes: > EG, if I have 3 mutually exclusive command line options, I'll do > something like: > > if option_a + option_b + option_c != 1: > sys.stderr.write('{}: -a, -b and -c are mutually exclusive\n'.format(sys.argv[0])) That is an excellent illustration of why exploiting this accidental property of True and False leads to obfuscated code. The above test gives me no clue that we're operating on boolean values, nor that we're testing for exclusive options. The error message bears no obvious relation to the test, and if I was tracking down that error message I'd have no hint from the code why the test is written that way. An explanatory comment would be needed, but that's a strong sign IMO that instead the test should be re-written to be much more obvious. -- \ “Never express yourself more clearly than you are able to | `\ think.” —Niels Bohr | _o__) | Ben Finney