From: Richard Heathfield on
Seebs wrote:
> On 2010-03-06, Richard Heathfield <rjh(a)see.sig.invalid> wrote:
>> No, he isn't. :-) Anyone who wastes half a day on understanding 7==x is
>> not the kind of person you want maintaining C code in the first place.
>
> Not "understanding 7==x". Figuring out whether it's been done that way for
> a particular reason.

If it takes him more than a quarter of a second to recognise that the
writer put the constant on the left to allow even the dumbest of
compilers to alert the programmer in case he missed one of the =s (given
that this technique is hardly a trade secret), then he's not the kind of
person you want maintaining C code in the first place.

> And while "half a day" may be a bit much, I've certainly
> seen fairly experienced coders lose an hour or more to something that was
> written in a way that suggested a deeper meaning or intent when it was, in
> fact, merely idiosyncratic.
>
> If someone wrote:
> for (i = 0; max > i; ++i)
> I'd at least want to investigate briefly whether there was some non-obvious
> reason for which the comparison was written backwards.

You say it's "backwards", and okay, obviously I believe that you see it
that way. I /don't/ see it that way. <shrug>

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
From: Seebs on
On 2010-03-06, Richard Heathfield <rjh(a)see.sig.invalid> wrote:
> Seebs wrote:
>> Not "understanding 7==x". Figuring out whether it's been done that way for
>> a particular reason.

> If it takes him more than a quarter of a second to recognise that the
> writer put the constant on the left to allow even the dumbest of
> compilers to alert the programmer in case he missed one of the =s (given
> that this technique is hardly a trade secret), then he's not the kind of
> person you want maintaining C code in the first place.

I disagree. I wouldn't trust someone who made that assumption without
checking it -- at least, say, verifying that the same author did that
consistently.

I've heard of that convention, and that argument for it, but I've never seen
it actually solve a problem -- I don't think I've used a compiler in either
of the last two decades that couldn't catch such errors in other ways. So if
I see code written that way, I check it out to see whether that's what's up.
That takes a lot more than a quarter second -- and if only one test in a file
is written that way, I'm not going to assume it was someone using that
convention, because if they did, all the other tests would be the same.

>> If someone wrote:
>> for (i = 0; max > i; ++i)
>> I'd at least want to investigate briefly whether there was some non-obvious
>> reason for which the comparison was written backwards.

> You say it's "backwards", and okay, obviously I believe that you see it
> that way. I /don't/ see it that way. <shrug>

That's fine -- but since the vast majority of code writes those relations in
a consistent way, exceptions ought to be looked at.

Cases where something is done in an unusual way are often either errors
or signs of something funky up with the code.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: io_x on

"pete" <pfiland(a)mindspring.com> ha scritto nel messaggio
news:4B919F04.271C(a)mindspring.com...
> Richard Heathfield wrote:
>>
>> pete wrote:
>> <snip>
>>
>> > To count down through an array with N elements, I use
>> >
>> > size_t i = N;
>> >
>> > while (i-- != 0) {
>> > array[i];
>> > }
>>
>> Isn't this where we came in? Or was that another thread?
>
> I remember writing the same thing once a few weeks ago
> but I don't remember which thread.

the thread i would like to prove above is not ok
but see i make wrong and i sent nothing

> --
> pete



From: Lorenzo Villari on
On 5 Mar 2010 23:29:45 +0100
lacos(a)ludens.elte.hu (Ersek, Laszlo) wrote:

> No, I would not have picked up the "7 == x" style in that case.
>
> For example, Pascal has := for assignment and = for equality
> (IIRC :)). Even in C, I started out with "x == 7". I was
> occasionally bitten by "if (x = 7)" typos. Not very frequently, and
> most of the time caught by compiler warnings. However, on some forum
> somebody brought up "7 == x" explicitly, and after giving the idea my
> unrelenting attention :) for a minute or two, I liked it so much that
> I trained myself to it.

1) The "Even in C" is in one some way related to "For example,
Pascal..." ?

2) The fact you "liked it so much" has something to do with Pascal?

I prefer

if (x == 7)

because it gives me the idea I'm testing x more and because 90 % of the
code I've seen use that.
From: Ersek, Laszlo on
In article <20100306145059.04e9465c(a)kubuntu>, Lorenzo Villari <vlllnz(a)tiscali.it> writes:
> On 5 Mar 2010 23:29:45 +0100
> lacos(a)ludens.elte.hu (Ersek, Laszlo) wrote:
>
>> No, I would not have picked up the "7 == x" style in that case.
>>
>> For example, Pascal has := for assignment and = for equality
>> (IIRC :)). Even in C, I started out with "x == 7". I was
>> occasionally bitten by "if (x = 7)" typos. Not very frequently, and
>> most of the time caught by compiler warnings. However, on some forum
>> somebody brought up "7 == x" explicitly, and after giving the idea my
>> unrelenting attention :) for a minute or two, I liked it so much that
>> I trained myself to it.
>
> 1) The "Even in C" is in one some way related to "For example,
> Pascal..." ?


I guess I did some fairly bad editing with the above :)


1. The question was if people liking "7 == x" would stick to it if the
language had an assignment operator that couldn't easily be mixed up
with testing for equality.

2. No, I would not stick to it then. For example, in Pascal, where the
assignment operator ":=" resembles the mathematical "let ... be" (define
.... as) act and is intuitively different from testing for equality, and
also where you can't put an assignment into a controlling expression
anyway, I never felt the need to write 7 == x (or rather, in Pascal, 7 =
x). Pascal is an example for the kind of language Keith specified in 1.
(You snipped the original question so I write this from memory.)

3. Even in C, where I later found "7 == x" useful, it was not part of my
original style.


Thus: Pascal -- no motivation, C -- even though I discovered my
incentive later, the idea was not obvious and didn't match my initial
way of writing ==. The word "even" refers to the fact that Pascal bears
no such incentive for me, while C does.


(Perhaps it's even more confusing now, sorry.)


> 2) The fact you "liked it so much" has something to do with Pascal?

No, it has not.


Cheers,
lacos
First  |  Prev  |  Next  |  Last
Pages: 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
Prev: integer
Next: shared memory question