From: Seebs on
On 2010-03-05, Richard Heathfield <rjh(a)see.sig.invalid> wrote:
> This is C we're discussing, not English. It is folly to pretend that the
> rules of English apply to C.

Actually, I'm not exactly talking about English. I'm talking about the
underlying cognitive structures English (and every other language) maps to.
So far as I know, regardless of language, humans distinguish between the
topic and the comment (thanks to another poster for providing the
terminology).

> Ignoring. Probably a minor thinko on his part, no big deal.

Not a big deal, but oddly, somewhat related -- it's the kind of mistake that
shows up as a side-effect of added complexity. If you add enough parentheses
to an expression, people will start mismatching them or putting them in the
wrong places because they can't track them automatically anymore, or because
the automatic tracking fails.

For me, swapping the "natural" order of a comparison (I expect the "topic"
to be first) is one extra layer, similar to an indirection, extra set of
parentheses, or whatever. I don't know how common that is, but I'm pretty
sure it's not going to change in the forseeable future.

-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: Keith Thompson on
ImpalerCore <jadill33(a)gmail.com> writes:
> On Mar 5, 12:13 pm, la...(a)ludens.elte.hu (Ersek, Laszlo) wrote:
>> In article <4JydnbCdGNgatgzWnZ2dnUVZ7rydn...(a)bt.com>,
>>
>> Richard Heathfield <r...(a)see.sig.invalid> writes:
>> > Ersek, Laszlo wrote:
>> >> Because when read out loud, "i" is the subject.
>>
>> > Again, your comment would only be relevant if this were English, which
>> > it isn't.
>>
>> Exactly -- I'm a staunch member of the "7 == x" camp. I just tried to
>> explain why, as I perceive, Seebs thinks what he thinks. (Sorry if this
>> qualifies as bad etiquette.)
>
> Are you a staunch member of the '7 == x' because of style, or because
> of the possibility of catching '7 = x' errors? I personally don't
> like the style simply because it *is* more mind taxing, and it's a
> result of not seeing code in that style, not writing code in that
> style, and not thinking about code in that style, for about 8 years
> between C++ and C, that my brain has been conditioned that way. I
> would be bold enough to say that a large majority of C programmers are
> conditioned that way, simply from other people's code and books that
> I've seen.
[...]

I have a question for those who like and/or use the '7 == x;' style.

The usual rationale for the '7 == x' style is that it makes it
easier to catch errors where you type "=" rather than "==".

Would you even consider writing '7 == x' rather than 'x == 7'
if C's equality and comparison operators were more distinct?

For example, consider a hypothetical C-like language in which the
equality operator is spelled "=" and the assignment operator is
"<-", and "==" is a syntax error. (Yes, that would quietly break
"x<-1"; let's ignore that.)

In such a language, would you ever write "if (7 = x)" in preference
to "if (x = 7)"? If so, why?

--
Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
From: Ian Collins on
Keith Thompson wrote:
>
> I have a question for those who like and/or use the '7 == x;' style.
>
> The usual rationale for the '7 == x' style is that it makes it
> easier to catch errors where you type "=" rather than "==".

Good development practices (unit testing) will catch that typo.

> Would you even consider writing '7 == x' rather than 'x == 7'
> if C's equality and comparison operators were more distinct?
>
> For example, consider a hypothetical C-like language in which the
> equality operator is spelled "=" and the assignment operator is
> "<-", and "==" is a syntax error. (Yes, that would quietly break
> "x<-1"; let's ignore that.)
>
> In such a language, would you ever write "if (7 = x)" in preference
> to "if (x = 7)"? If so, why?

While not a programming language, most unit test harnesses (at least all
those I've used) express test assertions as ASSERT( expected, actual )
so after using them for a while, placing the invariant on the left
doesn't look so bad. Despite many years exposure to this testing style,
I still place the invariant on the right in conditionals....

--
Ian Collins
From: Andrew Poelstra on
On 2010-03-05, Ersek, Laszlo <lacos(a)ludens.elte.hu> wrote:
>
> Ben Bacarisse <ben.usenet(a)bsb.me.uk> writes:
>
>> lacos(a)ludens.elte.hu (Ersek, Laszlo) writes:
>>
>>>> Seebs wrote:
>>>>>
>>>>> Why do we write "i < 10" rather than "10 >= i"?
>>>
>>> "10 == i" satisfies the second but not the first.
>>
>> Either way, it's not really at the heart of the question unless you
>> think the switch *caused* the typo.
>
> Yes, I thought (and think) that that was not unpossible. If my memory
> serves, both Keith and Seebs have pointed out that they need to reorder
> reverse-ordered relational operators in their heads (sorry if I'm making
> this up now) or that it causes extra mental load or something to that
> effect. So the typo may be related to the reversing process.
>

(I hope I haven't munged up the attributions; they were formatted
funnily and I was having a tough time reading them, so I shuffled
some >'s around.)

As Seebs points out in his reply to this article,
(i > 10) == !(i <= 10),
while
(i > 10) == (10 < i),
which is quite a different beast.

Also, the idiomatic "count up to 10" loop is:
for(i = 0; i < 10; ++i)

while "count down to 10" is:
for(i = 10; i >= 10; ++i)

For these reasons I didn't see the typo, even after lacos said that
there /was/ one, a fact that initially escaped me completely. Like
Keith and Seebs, I need to mentally reorder these kind of expressions
to understand them.

I do that simply by reading the words backwards, since reading and
writing backwards is much easier for me than re-ordering and then
"reading" different text from what I see. So I find it interesting
that I made the same mistake.

--
Andrew Poelstra
http://www.wpsoftware.net/andrew
From: Rick Jones on
In comp.unix.programmer Ike Naar <ike(a)localhost.claranet.nl> wrote:
> It doesn't matter, but anybody can fool themselves that it does.
> And then Alice convinces herself that 3+x is ugly and unreadable,
> Bob opts for x+3 being error-prone and unreadable, and now what
> should Carol write?

The ISO, or perhaps her elected representative - there aught to be a
law right?-)

rick jones
--
oxymoron n, Hummer H2 with California Save Our Coasts and Oceans plates
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
First  |  Prev  |  Next  |  Last
Pages: 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
Prev: integer
Next: shared memory question