Looking at the coding style for Angband, I notice it's pretty much identical to the Linux coding style except for two minor differences:
Personally, I prefer 8 tabs over 4, but I'm happy to work with 4
Allowing 'break' and 'continue' to share the same line as a conditional statement, however, just feels wrong. From the example in the coding guidelines:
I've actually been caught out by code like this - thinking that the printf would get called when (i % 2) was non-zero.
To me, this:
is much clearer. Also, when the if condition is long and complex, it's easy to miss that there is actually a statement dangling off the end. Add to this that this 'exception' has been abused and there is code other than 'break' and 'continue' that has crept in, I think we should drop the exception entirely.
The only other 'issue' I have is breaking function parameters over multiple lines. When a function declaration or call hits 80 columns, we need to split the parameters over multiple lines. The Linux coding style does not cover specifically how this is handled - Angband's coding style does.
Personally, I prefer this:
Over this (which is the current Angband coding style):
Partly because if we add another parameter, we end up with:
Which, when you look at the patch, the addition of the new parameter is clear and precise
Compared to this:
Which looks plain ugly in a patch.
Lastly, I'm wondering what you all think of the following:
So far, so good - but what about when we add a comment? Do we do this:
Or this?
To be honest, I find both options a bit ugly - single-statement if/then results should be so obvious as to never need a comment
- Angband uses 4 tabs, Linux uses 8
- Angband permits 'break' and 'continue' to be placed on the same line as conditional statements
Personally, I prefer 8 tabs over 4, but I'm happy to work with 4
Allowing 'break' and 'continue' to share the same line as a conditional statement, however, just feels wrong. From the example in the coding guidelines:
Code:
/* Only print even numbers */
if (i % 2) continue;
/* Be clever */
printf("Aha!");
To me, this:
Code:
/* Only print even numbers */
if (i % 2)
continue;
/* Be clever */
printf("Aha!");
The only other 'issue' I have is breaking function parameters over multiple lines. When a function declaration or call hits 80 columns, we need to split the parameters over multiple lines. The Linux coding style does not cover specifically how this is handled - Angband's coding style does.
Personally, I prefer this:
Code:
foo(buf,
sizeof(buf),
FLAG_UNUSED,
FLAG_TIMED,
FLAG_DEAD);
Code:
foo(buf, sizeof(buf), FLAG_UNUSED,
FLAG_TIMED, FLAG_DEAD);
Code:
foo(buf,
sizeof(buf),
new_parameter,
FLAG_UNUSED,
FLAG_TIMED,
FLAG_DEAD);
Compared to this:
Code:
foo(buf, sizeof(buf), new_parameter,
FLAG_UNUSED, FLAG_TIMED, FLAG_DEAD);
Lastly, I'm wondering what you all think of the following:
Code:
if (some_variable)
do_something();
else
do_something_else();
Code:
if (some_variable)
/* Ideally we want this to happen */
do_something();
else
/* But we have a fallback strategy */
do_something_else();
Code:
if (some_variable) {
/* Ideally we want this to happen */
do_something();
} else {
/* But we have a fallback strategy */
do_something_else();
}
Comment