Coding Style: should 80 chars per line be enough for everyone? [closed]
Most texts about coding style suggest to limit the length of a single line of code to at most 80 characters. However, the vast majority of common output devices is perfectly capable of exceeding this limit.
Why is this limit still advocated so strictly?
I.There are some cases where I can see an advantage due to increased readability, i.e. when returning the value of a boolean expression:
int is_foo(void *x)
{
开发者_运维百科 /* this would look like magic without linebreaks */
return (isint(*x) && \
(*x > 23) && \
(x != 0xDEADBEEF) && \
bar(*x));
}
II.
On the other hand, I don't see an urgent need to split the following statement across multiple lines:
snprintf(buf, BUFSIZ, "The big brown fox makes this LOC exceed its %d character limit", 80);
/* is IMO superior to: */
snprintf(buf, BUFSIZ, \
"The big brown fox makes this LOC exceed its %d character limit", \
80);
III.
And of course, there are cases where line splitting is a bad excuse for the lack of a clear structure of the code:
for (i = 0, *foo = bar, hash_init(); \
is_my_kungfu_already_that_old("bruce") && !list_empty(foo[i]); \
++i, ++j, --k, *p++ = *q--) {
/* whatever */
}
精彩评论