Follow-up Comment #2, bug #13848 (project freeciv):

> I don't like "switch" and "case" at same indentation
> level. I would vote for half indent step (2/2 = 1)
> for "case"

I do not feel that using one space indentation for
just this one area is very consistent with the two
space indentation rule used for most of the other
formatting rules. I think we should stick to units
of two spaces whenever indenting (or outdenting).

Using the attached perl script in the root of the
source tree:

$ grep switch `find -name \*.c` -A 3 -sn | ./

gives the following statistics for the indentation
of the case label relative to the preceeding switch

-6 = 1
-5 = 25
0 = 405
1 = 22
2 = 485
3 = 1
4 = 2
5 = 1
8 = 3

Most follow the new style rule (0 = 405) and the old
convention of having the case label indented and then
also the case body indented again (2 = 485).

(The weird stuff like -5 and 8 is due to tabs mixed
into the leading whitespace, macros, or (I assume)
typos. If you run the script it will show the context
for these outlier values.)

When making the rule for the coding style, I rejected
the second style (2 = 485) even though it has more
occurences because I feel it causes too much
indentation of most of the switch body relative to
the switch statement (most code would be 2 levels out
from the switch statement, in contrast to all other
code blocks).

I also prefer the 0 rule because if we realize that
case labels are essentially the same as goto labels,
then the rule is consistent with the goto label
outdenting rule (everything in the switch body is
indented by one level (2 spaces), and the goto
labels (case labels) are outdented back one level
making them align with the switch statement again).

Unfortunately since we do not have that many active
maintainers, if you are not convinced by my arguments
this issue would be at a standstill. In that case I
would be open to just not including any switch-case
indentation rule in the guide, thus implicitly
allowing any not completely insane convention used
by contributors (i.e. 0, your 1+1, or 2 would be ok).


(file #6117)

Additional Item Attachment:

File name:                 Size:0 KB


Reply to this item at:


  Message sent via/by Gna!

Freeciv-dev mailing list

Reply via email to