Sujet : Re: Which code style do you prefer the most?
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.cDate : 28. Feb 2025, 16:44:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vpsllj$3nd2i$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 28/02/2025 13:21, Richard Harnden wrote:
On 28/02/2025 11:54, David Brown wrote:
I don't go overboard on line length, but I do like to have more room than 80 characters, and I don't like hard limits. One factor in this is that a fair bit of my development is in C++ (on small embedded systems), and namespaces and classes mean that the average full identifier length is a fair amount longer than in C - thus it is natural for lines to be longer.
Have your mental margin-bell ding at around 75 characters, and aim to thow a new line as soon a you can?
No.
I often have a marker at column 96 on my editor (I find it a nice size for documentation - with prose text in documentation, I usually have automatic line breaks at that size). But I don't worry about going over that on occasion. 75 - 80 characters is far too small.
Since some people like statistics, I did a quick check on a project with 31 headers and 30 C files:
A histogram of the line column count is :
0 - 9 : 4586 = 18.98%
10 - 19 : 2021 = 8.36%
20 - 29 : 2758 = 11.41%
30 - 39 : 2494 = 10.32%
40 - 49 : 1677 = 6.94%
50 - 59 : 1052 = 4.35%
60 - 69 : 800 = 3.31%
70 - 79 : 7932 = 32.82%
80 - 89 : 398 = 1.65%
90 - 99 : 195 = 0.81%
100 - 109 : 159 = 0.66%
110 - 119 : 55 = 0.23%
120 - 129 : 28 = 0.12%
130 - 139 : 10 = 0.04%
150 - 159 : 1 = 0.00%
Total lines: 24166
35.78% of lines are over 72 characters, 3.5% are over 80 characters, 1.28% over 96 characters.
For a C++ project I checked, about 8.5% of lines are over 80 characters and 3.6% are over 96.
Attempting to limit my coding to 80 characters would make it significantly less clear. So I don't do that.