Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.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.096 X-Spam-Evidence: '*H*': 0.81; '*S*': 0.00; 'compiler': 0.07; 'function,': 0.09; 'string;': 0.09; 'sure,': 0.09; 'instance:': 0.16; 'operands': 0.16; 'questioned': 0.16; 'wrote:': 0.18; 'coding': 0.22; 'header:User-Agent:1': 0.23; 'char': 0.24; 'first,': 0.26; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; "doesn't": 0.30; 'constant': 0.31; 'maybe': 0.34; "i'd": 0.34; 'problem': 0.35; 'knows': 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'there': 0.35; 'convention': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'helps': 0.61; 'skip:* 10': 0.61; "you're": 0.61; 'you.': 0.62; 'making': 0.63; 'protection': 0.63; 'soon': 0.63; 'benefit': 0.68; 'realized': 0.68; 'received:74.208': 0.68; 'const': 0.84; 'received:74.208.4.194': 0.84 Date: Thu, 25 Apr 2013 23:43:08 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Comparison Style References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:ERX4wQOckYYOPHnE+W7IfEB9UhWzKyFt5wGipKGyDWr RcaJ8v2Zejmtbm3ma6o3qKPBQ8T5T0rk2PuE+9OrCDmCB6G8wV gN53Exx6wQdgq1lEzWj7pH6AaLLNA9a7s/Rl7GYnSja/O4j8HH RJNFmJ+EK38ueDLFvVj3x0L/A4tN+pI4oKh566x9JZPv1s2c6+ wJNQpHYJ0wSikXptxGEqa+6zOxPVRSQ9a9ArxjcGbeLw1bc/l5 mEZk9k1YLwNWbg4kOw8PS3Gv5NASo4vgF4nG3rQRA8IiP4Jyfw gQia5k2fOaHaJFngIu1GoORMqdKVFYEPMbaueuxUP+uu4C/Sw= = 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: 1366947835 news.xs4all.nl 15877 [2001:888:2000:d::a6]:56050 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44381 On 04/25/2013 10:48 PM, Chris Angelico wrote: > 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; > } Sure, but if I were coding in C again, I'd have made that function signature char *strchr(char *string, const char findme) { or maybe char *strchr(const char *string, const char findme) { > > If you switch the order of operands in that, the compiler won't help > you. Yes, it would. > Plus it "reads" wrong. So the convention is still > variable==constant. In my case, after having it drilled in that you're "supposed" to put the constant first, I realized that I never had any problem with using =, because as soon as I questioned the order, I just double-checked that I was using ==. At that point, there was no longer any benefit to making the order backwards. -- DaveA