Style niggle

10 views
Skip to first unread message

Steve VanDeBogart

unread,
Apr 12, 2011, 2:43:37 PM4/12/11
to Chromium-dev
We've had some disagreement on the proper sort order of headers in my cube area.  As far as I can tell, the style guide does not clearly define what order to put the following items in and reaching a consensus for consistencies sake would be great.

a/c.h a/c_b.h a/c_x.h a_b/c.h a_x/c.h

Some potential orderings:

Unix "sort" order:
a/c.h
a/c_b.h
a/c_x.h
a_b/c.h
a_x/c.h

Short words at the end:
a_b/c.h
a_x/c.h
a/c_b.h
a/c_x.h
a/c.h

Omit non alpha-numeric order:
a_b/c.h
a/c_b.h
a/c.h
a/c_x.h
a_x/c.h

Omit non alpha-numeric within file/directory names:
a/c_b.h
a/c.h
a/c_x.h
a_b/c.h
a_x/c.h

--
Steve

Mike Belshe

unread,
Apr 12, 2011, 2:47:18 PM4/12/11
to van...@chromium.org, Chromium-dev
On Tue, Apr 12, 2011 at 11:43 AM, Steve VanDeBogart <van...@chromium.org> wrote:
We've had some disagreement on the proper sort order of headers in my cube area.  As far as I can tell, the style guide does not clearly define what order to put the following items in and reaching a consensus for consistencies sake would be great.

I prefer no rule - too minor to matter.

Mike
 
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Evan Stade

unread,
Apr 12, 2011, 2:50:35 PM4/12/11
to van...@chromium.org, Chromium-dev
On Tue, Apr 12, 2011 at 11:43 AM, Steve VanDeBogart
<van...@chromium.org> wrote:
> We've had some disagreement on the proper sort order of headers in my cube
> area.  As far as I can tell, the style guide does not clearly define what
> order to put the following items in and reaching a consensus for
> consistencies sake would be great.
> a/c.h a/c_b.h a/c_x.h a_b/c.h a_x/c.h
> Some potential orderings:
> Unix "sort" order:
> a/c.h
> a/c_b.h
> a/c_x.h
> a_b/c.h
> a_x/c.h

I believe this is standard for chrome.

> Short words at the end:
> a_b/c.h
> a_x/c.h
> a/c_b.h
> a/c_x.h
> a/c.h
> Omit non alpha-numeric order:
> a_b/c.h
> a/c_b.h
> a/c.h
> a/c_x.h
> a_x/c.h
> Omit non alpha-numeric within file/directory names:
> a/c_b.h
> a/c.h
> a/c_x.h
> a_b/c.h
> a_x/c.h
> --
> Steve
>

Mattias Nissler

unread,
Apr 12, 2011, 2:54:33 PM4/12/11
to van...@chromium.org, Chromium-dev


On Apr 12, 2011 8:44 PM, "Steve VanDeBogart" <van...@chromium.org> wrote:
>
> We've had some disagreement on the proper sort order of headers in my cube area.  As far as I can tell, the style guide does not clearly define what order to put the following items in and reaching a consensus for consistencies sake would be great.
>
> a/c.h a/c_b.h a/c_x.h a_b/c.h a_x/c.h
>
> Some potential orderings:
>
> Unix "sort" order:
> a/c.h
> a/c_b.h
> a/c_x.h
> a_b/c.h
> a_x/c.h

This agrees with path-component-wise sorting, which I have so far assumed to be our style rule (but realizing at this point without good reason...)


>
> Short words at the end:
> a_b/c.h
> a_x/c.h
> a/c_b.h
> a/c_x.h
> a/c.h
>
> Omit non alpha-numeric order:
> a_b/c.h
> a/c_b.h
> a/c.h
> a/c_x.h
> a_x/c.h
>
> Omit non alpha-numeric within file/directory names:
> a/c_b.h
> a/c.h
> a/c_x.h
> a_b/c.h
> a_x/c.h
>
> --
> Steve
>

Peter Kasting

unread,
Apr 12, 2011, 2:55:38 PM4/12/11
to est...@chromium.org, van...@chromium.org, Chromium-dev
On Tue, Apr 12, 2011 at 11:50 AM, Evan Stade <est...@chromium.org> wrote:
On Tue, Apr 12, 2011 at 11:43 AM, Steve VanDeBogart> Unix "sort" order:
> a/c.h
> a/c_b.h
> a/c_x.h
> a_b/c.h
> a_x/c.h

I believe this is standard for chrome.

All files I'm aware of use this.

PK

William Chan (陈智昌)

unread,
Apr 12, 2011, 3:37:41 PM4/12/11
to mbelshe...@google.com, van...@chromium.org, Chromium-dev
On Tue, Apr 12, 2011 at 8:47 PM, Mike Belshe <mbe...@google.com> wrote:
On Tue, Apr 12, 2011 at 11:43 AM, Steve VanDeBogart <van...@chromium.org> wrote:
We've had some disagreement on the proper sort order of headers in my cube area.  As far as I can tell, the style guide does not clearly define what order to put the following items in and reaching a consensus for consistencies sake would be great.

I prefer no rule - too minor to matter.

+1

FWIW, I don't want to think about it, I just filter it through unix sort and forget it, and I don't care to comment on code reviews.

Marc-Antoine Ruel

unread,
Apr 12, 2011, 3:39:06 PM4/12/11
to will...@chromium.org, mbelshe...@google.com, van...@chromium.org, Chromium-dev
Le 12 avril 2011 15:37, William Chan (陈智昌) <will...@chromium.org> a écrit :
On Tue, Apr 12, 2011 at 8:47 PM, Mike Belshe <mbe...@google.com> wrote:
On Tue, Apr 12, 2011 at 11:43 AM, Steve VanDeBogart <van...@chromium.org> wrote:
We've had some disagreement on the proper sort order of headers in my cube area.  As far as I can tell, the style guide does not clearly define what order to put the following items in and reaching a consensus for consistencies sake would be great.

I prefer no rule - too minor to matter.

+1

FWIW, I don't want to think about it, I just filter it through unix sort and forget it, and I don't care to comment on code reviews.

Agreed, otherwise we'd have to specify sorting for:

a/02.h
a/1.h
à/0.h
A/0.h

:D

If someone still complain, simply reply: « I used ":sort u" ».

M-A 

Steve VanDeBogart

unread,
Apr 12, 2011, 3:43:42 PM4/12/11
to Marc-Antoine Ruel, William Chan (陈智昌), mbelshe...@google.com, Chromium-dev
Thanks all for replying.

I think we've reached consensus, that when you sort you should use unix sort, and in agreement with the current style guide ("Within each section it is nice to order the includes alphabetically.") sorting is not absolutely required.

--
Steve

Eric Seidel

unread,
Apr 12, 2011, 4:43:06 PM4/12/11
to van...@chromium.org, Marc-Antoine Ruel, William Chan (陈智昌), mbelshe...@google.com, Chromium-dev
One could simply write a tool to do the sort and then all argument
goes away. :) WebKit has a sort script for sorting the contents of
XCode project files, and we specify that headers should be sorted to
match the sort command, but no one has written a tool to do it yet,
sadly.

-eric

Denis Lagno

unread,
Apr 12, 2011, 4:54:10 PM4/12/11
to ese...@chromium.org, van...@chromium.org, Marc-Antoine Ruel, William Chan (陈智昌), mbelshe...@google.com, Chromium-dev
I used following shell script to sort include headers:

export LC_ALL=C
find chrome/browser/chromeos/ -name '*.h' -o -name '*.cc' \
| xargs grep -C1 '^#include' \
| awk -F: '$2 !~ "include" { prev=""; next } ($2 <= prev) {
print $1 } { prev=$2 }' \
| uniq \
| xargs -n1 sh -c 'cat "$1" \
| awk "{ tag=((/^#include/) \"_\" (/</)
\"_\" (/third.party/)); print tag \"\t\" \$0 }" \
| awk -vi=0 -F\\t "{ if (!/^1_0_/ || \$1 !=
prev) { ++i } } { printf \"%09d\t%s\n\",i,\$0; prev=\$1 }" \
| sort \
| sed "s/^[0-9]*\t[0-9]_[0-9]_[0-9]\t//" >
"$1".fixed; mv -f "$1".fixed "$1"' xxx

Nico Weber

unread,
Apr 12, 2011, 5:05:53 PM4/12/11
to dil...@chromium.org, ese...@chromium.org, van...@chromium.org, Marc-Antoine Ruel, William Chan (陈智昌), mbelshe...@google.com, Chromium-dev
There's also tools/sort-headers.py
Reply all
Reply to author
Forward
0 new messages