Re: [PATCH] Documentation/CodingStyle: Add an example for braces

2018-03-15 Thread Gary R Hook

On 03/15/2018 05:26 AM, Jani Nikula wrote:

On Wed, 14 Mar 2018, Gary R Hook  wrote:

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

Signed-off-by: Gary R Hook 
---
  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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Documentation/CodingStyle: Add an example for braces

2018-03-15 Thread Jani Nikula
On Wed, 14 Mar 2018, Gary R Hook  wrote:
> Add another example of required braces when using a compound statement in
> a loop.
>
> Signed-off-by: Gary R Hook 
> ---
>  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 majord...@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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Documentation/CodingStyle: Add an example for braces

2018-03-14 Thread Gary R Hook
Add another example of required braces when using a compound statement in
a loop.

Signed-off-by: Gary R Hook 
---
 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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Documentation/CodingStyle

2016-09-06 Thread Jonathan Corbet
On Sat, 3 Sep 2016 08:13:13 +0200
Bruno Raoult  wrote:

> I am new here, so feel free to tell me if I am wrong.

Welcome!

> I am participating to Eulyptula challenge, and of course had a look on
> Documentation/CodingStyle.
> 
> As I use GNU/Emacs (yes, I know, Evil Tool, according to Linus :-), I
> took the lines in Chapter 9, which are supposed to switch to kernel
> style if the source is in a given path.
> 
> I would like to do the following change, so that it works (both file
> path and linux path would be expanded the same way):
> 
> diff -up linux/Documentation/CodingStyle{.orig,}
> -
> --- linux/Documentation/CodingStyle.orig2016-09-03 08:05:37.0 
> +0200
> +++ linux/Documentation/CodingStyle2016-09-03 08:09:00.0 +0200
> @@ -524,7 +524,7 @@ values.  To do the latter, you can stick
> 
>  (add-hook 'c-mode-hook
>(lambda ()
> -(let ((filename (buffer-file-name)))
> +(let ((filename (expand-file-name (buffer-file-name
>;; Enable kernel mode for the appropriate files
>(when (and filename
>   (string-match (expand-file-name "~/src/linux-trees")
> -

Seems like a reasonable change.  Package it up as a proper patch as
described in SubmittingPatches and I'll apply it.

> I have a question, however: Which git tree should I use for such
> change ? Is there one relative to general documentation ?

As listed in the MAINTAINERS file:

  T:git git://git.lwn.net/linux.git docs-next

The CodingStyle document is not particularly dynamic, though; create a
patch against any recent kernel tree and it will apply just fine.

Thanks,

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


[PATCH] Documentation/CodingStyle

2016-09-03 Thread Bruno Raoult
Hi all,

I am new here, so feel free to tell me if I am wrong.

I am participating to Eulyptula challenge, and of course had a look on
Documentation/CodingStyle.

As I use GNU/Emacs (yes, I know, Evil Tool, according to Linus :-), I
took the lines in Chapter 9, which are supposed to switch to kernel
style if the source is in a given path.

I would like to do the following change, so that it works (both file
path and linux path would be expanded the same way):

diff -up linux/Documentation/CodingStyle{.orig,}
-
--- linux/Documentation/CodingStyle.orig2016-09-03 08:05:37.0 +0200
+++ linux/Documentation/CodingStyle2016-09-03 08:09:00.0 +0200
@@ -524,7 +524,7 @@ values.  To do the latter, you can stick

 (add-hook 'c-mode-hook
   (lambda ()
-(let ((filename (buffer-file-name)))
+(let ((filename (expand-file-name (buffer-file-name
   ;; Enable kernel mode for the appropriate files
   (when (and filename
  (string-match (expand-file-name "~/src/linux-trees")
-

I have a question, however: Which git tree should I use for such
change ? Is there one relative to general documentation ?

Thx,

br.

-- 
2 + 2 = 5, for very large values of 2.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html