[From nobody Mon Aug 2 21:31:08 2004 Received: from vger.kernel.org (vger.kernel.org [209.116.70.75]) by tipjar.com id h4VEiMvY089076; Sat, 31 May 2003 08:44:22 -0600 (MDT) X-Received-From: linux-kernel-owner+whatever=40davidnicol.com@vger.kernel.org X-Received-For: <whatever@davidnicol.com> Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S264336AbTEaOaK (ORCPT <rfc822; whatever@davidnicol.com>); Sat, 31 May 2003 10:30:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S264339AbTEaOaK (ORCPT <rfc822; linux-kernel-outgoing>); Sat, 31 May 2003 10:30:10 -0400 Received: from smtp.bitmover.com ([192.132.92.12]:37547 "EHLO smtp.bitmover.com") by vger.kernel.org with ESMTP id S264336AbTEaOaI (ORCPT <rfc822; linux-kernel@vger.kernel.org>); Sat, 31 May 2003 10:30:08 -0400 Received: from work.bitmover.com (ipcop.bitmover.com [192.132.92.15]) by smtp.bitmover.com (8.12.9/8.12.9) with ESMTP id h4VMm1Bm011604; Sat, 31 May 2003 15:48:01 -0700 Received: (from lm@localhost) by work.bitmover.com (8.11.6/8.11.6) id h4VEhNx00604; Sat, 31 May 2003 07:43:23 -0700 Date: Sat, 31 May 2003 07:43:23 -0700 From: Larry McVoy <lm@bitmover.com> To: Christoph Hellwig <hch@infradead.org>, Chris Heath <chris@heathens.co.nz>, linux-kernel@vger.kernel.org Subject: coding style (was Re: [PATCH][2.5] UTF-8 support in console) Message-ID: <20030531144323.GA22810@work.bitmover.com> Mail-Followup-To: Larry McVoy <lm@work.bitmover.com>, Christoph Hellwig <hch@infradead.org>, Chris Heath <chris@heathens.co.nz>, linux-kernel@vger.kernel.org References: <20030531095521.5576.CHRIS@heathens.co.nz> <20030531152133.A32144@infradead.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030531152133.A32144@infradead.org> User-Agent: Mutt/1.4i X-MailScanner-Information: Please contact the ISP for more information X-MailScanner: Found to be clean X-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (score=0.5, required 7, AWL, DATE_IN_PAST_06_12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org X-UIDL: jZ=!!NP9!!B7Q"!4!i"! Content-Transfer-Encoding: 7bit > Please linewrap after 80 chars. Amen to that. > + if (!q) { > > Kill the blank line above. > > + if (!q) return; > > Two lines again. A couple of comments: in the BK source tree, we've diverged from the Linux coding style a bit (maybe a lot, Linus has read the source, ask him). One thing is unless (p) { .... } instead of if (!p) { .... } It's just a #define unless(x) if (!(x)) but it makes some code read quite a bit easier. I'm a stickler for not using 2 lines where one will do, i.e., FILE *f; ... unless (f = fopen(file, "r")) { error handling; return (-1); } You hiccup the first time you see it, then you can read it, then you start using it. Yeah, I know, I'm using the value of an assignment in a conditional, trust me, it works fine. One other one is the if (!q) return; Chris said two lines, we don't do it that way. The coding style we use is a) one line is fine for a single statement. b) in all other cases there are curly braces unless (q) return; /* OK */ unless (q) { /* also OK */ return; } unless (q) return; /* not OK, no "}" */ The point of this style is twofold: save a line when the thing you are doing is a singe statement, and make it easier for your eyes (or my tired old eyes) to run over the code. If you see indentation you know it is a block and there will be a closing } without exception. It keeps the line counts about 10% smaller or so in our source base. If you are looking for bragging rights about how big your stuff is that might be bad but I like it because I can read more code in a window. -- --- Larry McVoy lm at bitmover.com http://www.bitmover.com/lm - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ ]