All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Documentation/CodingStyle: Add an example for braces
@ 2018-03-14 22:21 ` Gary R Hook
  0 siblings, 0 replies; 6+ messages in thread
From: Gary R Hook @ 2018-03-14 22:21 UTC (permalink / raw)
  To: linux-doc; +Cc: linux-kernel, corbet

Add another example of required braces when using a compound statement in
a loop.

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 Documentation/process/coding-style.rst |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
index a20b44a40ec4..d98deb62c400 100644
--- a/Documentation/process/coding-style.rst
+++ b/Documentation/process/coding-style.rst
@@ -200,6 +200,15 @@ statement; in the latter case use braces in both branches:
 		otherwise();
 	}
 
+Also, use braces when a loop contains more than a single simple statement:
+
+.. code-block:: c
+
+	while (condition) {
+		if (test)
+			do_something();
+	}
+
 3.1) Spaces
 ***********
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] Documentation/CodingStyle: Add an example for braces
@ 2018-03-14 22:21 ` Gary R Hook
  0 siblings, 0 replies; 6+ messages in thread
From: Gary R Hook @ 2018-03-14 22:21 UTC (permalink / raw)
  To: linux-doc; +Cc: linux-kernel, corbet

Add another example of required braces when using a compound statement in
a loop.

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 Documentation/process/coding-style.rst |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
index a20b44a40ec4..d98deb62c400 100644
--- a/Documentation/process/coding-style.rst
+++ b/Documentation/process/coding-style.rst
@@ -200,6 +200,15 @@ statement; in the latter case use braces in both branches:
 		otherwise();
 	}
 
+Also, use braces when a loop contains more than a single simple statement:
+
+.. code-block:: c
+
+	while (condition) {
+		if (test)
+			do_something();
+	}
+
 3.1) Spaces
 ***********
 

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Documentation/CodingStyle: Add an example for braces
  2018-03-14 22:21 ` Gary R Hook
@ 2018-03-15 10:26   ` Jani Nikula
  -1 siblings, 0 replies; 6+ messages in thread
From: Jani Nikula @ 2018-03-15 10:26 UTC (permalink / raw)
  To: Gary R Hook, linux-doc; +Cc: linux-kernel, corbet

On Wed, 14 Mar 2018, Gary R Hook <gary.hook@amd.com> wrote:
> Add another example of required braces when using a compound statement in
> a loop.
>
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>  Documentation/process/coding-style.rst |    9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
> index a20b44a40ec4..d98deb62c400 100644
> --- a/Documentation/process/coding-style.rst
> +++ b/Documentation/process/coding-style.rst
> @@ -200,6 +200,15 @@ statement; in the latter case use braces in both branches:
>  		otherwise();
>  	}
>  
> +Also, use braces when a loop contains more than a single simple statement:

Personally, I'd not limit this to loops.

	if (condition) {
        	if (another_condition)
                	action();
        }

You could argue the existing rule already covers these cases by
excluding selection and iteration statements from the "single statement"
in "Do not unnecessarily use braces where a single statement will do."

BR,
Jani.

> +
> +.. code-block:: c
> +
> +	while (condition) {
> +		if (test)
> +			do_something();
> +	}
> +
>  3.1) Spaces
>  ***********
>  
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-doc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Jani Nikula, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Documentation/CodingStyle: Add an example for braces
@ 2018-03-15 10:26   ` Jani Nikula
  0 siblings, 0 replies; 6+ messages in thread
From: Jani Nikula @ 2018-03-15 10:26 UTC (permalink / raw)
  To: Gary R Hook, linux-doc; +Cc: linux-kernel, corbet

On Wed, 14 Mar 2018, Gary R Hook <gary.hook@amd.com> wrote:
> Add another example of required braces when using a compound statement in
> a loop.
>
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>  Documentation/process/coding-style.rst |    9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
> index a20b44a40ec4..d98deb62c400 100644
> --- a/Documentation/process/coding-style.rst
> +++ b/Documentation/process/coding-style.rst
> @@ -200,6 +200,15 @@ statement; in the latter case use braces in both branches:
>  		otherwise();
>  	}
>  
> +Also, use braces when a loop contains more than a single simple statement:

Personally, I'd not limit this to loops.

	if (condition) {
        	if (another_condition)
                	action();
        }

You could argue the existing rule already covers these cases by
excluding selection and iteration statements from the "single statement"
in "Do not unnecessarily use braces where a single statement will do."

BR,
Jani.

> +
> +.. code-block:: c
> +
> +	while (condition) {
> +		if (test)
> +			do_something();
> +	}
> +
>  3.1) Spaces
>  ***********
>  
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-doc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Jani Nikula, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Documentation/CodingStyle: Add an example for braces
  2018-03-15 10:26   ` Jani Nikula
@ 2018-03-15 19:54     ` Gary R Hook
  -1 siblings, 0 replies; 6+ messages in thread
From: Gary R Hook @ 2018-03-15 19:54 UTC (permalink / raw)
  To: Jani Nikula, linux-doc; +Cc: linux-kernel, corbet

On 03/15/2018 05:26 AM, Jani Nikula wrote:
> On Wed, 14 Mar 2018, Gary R Hook <gary.hook@amd.com> wrote:
>> Add another example of required braces when using a compound statement in
>> a loop.
>>
>> Signed-off-by: Gary R Hook <gary.hook@amd.com>
>> ---
>>   Documentation/process/coding-style.rst |    9 +++++++++
>>   1 file changed, 9 insertions(+)
>>
>> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
>> index a20b44a40ec4..d98deb62c400 100644
>> --- a/Documentation/process/coding-style.rst
>> +++ b/Documentation/process/coding-style.rst
>> @@ -200,6 +200,15 @@ statement; in the latter case use braces in both branches:
>>   		otherwise();
>>   	}
>>   
>> +Also, use braces when a loop contains more than a single simple statement:
> 
> Personally, I'd not limit this to loops.
> 
> 	if (condition) {
>          	if (another_condition)
>                  	action();
>          }
> 
> You could argue the existing rule already covers these cases by
> excluding selection and iteration statements from the "single statement"
> in "Do not unnecessarily use braces where a single statement will do."

Define "statement"? There's a school of thought that uses semicolons to 
indicate a statement. I'm trying to eliminate any ambiguity by calling 
out compound statements as "more than one statement". Sure, semantics,
but in the interest of clarity. An additional sentence and example 
doesn't really cost much.

Thank you for your time. I've made some changes, and a v2 to follow shortly.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Documentation/CodingStyle: Add an example for braces
@ 2018-03-15 19:54     ` Gary R Hook
  0 siblings, 0 replies; 6+ messages in thread
From: Gary R Hook @ 2018-03-15 19:54 UTC (permalink / raw)
  To: Jani Nikula, linux-doc; +Cc: linux-kernel, corbet

On 03/15/2018 05:26 AM, Jani Nikula wrote:
> On Wed, 14 Mar 2018, Gary R Hook <gary.hook@amd.com> wrote:
>> Add another example of required braces when using a compound statement in
>> a loop.
>>
>> Signed-off-by: Gary R Hook <gary.hook@amd.com>
>> ---
>>   Documentation/process/coding-style.rst |    9 +++++++++
>>   1 file changed, 9 insertions(+)
>>
>> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
>> index a20b44a40ec4..d98deb62c400 100644
>> --- a/Documentation/process/coding-style.rst
>> +++ b/Documentation/process/coding-style.rst
>> @@ -200,6 +200,15 @@ statement; in the latter case use braces in both branches:
>>   		otherwise();
>>   	}
>>   
>> +Also, use braces when a loop contains more than a single simple statement:
> 
> Personally, I'd not limit this to loops.
> 
> 	if (condition) {
>          	if (another_condition)
>                  	action();
>          }
> 
> You could argue the existing rule already covers these cases by
> excluding selection and iteration statements from the "single statement"
> in "Do not unnecessarily use braces where a single statement will do."

Define "statement"? There's a school of thought that uses semicolons to 
indicate a statement. I'm trying to eliminate any ambiguity by calling 
out compound statements as "more than one statement". Sure, semantics,
but in the interest of clarity. An additional sentence and example 
doesn't really cost much.

Thank you for your time. I've made some changes, and a v2 to follow shortly.



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-03-15 19:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-14 22:21 [PATCH] Documentation/CodingStyle: Add an example for braces Gary R Hook
2018-03-14 22:21 ` Gary R Hook
2018-03-15 10:26 ` Jani Nikula
2018-03-15 10:26   ` Jani Nikula
2018-03-15 19:54   ` Gary R Hook
2018-03-15 19:54     ` Gary R Hook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.