From: Yury Norov <ynorov@caviumnetworks.com>
To: Joe Perches <joe@perches.com>
Cc: Kien Ha <kienha9922@gmail.com>,
linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org,
Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] Fix line too long warning
Date: Sun, 29 Oct 2017 21:34:57 +0300 [thread overview]
Message-ID: <20171029183457.xibbcvuduexv25fd@yury-thinkpad> (raw)
In-Reply-To: <1509298107.26592.26.camel@perches.com>
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@caviumnetworks.com>
prev parent reply other threads:[~2017-10-29 18:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-29 2:46 Kien Ha
2017-10-29 15:19 ` Joe Perches
2017-10-29 15:54 ` Yury Norov
2017-10-29 16:29 ` Yury Norov
2017-10-29 17:22 ` Kien Ha
2017-10-29 17:28 ` Joe Perches
2017-10-29 18:34 ` Yury Norov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171029183457.xibbcvuduexv25fd@yury-thinkpad \
--to=ynorov@caviumnetworks.com \
--cc=akpm@linux-foundation.org \
--cc=devel@driverdev.osuosl.org \
--cc=joe@perches.com \
--cc=kienha9922@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®