Am Fr., 25. Mai 2018 um 18:40 Uhr schrieb Nico Huber nico.h@gmx.de:
o Set a hard limit around 100 chars (96 would be a nice number). o If a line doesn't contain a string literal, recommend a visible width <= 72 chars.
As Sam noted, it's hard to find tooling for that. But even with 96 characters clang-format's output looks much better than with 80.
One thing your transfer of the 72 char rule from continuous text to code doesn't take into account is that in code, individual lines often stand on their own. Consider the following block:
/* this function will fill the corresponding manufacturer */ void smbios_fill_dimm_manufacturer_from_id(uint16_t mod_id, struct smbios_type17 *t) { switch (mod_id) { case 0x2c80: t->manufacturer = smbios_add_string(t->eos, "Crucial"); break;
You'd never set a chapter in a book like this except maybe as an art project (that I'd decline to read). It's more readable after collapsing both the header and the add_string call to a single line each (two "carriage returns" in the middle of a statement less), despite passing the 72/80 character limit - except if you're on an old-fashioned terminal where part of the line is missing because it's too long now.
If people write chapters full of documentation in comments, by all means, let's limit that to a 72 character width (plus indentation for "/* "). Code formatters generally leave comments alone if they can help it, so that requires a different tool if we want to enforce it.
Patrick