Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74284
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <cameron@cskk.homeip.net> |
| 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; 'operator': 0.03; 'heavily': 0.04; 'float': 0.07; 'plenty': 0.07; 'think,': 0.07; '===': 0.09; '[1,': 0.09; 'chunk': 0.09; 'currently,': 0.09; 'exit': 0.09; 'subtle': 0.09; 'things,': 0.09; 'used.': 0.09; 'python': 0.11; 'thread': 0.14; '"=="': 0.16; '"is"': 0.16; '>on': 0.16; '>the': 0.16; '>to': 0.16; 'behave': 0.16; 'compares': 0.16; 'confuse': 0.16; 'downside': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'nan': 0.16; 'nans': 0.16; 'nans,': 0.16; 'object).': 0.16; 'operator.': 0.16; 'operator;': 0.16; 'ought': 0.16; 'personally,': 0.16; 'pockets': 0.16; 'python",': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simpson': 0.16; 'skip:> 20': 0.16; 'subject:operators': 0.16; 'suite.': 0.16; 'token,': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'discussion': 0.18; 'obviously': 0.18; 'wed,': 0.18; 'differ': 0.19; 'pointed': 0.19; 'memory': 0.22; 'rules': 0.22; 'saying': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'affects': 0.24; 'example.': 0.24; 'cheers,': 0.24; "i've": 0.25; 'define': 0.26; 'nearly': 0.26; 'posts': 0.26; 'suggested': 0.26; 'values': 0.27; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'fixed': 0.29; 'chris': 0.29; "doesn't": 0.30; 'sets': 0.30; "i'm": 0.30; 'work.': 0.31; 'code': 0.31; '"do': 0.31; '(possibly': 0.31; 'context.': 0.31; "d'aprano": 0.31; 'decimal': 0.31; 'equality': 0.31; 'operators': 0.31; 'steven': 0.31; 'types.': 0.31; 'supposed': 0.32; 'another': 0.32; 'up.': 0.33; 'everyone': 0.33; 'running': 0.33; 'cases': 0.33; 'entirely': 0.33; 'plain': 0.33; 'used,': 0.33; 'actual': 0.34; 'moment': 0.34; 'could': 0.34; 'message.': 0.35; 'problem': 0.35; 'agree': 0.35; 'something': 0.35; 'computing': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'data,': 0.36; 'doubt': 0.36; "he's": 0.36; 'received:com.au': 0.36; 'skip:> 10': 0.36; 'doing': 0.36; 'useful': 0.36; 'charset:us-ascii': 0.36; 'similar': 0.36; 'should': 0.36; 'wrong': 0.37; 'real': 0.63; 'skip:n 10': 0.64; 'our': 0.64; 'pick': 0.64; 'more': 0.64; 'different': 0.65; 'articles': 0.65; 'within': 0.65; 'here': 0.66; 'bottom': 0.67; 'magazine': 0.68; 'surrounding': 0.68; 'therefore': 0.72; 'jul': 0.74; 'special': 0.74; 'introduce': 0.78; '_if_': 0.84; 'confusing': 0.84; 'confusion.': 0.84; 'fat': 0.84; 'hanging': 0.84; 'influences': 0.84; 'memories': 0.84; 'proposal.': 0.84; 'proposal:': 0.84; 'radar': 0.84; 'reoccurring': 0.84; 'toy': 0.84; 'wheel': 0.84; 'bloggers.': 0.91; 'subject:Proposal': 0.91 |
| Date | Thu, 10 Jul 2014 09:16:23 +1000 |
| From | Cameron Simpson <cs@zip.com.au> |
| To | python-list@python.org |
| Subject | Re: Proposal: === and !=== operators |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii; format=flowed |
| Content-Disposition | inline |
| In-Reply-To | <53bd08b4$0$2746$c3e8da3$76491128@news.astraweb.com> |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| References | <53bd08b4$0$2746$c3e8da3$76491128@news.astraweb.com> |
| X-Optus-CM-Score | 0 |
| X-Optus-CM-Analysis | v=2.1 cv=eojmkOZX c=1 sm=1 tr=0 a=YuQlxtEQCowy2cfE5kc7TA==:117 a=YuQlxtEQCowy2cfE5kc7TA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=LcaDllckn3IA:10 a=NLW-pn5WY5UA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=kZ7UWmmPAAAA:8 a=HapoENYgfPrSvjZ0QWYA:9 a=CjuIK1q_8ugA:10 a=pyH5b1fOeEsA:10 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11717.1404947787.18130.python-list@python.org> (permalink) |
| Lines | 127 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1404947787 news.xs4all.nl 2956 [2001:888:2000:d::a6]:50670 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:74284 |
Show key headers only | View raw
TL;DR: I've got an alternative proposal at the bottom of this message.
On 09Jul2014 09:17, Steven D'Aprano <steve@pearwood.info> wrote:
>On Wed, 09 Jul 2014 17:21:20 +1000, Chris Angelico wrote:
>> First thought: It will just add confusion. Currently, there are small
>> pockets of confusion surrounding the few cases where something's
>> non-reflexive, and there are occasional threads on the subject, like we
>> have now.
>
>It's a reoccurring issue that keeps coming up over and over again. Most
>people have no need of NANs, and want them to behave like "normal"
>objects. I'm sympathetic to this idea.
But most people also expect float addition to act as though they were Decimals.
I think the real problem here is that "float" is IEEE float and this isn't what
a naive user imagines.
>Whenever this comes up, no-one has suggested any non-reflexive values
>other than NANs, SQL NUL, and "Always Compares Unequal", which I suspect
>is more of a toy than an actual useful example. So there are *very, very*
>few people who actually need NANs.
>
>(But those who do ought to be able to easily get it.)
I agree people should have a noncumbersome way to get particular behaviours.
I have a (possibly ghastly) alternative suggestion, lower down.
>> Adding another pair of equality operators will mean that
>> everyone has to think "Do I want == or ===?",
>
>I don't think so. Nearly everyone will just use ==, those who want ===
>will know they need it.
Um, I disagree. And I also think that === in Python being different to (say)
PHP === or JS === will further confuse things, since they are spelt the same.
At the moment Python has "is", which is very simple in concept, and ==, which
is also conceptually simple (equal values, for the relevant values in the
object). I agree that "is" not implying "==" is confusing when it happens, but
that is only for a few types. Regrettably, float is heavily used.
>> and we just need to look
>> at PHP and ECMAScript to see what happens - people pick the wrong
>> operator and have no end of subtle problems.
>
>People are already having problems, just listen to Anders. He's
>(apparently) not doing NAN-aware computations on his data, he just wants
>to be able to do something like
>
>this_list_of_floats == that_list_of_floats
>
>without NANs screwing it up.
I think Ian Kelly has pointed out that this already works, and that therefore
Andres' problem may be more comoplicated and not fixed by your proposal.
I think, based entirely on my subjective memory of discussion rates on
python-list and doubtless influences by not hanging our in numeric computing
lists, that float not being a plain decimal construct causes more confusion and
surprise.
>But by the same token, if I want to use NANs
>the way they're supposed to be used, I should still be able to use an
>equals operator (rather than a function or method).
>
>> There will be blog posts
>> around saying "always use === in Python", or "never use === in Python",
>
>I doubt that this would even come into the radar of most bloggers.
I have (hazy) memories of seeing plenty of little pseudo-informative magazine
articles discussing this kind of thing for PHP etc. The very presence of the
extra very similar operator spawns clarification articles.
[...]
>> I think this is a big fat YAGNI. The two operators will differ in so few
>> situations that you may as well just define a few cases as "x is y or x
>> == y" instead of creating thew new operator;
>
>But the problem is, most people will need to us "x is y or x == y" nearly
>everywhere! And that doesn't help with containers:
>
>py> alist = [1.0, 2, float('NAN'), 4]
>py> blist = [1, 2.0, float('nan'), 4]
>py> alist is blist or alist == blist
>False
>
>There ought to be a simple way for people to get alist == blist, while
>still allowing IEEE-754 aware code to work.
Ok, here is my alternative proposal: dynamic float behaviour selection.
Consider this code snippet:
with float.behaviour(nan_eq=True):
... code here ...
This sets a thread-local behaviour flag on the entire float type and undoes it
on exit from the context.
This has the following advantages:
- it is very easy to use, and makes plain that this particular chunk of code has special rules
- it makes NaN == behaviour as requested in a particular window
- it can wrap all code called inside the suite
- because it is thread local it doesn't asynchronously affect other running code
- it doesn't introduce a new operator
- it affects a tightly constrainted behaviour, and can obviously be extended to other special cases if they arise
The downside is that it could break code depending on NaN being nonreflexive
_if_ that code is called within the suite.
Personally, I would take this over a new and only-subtly-different-from-==
"===" operator.
Cheers,
Cameron Simpson <cs@zip.com.au>
Check out Doohan's rear/all wheel slide in the French GP. Oh yeah.
"I was just mucking around. I won't do that again." - Mick Doohan
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Proposal: === and !=== operators Steven D'Aprano <steve@pearwood.info> - 2014-07-09 07:00 +0000
Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-09 17:21 +1000
Re: Proposal: === and !=== operators Steven D'Aprano <steve@pearwood.info> - 2014-07-09 09:17 +0000
Re: Proposal: === and !=== operators Rustom Mody <rustompmody@gmail.com> - 2014-07-09 09:20 -0700
Re: Proposal: === and !=== operators Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-09 11:50 -0600
Re: Proposal: === and !=== operators Cameron Simpson <cs@zip.com.au> - 2014-07-10 09:16 +1000
Re: Proposal: === and !=== operators Johannes Bauer <dfnsonfsduifb@gmx.de> - 2014-07-12 13:54 +0200
Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-12 16:35 +0000
Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-13 02:54 +1000
Re: Proposal: === and !=== operators Roy Smith <roy@panix.com> - 2014-07-12 16:39 -0400
Re: Proposal: === and !=== operators Johannes Bauer <dfnsonfsduifb@gmx.de> - 2014-07-12 20:14 +0200
Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-13 09:01 +1000
Re: Proposal: === and !=== operators Roy Smith <roy@panix.com> - 2014-07-12 19:06 -0400
Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-13 09:15 +1000
Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-13 04:48 +0000
Re: Proposal: === and !=== operators Cameron Simpson <cs@zip.com.au> - 2014-07-09 18:17 +1000
Re: Proposal: === and !=== operators Steven D'Aprano <steve@pearwood.info> - 2014-07-09 09:02 +0000
Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-09 19:23 +1000
Re: Proposal: === and !=== operators Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-07-09 05:01 -0700
Re: Proposal: === and !=== operators Roy Smith <roy@panix.com> - 2014-07-09 08:27 -0400
Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-09 12:48 +0000
Re: Proposal: === and !=== operators Tim Chase <python.list@tim.thechases.com> - 2014-07-09 13:05 -0500
Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-10 01:10 +0000
Re: Proposal: === and !=== operators Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-09 12:31 -0600
Re: Proposal: === and !=== operators Roy Smith <roy@panix.com> - 2014-07-09 16:47 -0400
Re: Proposal: === and !=== operators Ethan Furman <ethan@stoneleaf.us> - 2014-07-09 05:43 -0700
Re: Proposal: === and !=== operators Robert Kern <robert.kern@gmail.com> - 2014-07-09 16:27 +0100
Re: Proposal: === and !=== operators Alex Burke <alexjeffburke@gmail.com> - 2014-07-10 18:33 +0200
Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-12 03:30 +0000
Re: Proposal: === and !=== operators Alan Bawden <alan@scooby-doo.csail.mit.edu> - 2014-07-12 01:07 -0400
Re: Proposal: === and !=== operators Torsten Bronger <bronger@physik.rwth-aachen.de> - 2014-07-12 08:05 +0200
Re: Proposal: === and !=== operators Torsten Bronger <bronger@physik.rwth-aachen.de> - 2014-07-12 08:14 +0200
Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-12 16:06 +1000
Re: Proposal: === and !=== operators Ethan Furman <ethan@stoneleaf.us> - 2014-07-11 23:11 -0700
Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-12 16:39 +1000
Re: Proposal: === and !=== operators Marko Rauhamaa <marko@pacujo.net> - 2014-07-12 10:06 +0300
Re: Proposal: === and !=== operators Ethan Furman <ethan@stoneleaf.us> - 2014-07-11 23:53 -0700
Re: Proposal: === and !=== operators Chris Angelico <rosuav@gmail.com> - 2014-07-12 17:25 +1000
Re: Proposal: === and !=== operators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-12 08:33 +0000
csiph-web