Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'charset:iso-8859-7': 0.04; 'static': 0.04; '(even': 0.05; 'nasty': 0.07; 'variables': 0.07; '"if': 0.09; 'operator,': 0.09; 'mostly': 0.14; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'incremented': 0.16; 'loop.': 0.16; 'order?': 0.16; 'sane': 0.16; 'shalt': 0.16; 'tradition': 0.16; 'elements': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'normally': 0.19; 'thu,': 0.19; 'programming': 0.22; 'putting': 0.22; 'saying': 0.22; 'comparing': 0.24; 'earlier': 0.24; 'sort': 0.25; 'compare': 0.26; 'switch': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'wondering': 0.29; 'possibility': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; '25,': 0.31; 'comparison': 0.31; 'constant': 0.31; 'there,': 0.34; "i'd": 0.34; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; "didn't": 0.36; 'received:209': 0.37; 'performance': 0.37; 'being': 0.38; 'convention': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'most': 0.60; "you're": 0.61; 'first': 0.61; 'term': 0.63; 'kind': 0.63; 'such': 0.63; 'situation': 0.65; 'treating': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=dBGoVy1pbbsUmL4T5DF2kW0+0xlqIDPSUeyt2TvU4JI=; b=U1DS2pQuPEVYFqU1lCkHjcpYQ8pahraSnvcrto2RXsN0dhYALC2sZPCplU9jp4DuUF 8pz6cyTYmWPZLORgVwH3eN+EoIsnCmSqKYqvcq0JT0YCqDWcJxpca7fI+FIcZqgjFPMZ Yc0mdO60Nhvf3+Jv8morJp0RJD19XZH2mCAHIV6bW2vq+75EZV1qrXN+m9YV1r0VVcyt bTctfYIKp1DFPTlxXLmI0TFYEN9dk+Y/c4HCWk9Dr/UyoamVV+AN2lsImL3ZkhDX7mNV tsg1hK2qs/ru8/ua5TO3Z6ZZ5LkJ1S1ATtpM5B1d00aBmdL+JuFH2HA7AekBSXwkd4B4 K1OQ== MIME-Version: 1.0 X-Received: by 10.58.15.193 with SMTP id z1mr26612259vec.40.1366869469071; Wed, 24 Apr 2013 22:57:49 -0700 (PDT) In-Reply-To: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> Date: Thu, 25 Apr 2013 15:57:49 +1000 Subject: Re: Comparison Style From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366869477 news.xs4all.nl 15986 [2001:888:2000:d::a6]:50534 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44323 On Thu, Apr 25, 2013 at 3:49 PM, llanitedave wrote= : > Given that > > s =3D some static value > i =3D a value incremented during a loop > > I'm used to comparing them as > > if i =3D=3D s: > # some code > > But for some unknown reason I did a switch > > if s =3D=3D i: > # same code > > It didn't seem to make any difference at first glance, so I just got to w= ondering -- It won't make any difference in any sort of sane code. If there's any situation in which =3D=3D is not reflexive, something seriously nasty is going on. > Is there a standard for comparison order? Is there any kind of performan= ce difference? Is there even a tradition for one or the other? Are there = any gotchas? It's conventional to compare variables to constants, not constants to variables (even in C where there's the possibility of mucking up the operator, most people still compare variables to constants). I'd normally use "i =3D=3D s" there, treating s as a constant for the purpose of the loop. Unless you're deliberately being poetical, language such as "Three is the number thou shalt count" is distinctly abnormal, so saying "if (5 =3D=3D i)" is equally awkward. It's nothing major; mostly it's like the algebraic convention of putting the more-known elements earlier in a term (eg 2=F0ix - 2 is known, 3.14159.... is mostly known, i is imaginary but at least it's constant, and x is unknown). > Do I need to get a hobby? I thought programming WAS a hobby? ChrisA