coding style (was Re: [PATCH][2.5] UTF-8 support in console)

Larry McVoy (lm@bitmover.com)
Sat, 31 May 2003 07:43:23 -0700


> 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/