[PATCH 1.12] A coding style for the server

Jeremy Huddleston jeremyhu at apple.com
Sat Feb 11 14:47:43 PST 2012


On Jan 17, 2012, at 7:02 PM, Daniel Stone <daniel at fooishbar.org> wrote:

> Hi all,
> So since the list has been fairly quiet and uncontroversial since the
> Ctrl-Alt-Backspace argument, I thought I might throw two comedy patches
> out there and see if they stuck.

This is gonna be a fun thread.

> No but seriously though, it's both a) utterly ridiculous and b) faintly
> stupid, that we still don't actually have a coding style.  I honestly --
> honestly[0] -- don't care what the coding style is.  I just care that we
> have one.

+1

> Most of the code we broadly agrees on most things.  Some things were a
> little more split; for instance, cuddling else was only just outnumbered
> by non-cuddling else, and also braces cuddling if outnumbered
> non-cuddling.

> Probably the largest change is that all tabs were expanded to eight
> spaces.  The only argument I've ever heard in favour of having a tab
> hardcoded to eight spaces and mixing tabs and spaces is that a) emacs
> does that sometimes, and b) it makes compilation faster because you have
> fewer bytes to lex.  I honestly don't have much time for either
> argument, and it does provably make editing code harder.

Ok, in all seriousness now ... I *HATE* it when people mix tabs and spaces.  Especially when TAB_SPACES != INDENT_SPACES.  For the life of me, I can't find a decent editor that supports that style.  Yes, vim doesn't count because I said "decent" before editor.

> So, the commit in my coding-style xserver branch is simply the result of
> running this:
> indent -linux -bad -bap -blf -bli0 -br -brs -cbi0 -cdw -nce -cs -i4 -hnl
> -l80 -lc80 -lp -nbbo -nbc -nbfda -nprs -npcs -npsl -saf -sai -saw -nut
> across *.c and *.h in the X server tree.

Can you please throw .m in there as well to grab my handful of Obj-C files in XQuartz in the same commit.

For those too lazy to read the man page, here's a quick list of the options from Daniel's command above:

-linux: Use Linux coding style
-bad: Force blank lines after the declarations.
-bap: Force blank lines after procedure bodies.
-blf: Put braces on line following function definition line.
-bli0: Indent braces n spaces.
-br: Put braces on line with if, etc.
-brs: Put braces on struct declaration line.
-cbi0: Indent braces after a case label N spaces.
-cdw: Cuddle while of do {} while; and preceding `}'.
-nce: Do not cuddle } and else.
-cs: Put a space after a cast operator.
-i4: Set indentation level to n spaces.
-hnl: Prefer to break long lines at the position of newlines in the input.
-l80: Set maximum line length for non-comment lines to n.
-lc80: Set maximum line length for comment formatting to n.
-lp: Line up continued lines at parentheses.
-nbbo: Do not prefer to break long lines before boolean operators.
-nbc: Do not force newlines after commas in declarations.
-nbfda: Don't put each argument in a function declaration on a separate line.
-nprs: Do not put a space after every '(' and before every ')'.
-npcs: Do not put space after the function in function calls.
-npsl: Put the type of a procedure on the same line as its name.
-saf: Put a space after each for.
-sai: Put a space after each if.
-saw: Put a space after each while.
-nut: Use spaces instead of tabs.

-linux adds these defaults:
-nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4
-cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -sai
-saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1

Thus -linux adds these effects:
-c33 -cd33 -ncdb -ci4 -cli0 -d0 -di1 -nfc1 -ip0 -nsc -sob
-nfca -cp33 -ss -ts8 -il1

-c33: Put comments to the right of code in column n.
-cd33: Put comments to the right of the declarations in column n.
-ncdb: Do not put comment delimiters on blank lines.
-ci4: Continuation indent of n spaces.
-cli0: Case label indent of n spaces.
-d0: Set indentation of comments not to the right of code to n spaces.
-di1: Put variables in column n.
-nfc1: Do not format comments in the first column as normal.
-ip0: Indent parameter types in old-style function definitions by n spaces.
-nsc: Do not put the `*' character at the left of comments.
-sob: Swallow optional blank lines.
-nfca: Do not format any comments.
-cp33: Put comments to the right of #else and #endif statements in column n.
-ss: On one-line for and while statements, force a blank before the semicolon.
-ts8: Set tab size to n spaces.
-il1: Set offset for labels to column n.

My comments:

1) -nce is ugly.  Please use -ce.
2) I'd like to see -nss rather than picking up -ss from -linux.
3) I'd prefer -cli4 to the -cli0 from -linux.


>  No more, no less.  The build
> seems to continue to work just fine.  Don't be scared by the -linux;
> it just provides a set of reasonable default options.  Pretty much
> everything else was just done by hand to match what we seem to generally
> do in the server.
> 
> It's obviously too big to attach to this mail, so I haven't done that.
> 
> I'd like to see this merged for 1.12, despite the merge window having
> shut, so patches for 1.13's master are more likely to apply to 1.12.
> It's arguably not the best time to do it, but there is no good time.

Also, we should do the exact same thing on the stable branch to allow for easier cherry-picking.

> Thoughts?
> 
> Cheers,
> Daniel
> 
> [0]: As long as it's not GNU.
> [1]: git://people.freedesktop.org/~daniels/xserver - it's based against
>     current upstream master.
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 



More information about the xorg-devel mailing list