On Thursday 07 March 2002 12:59 am, Poul-Henning Kamp wrote:
| In message <[EMAIL PROTECTED]>, "David O'Brien" writes:
| >Implies???  I thought I was quite explicit:
| >
| >    to prevent is "if (!strcmp(a,b))" which when read is extremely wrong
| > of that is actually happening.
| >
| >! is pronounced "NOT".  When read "if not string compare a with b then do
| > X", is the opposite of the the logic of the expression does.  Which is
| > "if string compare a with b is equal then do X".  ["if (strcmp(a,b) ==
| > 0)"]
|
| Well, we're clearly into "IMO" land here, so lets ignore that :-)

No, we aren't, and let's not.

Maybe your brain has gotten used to it, but to us ordinary mortals, even us 
ordinary mortals who've been slogging C code for time periods that can be 
measured in decades  (yikes!), it is very tempting to read

  i f (!strcmp(a,b,l))

as "if the strings don't compare" which , in ordinary usage, means don't 
compare *equal*.  But of course the C program is going to proceed to do 
exactly the opposite of that.

Now, I personally find the constructions

   if (!p)  do_thing_for_null_pointer;

and 

   if (p)  do_thing_for_valid_pointer;

quite readable and would prefer that an abstract Guide To Perfect Style 
blessed them since I find them quite readable as "if I don't have a pointer" 
and "if I do have a pointer".

But  *ALL* of this is beside the nominal point ANYWAY, which is to discuss 
the proper wording for the man(9) style guide which is supposed to document 
how things things are actually done in the kernel, not personal preference.

===================================================================

 So I just grepped the code

(find /usr/src -type f -exec grep 'if.*strcmp' {} \;)

and analyize the results.

Overall, there are 1831 !strcmp test and 3363 strcmp.*==0 tests

Within the kernel there are 84 !strcmp tests and 155 strcmp.*== 0 tests

So 65% either way in favor of the proposed change in wording -- a 2:1 
majority of the code votes FOR the proposed change.

(This is subject to minor error given that it's all based on greps and 
statistics, but I did the analysis a few different ways using different 
plausible regular expressions to determine the two code paths, and all  of 
analysis showed that it was at least 2:1 using the == / != 0 tests.)


-- 
Brian T. Schellenberger . . . . . . .   [EMAIL PROTECTED] (work)
Brian, the man from Babble-On . . . .   [EMAIL PROTECTED] (personal)
                                ME -->  http://www.babbleon.org
http://www.eff.org   <-- GOOD GUYS -->  http://www.programming-freedom.org 

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to