[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1a03fcbd-151f-4bba-828f-d6aaf40e4116@infradead.org>
Date: Fri, 9 May 2025 14:44:31 -0700
From: Randy Dunlap <rdunlap@...radead.org>
To: Alexey Dobriyan <adobriyan@...il.com>, corbet@....net
Cc: workflows@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 9/9] CodingStyle: flip the rule about curlies
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@...il.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
Powered by blists - more mailing lists