[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH 04/17] syntax-check: Don't forbid curly braces around single line condition body



On a Friday in 2020, Peter Krempa wrote:
This syntax rule doesn't make much sense, especially if there are so
much exceptions to it. Just remove it and adjust the coding style.

Signed-off-by: Peter Krempa <pkrempa redhat com>
---
build-aux/check-spacing.pl | 36 ------------------------------------

  before:

$ hyperfine 'make -C build/build-aux sc_spacing-check'
Benchmark #1: make -C build/build-aux sc_spacing-check
  Time (mean ± σ):      1.385 s ±  0.023 s    [User: 1.386 s, System: 0.022 s]
  Range (min … max):    1.356 s …  1.425 s    10 runs

  after:

$ hyperfine 'make -C build/build-aux sc_spacing-check'
Benchmark #1: make -C build/build-aux sc_spacing-check
  Time (mean ± σ):      1.215 s ±  0.025 s    [User: 1.217 s, System: 0.024 s]
  Range (min … max):    1.179 s …  1.259 s    10 runs

Yay, less wasted CPU cycles.

docs/coding-style.rst      |  8 ++++----
2 files changed, 4 insertions(+), 40 deletions(-)

diff --git a/docs/coding-style.rst b/docs/coding-style.rst
index 942caf4e09..44e5265a60 100644
--- a/docs/coding-style.rst
+++ b/docs/coding-style.rst
@@ -258,15 +258,15 @@ comment, although use of a semicolon is not currently rejected.
Curly braces
------------

-Omit the curly braces around an ``if``, ``while``, ``for`` etc.
-body only when both that body and the condition itself occupy a
-single line. In every other case we require the braces. This
+Curly braces around an ``if``, ``while``, ``for`` etc. can be omitted if the
+body and the condition itself occupy only a single line.
+In every other case we require the braces. This
ensures that it is trivially easy to identify a
single-\ *statement* loop: each has only one *line* in its body.

::

-  while (expr)             // single line body; {} is forbidden
+  while (expr)             // single line body; {} is optional
      single_line_stmt();

::


Reviewed-by: Ján Tomko <jtomko redhat com>

Jano

Attachment: signature.asc
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]