From: Randy Dunlap <rdunlap@infradead.org>
To: Alexey Dobriyan <adobriyan@gmail.com>, corbet@lwn.net
Cc: workflows@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 9/9] CodingStyle: flip the rule about curlies
Date: Fri, 9 May 2025 14:44:31 -0700 [thread overview]
Message-ID: <1a03fcbd-151f-4bba-828f-d6aaf40e4116@infradead.org> (raw)
In-Reply-To: <20250509203430.3448-9-adobriyan@gmail.com>
On 5/9/25 1:34 PM, Alexey Dobriyan wrote:
> Require set of curlies {} in all if/else branches and all loops
> not matter how simple.
>
> The rationale is that maintaining curlies increases churn and make
> patches bigger when those if/else branches grow and shrink so it is
> easier to always add them.
>
> There are more important things in life than herding curlies.
>
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
> Documentation/process/coding-style.rst | 57 +++++++++++++++-----------
> 1 file changed, 32 insertions(+), 25 deletions(-)
>
> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
> index 494ab3201112..dc18ff40ebf2 100644
> --- a/Documentation/process/coding-style.rst
> +++ b/Documentation/process/coding-style.rst
> @@ -280,43 +280,50 @@ supply of new-lines on your screen is not a renewable resource (think
> 25-line terminal screens here), you have more empty lines to put
> comments on.
>
> -Do not unnecessarily use braces where a single statement will do.
> +All ``if``, ``for``, ``do``-``while``, ``switch`` and ``while`` statements
> +use braces even when C grammar allows to omit them:
>
> .. code-block:: c
>
> - if (condition)
> - action();
> -
> -and
> -
> -.. code-block:: c
> -
> - if (condition)
> - do_this();
> - else
> - do_that();
> -
> -This does not apply if only one branch of a conditional statement is a single
> -statement; in the latter case use braces in both branches:
> + if (cond) {
> + t();
> + }
>
> -.. code-block:: c
> + if (cond) {
> + t();
> + } else {
> + f();
> + }
>
> - if (condition) {
> - do_this();
> - do_that();
> + if (cond1) {
> + t1();
> + } else if (cond2) {
> + t2();
> } else {
> - otherwise();
> + f();
> }
>
> -Also, use braces when a loop contains more than a single simple statement:
> + for (int i = 0; i < N; i += 1) {
> + f(i);
> + }
>
> -.. code-block:: c
> + do {
> + g();
> + } while (0);
>
> - while (condition) {
> - if (test)
> - do_something();
> + switch (x) {
> + case X1:
> + f();
> }
>
> + while (1) {
> + f();
> + }
> +
> +In the future, code will be added and deleted but braces stay untouched.
> +Maitaining them when if branches, loop bodies grow and shrink is useless
Maintaining
> +busywork not even worthy of discussion.
> +
> Spaces
> ******
>
--
~Randy
next prev parent reply other threads:[~2025-05-09 21:44 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
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 [this message]
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=1a03fcbd-151f-4bba-828f-d6aaf40e4116@infradead.org \
--to=rdunlap@infradead.org \
--cc=adobriyan@gmail.com \
--cc=corbet@lwn.net \
--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