Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44381
| Date | 2013-04-25 23:43 -0400 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| Subject | Re: Comparison Style |
| References | <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> <CAPTjJmq6afVuQnXCyXNFV1QvYi_Pt2qT9tCmjBVUSvqOLunEhA@mail.gmail.com> <nqpjn81vrbluuegvj1ggvuhegdcvki6743@invalid.netcom.com> <CAPTjJmrwsC1NFB0Vk4H2_fy1+mS+ec41r-9OoFpkX5i5ZcJsXw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1079.1366947835.3114.python-list@python.org> (permalink) |
On 04/25/2013 10:48 PM, Chris Angelico wrote:
<SNIP>
> 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
Back to comp.lang.python | Previous | Next — Previous 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