From owner-freebsd-hackers Thu Mar 7 1:31:50 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mail4.nc.rr.com (fe4.southeast.rr.com [24.93.67.51]) by hub.freebsd.org (Postfix) with ESMTP id B741837B400; Thu, 7 Mar 2002 01:31:43 -0800 (PST) Received: from i8k.babbleon.org ([66.57.85.154]) by mail4.nc.rr.com with Microsoft SMTPSVC(5.5.1877.687.68); Thu, 7 Mar 2002 02:17:09 -0500 Received: by i8k.babbleon.org (Postfix, from userid 111) id E26DBBA03; Thu, 7 Mar 2002 02:16:30 -0500 (EST) Content-Type: text/plain; charset="iso-8859-1" From: Brian T.Schellenberger To: Poul-Henning Kamp , obrien@FreeBSD.ORG Subject: Re: RFC: style(9) isn't explicit about booleans for testing -- an actual analysis of the code! Date: Thu, 7 Mar 2002 02:16:30 -0500 X-Mailer: KMail [version 1.3] Cc: Garance A Drosihn , Mike Meyer , hackers@FreeBSD.ORG References: <52204.1015480748@critter.freebsd.dk> In-Reply-To: <52204.1015480748@critter.freebsd.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <20020307071630.E26DBBA03@i8k.babbleon.org> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thursday 07 March 2002 12:59 am, Poul-Henning Kamp wrote: | In message <20020306192234.B55297@dragon.nuxi.com>, "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 . . . . . . . bts@wnt.sas.com (work) Brian, the man from Babble-On . . . . bts@babbleon.org (personal) ME --> http://www.babbleon.org http://www.eff.org <-- GOOD GUYS --> http://www.programming-freedom.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message