Re: [PATCH] CodingStyle fixes for drm_agpsupport

Werner Almesberger
2003-08-12T10:00:49Z

Jeff Garzik wrote:
> Also, having two styles
> of 'if' formatting in your example just screams "inconsistent" to me :)

Naw, it's only one style:

<stmt> ::= if (<expression>) <stmt>
<stmt> ::= { <newline> <stmts> } <newline>
<stmt> ::= <expression> ; <newline>
etc.

Perfectly consistent. ("Always end a statement with a newline.")

> Ug. The first and last 'if' need spreading out away from the big fat
> block,

Why waste a perfectly good punch card on that second line ? :-)

My own formatting rules for "if" go about like this:

1) if "if" and the statement fit on a single line, put them accordingly
("vertical space is precious")

2) if the line needs to wrap (I wrap at the 79th column), always put
the statement on a separate line, fully indented ("wrap at the
highest hierarchical level")

3) likewise for "else" and statement. Here, 2) doesn't apply for kernel
code, which uses a full tab for indentation - in my user-space code,
I use only four spaces, so sometimes, I get
else
stuff_that_just_happens_to_be_too_long_by_one_silly_little_character();

4) if the statement is a block, and there is an "else" branch with a
single statement, invert the condition ("don't hide the fine print")

Since I'm the only sentient being in the universe, and all the rest
of you are just figments of my imagination, it's fairly obvious that
my style is The Right Style :-)

> and the "return (whatever)" fools your eyes into thinking they
> are function calls at a 10-nanosecond glance.

Yeah, I hate that too.

Larry:
> > I also make people do
> >
> > if ((a <= B) || (c >= d)) {

Argl. That's one place where the precedence works beautifully.
Extra parentheses in trivial cases always make me suspect that
the author was actually trying to do something else.

- Werner

--
_________________________________________________________________________
/ Werner Almesberger, Buenos Aires, Argentina wa@almesberger.net /
/_http://www.almesberger.net/____________________________________________/