Skip to contentSkip to conversation

(0 == foo), rather than (foo == 0)

DISCUSSION Chip Salzenberg 4 participants 4 messages Mar 11, 2004 – Mar 12, 2004 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 6 lines · [email protected] writes:
Quoted 3 lines

As a result, using the former just tends to increase peoples confusion by making code harder to read, which in turn tends to increase the chance of bugs.

Kindly don't insult the kernel developers' with such statements. ;-) They are smart enough to understand such constructs [...]

It's not about intelligence! It's about the nature of human visual pattern-matching. Reading a pattern is always easier when you've seen it thousands of times before.

Henry Spencer's dictum about brace style seems particularly apropos:

8. Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding.

And that's what "0 == foo" is: an impediment to understanding.

Signature · 3 lines
Chip Salzenberg               - a.k.a. -               <[email protected]>
"I wanted to play hopscotch with the impenetrable mystery of existence,
    but he stepped in a wormhole and had to go in early."  // MST3K
#2 lore raw
Quoted 12 lines · Chip Salzenberg
Quoted 4 lines · [email protected] writes:
Quoted 1 line

As a result, using the former just tends to increase peoples confusion by making code harder to read, which in turn tends to increase the chance of bugs.

Kindly don't insult the kernel developers' with such statements. ;-) They are smart enough to understand such constructs [...]

It's not about intelligence! It's about the nature of human visual pattern-matching. Reading a pattern is always easier when you've seen it thousands of times before.

Quoted 8 lines

Henry Spencer's dictum about brace style seems particularly apropos:

8. Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding.

And that's what "0 == foo" is: an impediment to understanding.

It's got nothing to do with visual scanning. It's more to do with grammatical form i.e. we (especially English speakers) like the form: subject (foo) verb (==) object (0); and in these cases the variable (foo) is the indisputable subject (i.e. the thing the sentence is about) but (0 == foo) momentarily causes us to think that 0 is the subject and we find this disconcerting. On the other hand, Yoda (the Jedi master) would probably prefer: (0 foo ==) :-)

Like most matters of style there are points for and against both methods
and eventually someone has to make a (relatively arbitrary) decision.
Linus has made the decision and it's his call so we should abide by it
(especially since he made it pretty clear that he was aware of (and considered) all the relevant arguments and is therefore unlikely to change his mind).

Peter
PS It's important not to get too emotionally attached to a particular method or style because there's always a chance that whoever gets to decide which will be used may not choose the one you like. This time you lucked in :-)

Signature · 4 lines
Dr Peter Williams, Chief Scientist                [email protected]
Aurema Pty Limited                                Tel:+61 2 9698 2322
PO Box 305, Strawberry Hills NSW 2012, Australia  Fax:+61 2 9699 9174
79 Myrtle Street, Chippendale NSW 2008, Australia http://www.aurema.com
#3 lore raw
In reply to Chip Salzenberg

Just to throw a little more gas on this particular fire (or maybe some water, depending on your point of view), when I worked for a while at the Evil Empire, the "const == variable" comparison was mandatory in the group I worked in. Odd to look at initially, I'll admit, but it still caught several potential bugs. One other thing that was mandatory was to set to NULL any pointer to memory area that was freed immediately after freeing it. Again, a good idea, although not a coding style issue.

Chris

Quoted 30 lines · Chip Salzenberg
Quoted 6 lines · [email protected] writes:
Quoted 3 lines

As a result, using the former just tends to increase peoples confusion by making code harder to read, which in turn tends to increase the chance of bugs.

Kindly don't insult the kernel developers' with such statements. ;-) They are smart enough to understand such constructs [...]

It's not about intelligence! It's about the nature of human visual pattern-matching. Reading a pattern is always easier when you've seen it thousands of times before.

Henry Spencer's dictum about brace style seems particularly apropos:

8. Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding.

And that's what "0 == foo" is: an impediment to understanding.

Signature · 8 lines
Chip Salzenberg               - a.k.a. -               <[email protected]>
"I wanted to play hopscotch with the impenetrable mystery of existence,
    but he stepped in a wormhole and had to go in early."  // MST3K
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#4 lore raw
Quoted 11 lines · Chris Johns

Just to throw a little more gas on this particular fire (or maybe some water, depending on your point of view), when I worked for a while at the Evil Empire, the "const == variable" comparison was mandatory in the group I worked in. Odd to look at initially, I'll admit, but it still caught
several potential bugs. One other thing that was mandatory was to set to NULL any pointer to memory area that was freed immediately after freeing it. Again, a good idea, although not a coding style issue.

Chris

Well I'll take it as being proof that forcing a particular style doesn't help make bug-free code since it didn't help Microsoft.

I'll bet that Microsoft has more bugs per KLOC than any other software, ever. It is a formidable challenge to make software that will beat it in that area. You really need to try. You need to be cunning enough to get it through the compile-stage. It's an art.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.