Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44379
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; '(even': 0.05; 'assignment': 0.07; 'compiler': 0.07; 'variables': 0.07; 'assigning': 0.09; 'function,': 0.09; 'operator,': 0.09; 'string;': 0.09; 'c/c++': 0.16; 'expression.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instance:': 0.16; 'operands': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'first.': 0.19; 'thu,': 0.19; 'putting': 0.22; 'char': 0.24; 'compare': 0.26; 'first,': 0.26; 'switch': 0.26; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'possibility': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'constant': 0.31; 'this.': 0.32; 'fri,': 0.33; 'received:209.85': 0.35; 'common': 0.35; 'knows': 0.35; 'received:209.85.220': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'executing': 0.36; 'error.': 0.37; 'received:209': 0.37; 'convention': 0.38; 'ends': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'then,': 0.60; 'most': 0.60; 'helps': 0.61; 'first': 0.61; 'you.': 0.62; 'protection': 0.63; 'more': 0.64; '26,': 0.68; '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; bh=4QOGGNv7j9fxpX4QIez0gO2XqtmsmVO2+SdYza3j3UA=; b=B1vTBqICWOLoadpHSBac8bX46fYl6f2nZQGAk53jBfqxccUJS7jIXySERcalEiKuC4 d9MnA/2CflyqE3xMHNiyWwXfSTp/r7S2lqewYImsJoh9P/px3YofcZja+vASb53Z4iTT kKTBKaN7OMCx35fs7Ngm5w6zUO0jOTwLbMUCrpqLamUM595aN4qFOA5f5/WbGayJVqEF OMxF+mdEqAxOZS9aoILH5KAJtxpbgpNwSUelgTwU0jUbm6PRyK6coqJLZZ66IpKKSI0S dT/e+nVyckA2404xWwvUsRerQknrugWUXikwxk+MSvThTzBXqT+/6z2H5MnxU2Ajmk+O dNsg== |
| MIME-Version | 1.0 |
| X-Received | by 10.58.75.46 with SMTP id z14mr27897857vev.52.1366944515167; Thu, 25 Apr 2013 19:48:35 -0700 (PDT) |
| In-Reply-To | <nqpjn81vrbluuegvj1ggvuhegdcvki6743@invalid.netcom.com> |
| References | <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> <CAPTjJmq6afVuQnXCyXNFV1QvYi_Pt2qT9tCmjBVUSvqOLunEhA@mail.gmail.com> <nqpjn81vrbluuegvj1ggvuhegdcvki6743@invalid.netcom.com> |
| Date | Fri, 26 Apr 2013 12:48:35 +1000 |
| Subject | Re: Comparison Style |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1077.1366944517.3114.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1366944517 news.xs4all.nl 15893 [2001:888:2000:d::a6]:60570 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44379 |
Show key headers only | View raw
On Fri, Apr 26, 2013 at 12:37 PM, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:
> On Thu, 25 Apr 2013 15:57:49 +1000, Chris Angelico <rosuav@gmail.com>
> declaimed the following in gmane.comp.python.general:
>> 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).
>
> The main reason for /literal/ first is to trap C/C++ assignment as
> expression.
>
> if (x = 5)
>
> ends up assigning x the value 5 and THEN, since 5 is "true" executing
> the "then" part.
>
> if (5 = x)
>
> OTOH is a compiler error.
>
Aware of this. My point is that, even though there's a good reason for
putting the constant first, it's still FAR more common to put the
variable first. Also, this protection helps only when the "constant"
is actually something the compiler knows is a constant - it doesn't
work in a search function, for instance:
char *strchr(char *string, char findme) {
while (*string) {
if (*string==findme) return string;
++string;
}
return 0;
}
If you switch the order of operands in that, the compiler won't help
you. Plus it "reads" wrong. So the convention is still
variable==constant.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Comparison Style llanitedave <llanitedave@veawb.coop> - 2013-04-24 22:49 -0700
Re: Comparison Style Chris Angelico <rosuav@gmail.com> - 2013-04-25 15:57 +1000
Re: Comparison Style llanitedave <llanitedave@veawb.coop> - 2013-04-25 07:19 -0700
Re: Comparison Style Chris Angelico <rosuav@gmail.com> - 2013-04-26 02:25 +1000
Re: Comparison Style Steve Simmons <square.steve@gmail.com> - 2013-04-25 19:31 +0100
Re: Comparison Style llanitedave <llanitedave@veawb.coop> - 2013-04-25 13:13 -0700
Re: Comparison Style Neil Cerutti <neilc@norwich.edu> - 2013-04-25 20:15 +0000
Re: Comparison Style Steve Simmons <square.steve@gmail.com> - 2013-04-25 21:35 +0100
Re: Comparison Style Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-26 10:02 +0100
Re: Comparison Style Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-25 22:37 -0400
Re: Comparison Style Chris Angelico <rosuav@gmail.com> - 2013-04-26 12:48 +1000
Re: Comparison Style Roy Smith <roy@panix.com> - 2013-04-27 17:03 -0400
Re: Comparison Style Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-27 17:40 -0400
Re: Comparison Style Dave Angel <davea@davea.name> - 2013-04-25 23:43 -0400
csiph-web