Skip to contentSkip to conversation

CodingStyle: remove what nowadays might be considered polemic

RFC PATCH In review Alexander Holler 2 participants 5 messages Dec 19, 2014 – Dec 22, 2014 Documentation

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 CodingStyle: remove what nowadays might be considered polemic

In times where things like checkpatch do exist and are mandated to be used, it would be easy to warn if too many levels of indentation are used (e.g. by counting leading tabs).

The paragraph before already says that more than 3 levels of indentation are bad, so the (removed) sentence nowadays only smells like an additional excuse or polemic (because you still could use an unholy number of e.g. 7 indentations, even within the limit of 80 chars).

---
 Documentation/CodingStyle | 4 ----
 1 file changed, 4 deletions(-)
Documentation/CodingStyle +0 -4
index 618a33c..8e96b14 100644
@@ -31,10 +31,6 @@ the code move too far to the right, and makes it hard to read on a
 more than 3 levels of indentation, you're screwed anyway, and should fix
 your program.
 
-In short, 8-char indents make things easier to read, and have the added
-benefit of warning you when you're nesting your functions too deep.
-Heed that warning.
-
 The preferred way to ease multiple indentation levels in a switch statement is
 to align the "switch" and its subordinate "case" labels in the same column
 instead of "double-indenting" the "case" labels.  E.g.:
Signature · 1 line
1.8.3.1
#1 lore raw

Am 19.12.2014 um 14:36 schrieb Alexander Holler:

Quoted 19 lines

In times where things like checkpatch do exist and are mandated to be used, it would be easy to warn if too many levels of indentation are used (e.g. by counting leading tabs).

The paragraph before already says that more than 3 levels of indentation are bad, so the (removed) sentence nowadays only smells like an additional excuse or polemic (because you still could use an unholy number of e.g. 7 indentations, even within the limit of 80 chars).

---
  Documentation/CodingStyle | 4 ----
  1 file changed, 4 deletions(-)
Documentation/CodingStyle +0 -0
index 618a33c..8e96b14 100644

Documentation/CodingStyle the code move too far to the right, and makes it hard to read on a · line 37

Quoted 7 lines
Documentation/CodingStyle +0 -4
@@ -31,10 +31,6 @@ the code move too far to the right, and makes it hard to read on a
  more than 3 levels of indentation, you're screwed anyway, and should fix
  your program.
 
-In short, 8-char indents make things easier to read, and have the added
-benefit of warning you when you're nesting your functions too deep.
-Heed that warning.
-

As I've become curious how many time the kernels source is already screwed, I did some quick and simple stats on 3.18:

find /tmp/linux/ -name '*.c' -exec grep -P "^\t+return " {} \; | sed -e 's/^\(\t\+\).*/\1/' | wc -L 72

Uups, there is maximum of 8 levels of intendation (not 9, the first tab isn't really an intendation as it's the leading tab of every code inside a function). Quiet the maximum which is possible with the 80 character limit. This made me even more curious, so I did:

[aholler@krabat ~]$ for i in $(seq 1 9); do echo -n "$i tabs: "; find /tmp/linux/ -name '*.c' -exec grep -P "^(\t){$i}return " {} \; | wc -l; done 1 tabs: 233866
2 tabs: 189497
3 tabs: 45874
4 tabs: 9473
5 tabs: 1738
6 tabs: 249
7 tabs: 51
8 tabs: 15
9 tabs: 5

That means the kernels source is already screwed at at least 2058 places And regarding that I've searched only for "<tab>return " this should be enough proof, that the limit of 80 chars doesn't really help in regard to levels of intendation.

Regards,

Alexander Holler

PS: Please don't start a discussion about the regexp I've used (if they aren't wrong). They are a result of 10 minutes and are not the topic of this mail (TIMTOWTDI).

PPS: If you are curious why I've spend the time to built and sent that silly patch: I've heared that wrong argument that a maximum line length of 80 chars helps in regard to keep the levels of intendation low once too often. And the source was much likely always the kernels CodingStyle document.

#2 lore raw

Am 21.12.2014 um 11:23 schrieb Alexander Holler:

Quoted 1 line

Uups, there is maximum of 8 levels of intendation (not 9, the first tab

And, please, no words about my broken english. Turn on your human fuzzy and do s/intendation/indentation/ ;)

Regards,

Alexander Holler

#3 lore raw
In reply to Alexander Holler
Quoted 4 lines · Alexander Holler

Am 19.12.2014 um 14:36 schrieb Alexander Holler:

Quoted 3 lines

In times where things like checkpatch do exist and are mandated to be used, it would be easy to warn if too many levels of indentation are used (e.g. by counting leading tabs).

checkpatch already does that looking for 6+ leading tabs then any statement that increases indentation.

Quoted 3 lines

I've heared that wrong argument that a maximum line length of 80 chars helps in regard to keep the levels of intendation low once too often.

I believe that argument correct.

helps is not a mandate.

The idea is that code that start far from the left (for some definition of far) is a signal that code could be refactored into more discrete chunks.

Without a limit to line length, more code would likely not have been as disaggregated as today.

#4 lore raw

Am 21.12.2014 um 18:09 schrieb Joe Perches:

Quoted 8 lines · Alexander Holler
Quoted 4 lines

Am 19.12.2014 um 14:36 schrieb Alexander Holler:

Quoted 3 lines

In times where things like checkpatch do exist and are mandated to be used, it would be easy to warn if too many levels of indentation are used (e.g. by counting leading tabs).

checkpatch already does that looking for 6+ leading tabs then any statement that increases indentation.

Oh, nice. I didn't know that.

Quoted 11 lines
Quoted 3 lines

I've heared that wrong argument that a maximum line length of 80 chars helps in regard to keep the levels of intendation low once too often.

I believe that argument correct.

helps is not a mandate.

The idea is that code that start far from the left (for some definition of far) is a signal that code could be refactored into more discrete chunks.

I think people just make variable and function names even more cryptic (shorter) in order to let them fit into the remaining free space. That seems to be easier for most than to refactor their code.

Regards,

Alexander Holler