From: Alexey Dobriyan <adobriyan@gmail.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: corbet@lwn.net, workflows@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 8/9] CodingStyle: tell people how to split long "for" loops
Date: Mon, 12 May 2025 19:20:23 +0300 [thread overview]
Message-ID: <cefe24b6-c1a1-4fe4-826d-e08a856aa8e0@p183> (raw)
In-Reply-To: <20250510195603.37279af3@pumpkin>
On Sat, May 10, 2025 at 07:56:03PM +0100, David Laight wrote:
> On Fri, 9 May 2025 23:34:29 +0300
> Alexey Dobriyan <adobriyan@gmail.com> wrote:
>
> > Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> > ---
> > Documentation/process/coding-style.rst | 16 +++++++++++++++-
> > 1 file changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
> > index e17de69845ff..494ab3201112 100644
> > --- a/Documentation/process/coding-style.rst
> > +++ b/Documentation/process/coding-style.rst
> > @@ -183,7 +183,21 @@ Descendants are always substantially shorter than the parent and
> > are placed substantially to the right. A very commonly used style
> > is to align descendants to a function open parenthesis.
> >
> > -These same rules are applied to function headers with a long argument list.
> > +These same rules are applied to function prototypes with a long argument list.
> > +
> > +Very long ``for`` loops are split at the ``;`` characters making it easier
> > +to see which code goes to which clause:
> > +
> > +.. code-block:: c
> > +
> > + for (int i = 0;
> > + i < N;
> > + i += 1)
> > + {
> > + }
> > +
> > +Opening curly is placed on a separate line then to make it easier to tell
> > +loop body from iteration clause.
>
> Is that actually the style - I don't remember seeing it.
Check include/linux/list.h.
The point here is that it is either 1 line or 3 (not 2).
If you start splitting for loop there are 2 obvious points to do so.
> The location of the { isn't a significant problem with for (;;), it can be
> much worse elsewhere.
> In reality the 'align with the (' is what causes the problems, either
> double indenting (two tabs) or half indent (4 spaces - to annoy anyone who
> sets an editor to 4 space tabs) is more readable.
>
> For for (;;) loops I'll normally try moving the initialisation outside the
> loop
That's slightly bad -- variables could leak outside.
> and even put an inverted condition inside the loop to avoid long lines.
> If a #define all bets are off :-)
It applies even more inside #define: #define shits everything by 1 indent usually
so more chance of split line,
it is harder tom see semicolons because macro body is usually colored in
1 color not the normal way.
Do you like how xas_for_each() look like?
"for" macros in include/linux/list.h look mostly OK.
next prev parent reply other threads:[~2025-05-12 16:20 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-09 20:34 [PATCH 1/9] CodingStyle: make Documentation/CodingStyle into symlink Alexey Dobriyan
2025-05-09 20:34 ` [PATCH 2/9] CodingStyle: delete explicit numbering Alexey Dobriyan
2025-05-12 9:06 ` Jani Nikula
2025-05-09 20:34 ` [PATCH 3/9] CodingStyle: advise on using "sysctl" in sysctl variables Alexey Dobriyan
2025-05-09 20:34 ` [PATCH 4/9] CodingStyle: mention "typedef struct S {} S;" if typedef is used Alexey Dobriyan
2025-05-10 6:18 ` Greg KH
2025-05-13 18:34 ` Alexey Dobriyan
2025-05-10 10:47 ` Mauro Carvalho Chehab
2025-05-10 10:47 ` Mauro Carvalho Chehab
2025-05-13 18:37 ` Alexey Dobriyan
2025-05-09 20:34 ` [PATCH 5/9] CodingStyle: institute better inline assembly formatting Alexey Dobriyan
2025-05-13 19:41 ` David Laight
2025-05-09 20:34 ` [PATCH 6/9] CodingStyle: recommend static_assert/_Static_assert Alexey Dobriyan
2025-05-10 6:21 ` Greg KH
2025-05-13 18:41 ` Alexey Dobriyan
2025-05-13 19:40 ` David Laight
2025-05-09 20:34 ` [PATCH 7/9] CodingStyle: new variable declaration placement rule Alexey Dobriyan
2025-05-09 20:34 ` [PATCH 8/9] CodingStyle: tell people how to split long "for" loops Alexey Dobriyan
2025-05-10 18:56 ` David Laight
2025-05-12 16:20 ` Alexey Dobriyan [this message]
2025-05-12 16:59 ` Greg KH
2025-05-12 19:09 ` David Laight
2025-05-09 20:34 ` [PATCH 9/9] CodingStyle: flip the rule about curlies Alexey Dobriyan
2025-05-09 21:44 ` Randy Dunlap
2025-05-10 6:18 ` Greg KH
2025-05-12 16:43 ` Jeff Johnson
2025-05-12 16:56 ` Greg KH
2025-05-13 19:06 ` Alexey Dobriyan
2025-05-15 16:33 ` Jeff Johnson
2025-05-09 20:40 ` [PATCH 1/9] CodingStyle: make Documentation/CodingStyle into symlink Ozgur Kara
2025-05-10 10:05 ` Jonathan Corbet
2025-05-12 16:08 ` Alexey Dobriyan
2025-05-12 16:57 ` Greg KH
2025-05-13 18:32 ` Alexey Dobriyan
2025-05-14 18:55 ` Jonathan Corbet
2025-05-13 4:12 ` Al Viro
2025-05-13 18:33 ` Alexey Dobriyan
2025-05-13 19:04 ` Al Viro
2025-05-13 19:26 ` Alexey Dobriyan
2025-05-13 19:50 ` Al Viro
2025-05-19 16:21 ` Pavel Machek
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=cefe24b6-c1a1-4fe4-826d-e08a856aa8e0@p183 \
--to=adobriyan@gmail.com \
--cc=corbet@lwn.net \
--cc=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=workflows@vger.kernel.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