Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.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.025 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'true,': 0.05; 'subject:Python': 0.06; 'indicating': 0.07; 'level,': 0.07; 'defines': 0.09; 'exit': 0.09; 'false.': 0.09; 'finney': 0.16; 'processes.': 0.16; 'unix,': 0.16; 'wrote:': 0.18; 'command': 0.22; 'machine': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; "shouldn't": 0.24; '(or': 0.24; 'script': 0.25; 'defined': 0.27; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'unix': 0.29; 'asked': 0.31; 'though.': 0.31; 'probably': 0.32; 'critical': 0.32; 'know.': 0.32; 'running': 0.33; 'older': 0.33; 'but': 0.35; 'there': 0.35; 'false': 0.36; 'similar': 0.36; 'error.': 0.37; 'level': 0.37; 'ben': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'even': 0.60; 'tell': 0.60; 'mentioned': 0.61; 'success': 0.61; 'further': 0.61; 'more': 0.64; '2015': 0.84; 'answer:': 0.84; 'borrow': 0.84; 'received:btcentralplus.com': 0.84; 'subject:Practices': 0.84; 'received:86': 0.91 User-Agent: Kaiten Mail In-Reply-To: <85zj814jmb.fsf@benfinney.id.au> References: <85bnkh5z96.fsf@benfinney.id.au> <85zj814jmb.fsf@benfinney.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Subject: Re: Python Worst Practices From: Simon Ward Date: Thu, 26 Feb 2015 20:10:28 +0000 To: python-list@python.org X-Spam-Flag: NO X-Spam-Score: -2.9 X-Spam-Level: -- X-Spam-Report: No, score=-2.9 required=5.0 tests=ALL_TRUSTED, BAYES_00 autolearn=ham version=3.3.2 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424981447 news.xs4all.nl 2869 [2001:888:2000:d::a6]:47231 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86541 On 26 February 2015 00:11:24 GMT+00:00, Ben Finney wrote: >> Yes, but my point is: You shouldn't need to rebind those names (or >> have names "true" and "false" for 0 and 1). > >That's not what you asked, though. You asked “When would 0 mean true >and >1 mean false?” My answer: in all Unix shell contexts. > >> Instead, use "success" and "failure". > >You'd better borrow the time machine and tell the creators of Unix. The >meme is already established for decades now. 0 = success and non-zero = failure is the meme established, rather than 0 = true, non-zero = false. It's not just used by UNIX, and is not necessarily defined by the shell either (bash was mentioned elsewhere in the thread). There is probably a system that pre-dates UNIX that I uses/used this too, but I don't know. C stdlib defines EXIT_SUCCESS = 0, yet C99 stdbool.h defines false = 0. That shells handle 0 as true and non-zero as false probably stems from this (or similar in older languages). The " true" command is defined to have an exit status of 0, and "false" an exit status of 1. The value is better thought of an error level, where 0 is no error and non-zero is some error. The AmigaOS shell conventionally takes this further with higher values indicating more critical errors, there's even a "failat N" command that means exit the script if the error level is higher than N. None of the above is a good reason to use error *or* success return values in Python--use exceptions!--but may be encountered when running other processes. Simon