开发者

Coding Style: should 80 chars per line be enough for everyone? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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 */
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜