Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Which code style do you prefer the most? Date: Sun, 02 Mar 2025 05:52:07 -0800 Organization: A noiseless patient Spider Lines: 78 Message-ID: <86ldtnwneg.fsf@linuxsc.com> References: <87frk10w51.fsf@onesoftnet.eu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sun, 02 Mar 2025 14:52:11 +0100 (CET) Injection-Info: dont-email.me; posting-host="3262fa73ab11de5fd8cc37f0606a7eed"; logging-data="856971"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ZwvDCz35v8bmOEHraPK+NjyQuMUkHGCY=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:SudkUWY1No39mf49D/MPAiEpDRI= sha1:7Qva/dsSnYJA/nmPbiQ3orOnNGA= Xref: csiph.com comp.lang.c:390640 Janis Papanagnou writes: > On 27.02.2025 10:15, Lawrence D'Oliveiro wrote: > >> On Thu, 27 Feb 2025 09:38:40 +0100, Janis Papanagnou wrote: >> >>> Too deep indenting I consider to be a possible bad structuring >>> effect ... >> >> Would you consider half a dozen indentation levels to be too many? I >> frequently go that deep. > > To be honest, I've never counted them. So why should I suggest someone > else what's a "good" value. Programmers certainly should have got (or > develop) a feeling about what's acceptable and what's too much in their > own playground (or in project contexts where many people cooperate). > > But since you were asking I got curious; I pick one recent "C" source > from one of my toy projects and get this distribution of the amount of > indents > > 80 - // empty lines > 169 0 > 254 1 > 172 2 > 122 3 > 46 4 > 34 5 > 7 6 > 3 7 This measurement is an interesting idea. Gathering some statistics from what I expect is typical source for my own code, and ignoring: blank lines; lines that are flush left; and "non-code" lines; I get level percent percentile ===== ======= ========== 1 69.6 69.6 2 27.0 96.5 3 2.2 98.7 4 0.9 99.6 5 0.4 100.0 giving an average indentation of 1.36 levels. The numbers shown are calculated by considering the amount of leading white space in each line, and rounding up to an integral multiple of one indent level (which is four columns). There were some lines that had larger amounts of leading white space, but they were not lines that reflect normal indenting. > What would be your typical indent distribution in your "C" source code? Probably the numbers I gave above are typical. In most cases the code I write is very flat. For comparison here are the percentages for the previous list of numbers: level percent percentile ===== ======= ========== 1 39.8 39.8 2 27.0 66.8 3 19.1 85.9 4 7.2 93.1 5 5.3 98.4 6 1.1 99.5 7 0.5 100.0 giving an average indentation of 2.16 levels. > [a bunch of stuff about line widths] I almost never write C code with lines wider than 80 columns. The numbers shown above are gathered from source with all lines not more than 80 columns.