Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'algorithm': 0.04; 'explicitly': 0.05; 'true,': 0.05; 'defaults': 0.07; 'nicely': 0.07; 'plenty': 0.07; 'socket': 0.07; 'string': 0.09; '"if': 0.09; 'false,': 0.09; 'false.': 0.09; 'parameter': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; '(assuming': 0.16; 'acted': 0.16; 'advocating': 0.16; 'containers': 0.16; 'establish,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'merely': 0.16; 'none.': 0.16; 'omitted,': 0.16; 'opposite': 0.16; 'optional': 0.16; 'similarly,': 0.16; 'tables,': 0.16; 'throw': 0.16; 'which,': 0.16; 'wished': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'bit': 0.19; "python's": 0.19; 'entered': 0.20; 'not,': 0.20; 'previously': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'comparing': 0.24; 'instance,': 0.24; 'logical': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; "i've": 0.25; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; "d'aprano": 0.31; 'name;': 0.31; 'steven': 0.31; 'quite': 0.32; 'fri,': 0.33; 'sense': 0.34; "i'd": 0.34; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'consistent': 0.36; 'object,': 0.36; 'doing': 0.36; 'being': 0.38; 'arrange': 0.38; 'depends': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'either': 0.39; 'ensure': 0.60; 'matter': 0.61; 'providing': 0.61; "you're": 0.61; 'times': 0.62; 'making': 0.63; 'name': 0.63; 'such': 0.63; 'myself': 0.63; 'situation': 0.65; 'between': 0.67; 'obvious': 0.74; '2015': 0.84; 'distinguish': 0.84; 'lately,': 0.84; 'to:none': 0.92 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:cc :content-type; bh=lX7bYBX4TONkVwYVNZF7EbasUHB/qbpFcAxeQIvESoc=; b=GCsUhTmx01VL3gaTAeSwS833GyoyGux7TwQXZ0R68YRgkIj8AbAlTOpkbW9PazLobf 4jtXw3Cf9OFY7A+7nhE6PLd9F/go+yIfpHmOdsps9lnLRve/J64SOPJErA5mPooCzLy2 +YH00FlAh+nuji7N3tyKRfxSZE08/LkJyIwT5B8zFEUpY1y+4F+DwKDNTqtrIwAtE7w0 tnzMxVn0tTSHim9fgt8hqTv1l4sIgcY3rPizPV6LENoNvmDFVllAfImSvzG7fAPIyXKi GtaIQKcTw2zuFYS05WIsCat5u/u01rKtcIdc/Kx55Mpsm1daRyHE2hIGs0jMHpE2fCIf tWIQ== MIME-Version: 1.0 X-Received: by 10.42.94.14 with SMTP id z14mr12448824icm.59.1420807422601; Fri, 09 Jan 2015 04:43:42 -0800 (PST) In-Reply-To: <54afc949$0$12985$c3e8da3$5496439d@news.astraweb.com> References: <54ABB88A.7070504@r3dsolutions.com> <54ABC52A.1050507@davea.name> <54ABE383.3020801@r3dsolutions.com> <54ABEAD9.8070000@davea.name> <54ace9f0$0$2738$c3e8da3$76491128@news.astraweb.com> <87tx02gb9d.fsf@elektro.pacujo.net> <54adc53c$0$12999$c3e8da3$5496439d@news.astraweb.com> <877fwx3i8f.fsf@elektro.pacujo.net> <54afc949$0$12985$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 9 Jan 2015 23:43:42 +1100 Subject: Re: Comparisons and sorting of a numeric class.... From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1420807429 news.xs4all.nl 2887 [2001:888:2000:d::a6]:52735 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83437 On Fri, Jan 9, 2015 at 11:27 PM, Steven D'Aprano wrote: > Chris Kaynor wrote: > >> Lately, I've been doing quite a bit of work in lua, and many times have >> wished that empty strings, tables, and 0 acted "falsey", but at the same >> time, previously working in Python, there were plenty of times I wished >> they acted "truthy". It merely depends on what algorithm I am using at the >> time... > > > Please do elaborate. I've never found myself in a situation where I have > wanted empty containers to be truthy, and I can't think of what such a > situation would be like. It's a matter of what you're comparing against. If you might have a thing and might not, the obvious way to arrange things is to have the thing be true and the non-thing be false. That works nicely if that "thing" is an object that's always True, and the "non-thing" is None; for instance, I might have a socket object, and I might not, so I can use "if not self.socket: self.connect()" to ensure that I have one (assuming that self.connect() will throw an error if it fails to establish, blah blah, handwave away the details). This does NOT work if a socket object might be false, so I'd have to explicitly check "if self.socket is None:". Similarly, there are times when the user might have entered a string or might not - say you have an optional parameter "--name" which, if omitted, defaults to some sort of arbitrarily-assigned name; to distinguish between "--name=" and not providing that parameter at all, the logical way is to have name be either a string or None. Again, "if name" would make good sense as meaning "if the --name parameter was provided", rather than "if the --name parameter was provided and not the empty string". If it helps, think of a "nullable field" in databasing. Python's truthiness model is pretty consistent (apart from a few oddities like midnight being false), so I'm not advocating making this change. I'm just explaining the case where the opposite choice does make sense. ChrisA