Re: [PATCH] Fix line too long warning
From: Yury Norov
Date: Sun Oct 29 2017 - 14:35:16 EST
On Sun, Oct 29, 2017 at 10:28:27AM -0700, Joe Perches wrote:
> On Sun, 2017-10-29 at 18:54 +0300, Yury Norov wrote:
> > At second, and most important, refer Documentation/process/coding-style.rst:
> > Now, some people will claim that having 8-character indentations makes
> > the code move too far to the right, and makes it hard to read on a
> > 80-character terminal screen. The answer to that is that if you need
> > more than 3 levels of indentation, you're screwed anyway, and should fix
> > your program.
> >
> > The real problem here is not "line too long", but "indentation level too
> > big" - 5. And it worth to address real problem.
>
> Line length issues can be a combination of several factors:
>
> o identifier length
> o quantity of dereferences
> o indentation depth
> o code complexity
>
> 4 indentation depth levels are not a real issue.
> A significant percentage of lines in the kernel
> are 4 or more tab indent levels deep.
>
> checkpatch suggests that 6 or more is the depth level
> that should cause real concern.
>
> Here's a little breakdown of lines that start with
> a tab followed by a c90 keyword in the kernel
>
> $ git grep -P "^\t+(if|for|do|while|\}|else|switch|return|case|break|continue|goto)\b" -- "*.[ch]" | \
> cut -f2- -d":" | perl -p -e 's/(^\t+).*/\1/' | \
> sort | uniq -c | sort -rn | \
> awk '{total += $1; count[i++] = $1} END { for (j = 0; j < i; j++) { printf "%d\t%d\t%.2f%%\n", j + 1, count[j], count[j] / total * 100 }}'
> 1 1325462 52.19%
> 2 863007 33.98%
> 3 271844 10.70%
> 4 64009 2.52%
> 5 12502 0.49%
> 6 2199 0.09%
> 7 501 0.02%
> 8 166 0.01%
> 9 51 0.00%
> 10 20 0.00%
> 11 10 0.00%
> 12 4 0.00%
> 13 1 0.00%
>
> I think it could reasonably be argued that the
> indentation depth warning (DEEP_INDENTATION)
> should start at 5 and not at 6.
>
> ---
> scripts/checkpatch.pl | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 6bdd43d5dec5..923e4ff09d24 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3353,7 +3353,7 @@ sub process {
>
> my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
>
> - if ($line =~ /^\+\t{6,}/) {
> + if ($line =~ /^\+\t{5,}/) {
> WARN("DEEP_INDENTATION",
> "Too many leading tabs - consider code refactoring\n" . $herecurr);
> }
There are 2 different subjects here - this specific function in staging
driver and general considerations.
Regarding the function, it has very simple structure, and so deep indentation
level is definitely a symptom of bad design.
Regarding general considerations, the kernel is very complex, and I admit
that indentations deeper than 3 are unavoidable in some cases.
But we have coding style that insists on 3, and this rule is (probably ?)
written by Linus, so... :-)
Nevertheless, your patch is the step toward right direction, so if you
need my ack,
Acked-by: Yury Norov <ynorov@xxxxxxxxxxxxxxxxxx>