LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH/RFC] CodingStyle updates
@ 2006-12-07 8:48 Randy Dunlap
2006-12-07 8:54 ` Jesper Juhl
` (4 more replies)
0 siblings, 5 replies; 20+ messages in thread
From: Randy Dunlap @ 2006-12-07 8:48 UTC (permalink / raw)
To: lkml; +Cc: akpm, jesper.juhl
From: Randy Dunlap <randy.dunlap@oracle.com>
Add some kernel coding style comments, mostly pulled from emails
by Andrew Morton, Jesper Juhl, and Randy Dunlap.
- add paragraph on switch/case indentation
- add paragraph on multiple-assignments
- add more on Braces
- add section on Spaces
- add paragraph on function breaks in source files
- add paragraph on EXPORT_SYMBOL placement
- add section on /*-comment style, long-comment style, and data
declarations and comments
- correct some chapter number references that were missed when
chapters were renumbered
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
---
Documentation/CodingStyle | 107 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 102 insertions(+), 5 deletions(-)
--- linux-2.6.19-git7.orig/Documentation/CodingStyle
+++ linux-2.6.19-git7/Documentation/CodingStyle
@@ -35,12 +35,34 @@ In short, 8-char indents make things eas
benefit of warning you when you're nesting your functions too deep.
Heed that warning.
+The preferred way to ease multiple indentation levels in a switch
+statement is to align the "switch" and its subordinate "case" labels in
+the same column instead of "double-indenting" the "case" labels. E.g.:
+
+ switch (suffix) {
+ case 'G':
+ case 'g':
+ mem <<= 10;
+ case 'M':
+ case 'm':
+ mem << 10;
+ case 'K':
+ case 'k':
+ mem << 10;
+ default:
+ break;
+ }
+
+
Don't put multiple statements on a single line unless you have
something to hide:
if (condition) do_this;
do_something_everytime;
+Don't put multiple assignments on a single line either. Kernel
+coding style is super simple. Avoid tricky expressions.
+
Outside of comments, documentation and except in Kconfig, spaces are never
used for indentation, and the above example is deliberately broken.
@@ -69,7 +91,7 @@ void fun(int a, int b, int c)
next_statement;
}
- Chapter 3: Placing Braces
+ Chapter 3: Placing Braces and Spaces
The other issue that always comes up in C styling is the placement of
braces. Unlike the indent size, there are few technical reasons to
@@ -81,6 +103,20 @@ brace last on the line, and put the clos
we do y
}
+This applies to all non-function statement blocks (if, switch, for,
+while, do). E.g.:
+
+ switch (action) {
+ case KOBJ_ADD:
+ return "add";
+ case KOBJ_REMOVE:
+ return "remove";
+ case KOBJ_CHANGE:
+ return "change";
+ default:
+ return NULL;
+ }
+
However, there is one special case, namely functions: they have the
opening brace at the beginning of the next line, thus:
@@ -121,6 +157,40 @@ supply of new-lines on your screen is no
25-line terminal screens here), you have more empty lines to put
comments on.
+ 3.1: Spaces
+
+Linux kernel style for use of spaces depends (mostly) on
+function-versus-keyword usage. Use a space after (most) keywords.
+The notable exception is "sizeof", which looks like a function
+(and is usually used with parentheses in Linux, although they are
+not required in the language, as in: "sizeof struct file").
+So use a space after these keywords:
+ if, switch, case, for, do, while
+but not with "sizeof". E.g.,
+ s = sizeof(struct file);
+
+Do not add spaces around (inside) parenthesized expressions.
+This example is *bad*:
+
+ s = sizeof( struct file );
+
+When declaring pointer data or a function that returns a pointer type,
+the preferred use of '*' is adjacent to the data name or function name
+and not adjacent to the type name. Examples:
+
+ char *linux_banner;
+ unsigned long long memparse(char *ptr, char **retptr);
+ char *match_strdup(substring_t *s);
+
+Use one space around (on each side of) most binary operators, such as
+any of these:
+ = + - < > * / % | & ^ <= >= == !=
+
+but no space after unary operators:
+ sizeof ++ -- & * + - ~ ! defined
+
+and no space around the '.' unary operator.
+
Chapter 4: Naming
@@ -152,7 +222,7 @@ variable that is used to hold a temporar
If you are afraid to mix up your local variable names, you have another
problem, which is called the function-growth-hormone-imbalance syndrome.
-See next chapter.
+See chapter 6 (Functions).
Chapter 5: Typedefs
@@ -258,6 +328,16 @@ generally easily keep track of about 7 d
and it gets confused. You know you're brilliant, but maybe you'd like
to understand what you did 2 weeks from now.
+In source files, separate functions with one blank line.
+If the function is exported, the EXPORT* macro for it should follow
+immediately after the closing function brace line. E.g.:
+
+int system_is_up(void)
+{
+ return system_state == SYSTEM_RUNNING;
+}
+EXPORT_SYMBOL(system_is_up);
+
Chapter 7: Centralized exiting of functions
@@ -306,16 +386,33 @@ time to explain badly written code.
Generally, you want your comments to tell WHAT your code does, not HOW.
Also, try to avoid putting comments inside a function body: if the
function is so complex that you need to separately comment parts of it,
-you should probably go back to chapter 5 for a while. You can make
+you should probably go back to chapter 6 for a while. You can make
small comments to note or warn about something particularly clever (or
ugly), but try to avoid excess. Instead, put the comments at the head
of the function, telling people what it does, and possibly WHY it does
it.
-When commenting the kernel API functions, please use the kerneldoc format.
+When commenting the kernel API functions, please use the kernel-doc format.
See the files Documentation/kernel-doc-nano-HOWTO.txt and scripts/kernel-doc
for details.
+Linux style for comments is the pre-C99 "/* ... */" style.
+Don't use C99-style "// ..." comments.
+
+The preferred style for long (multi-line) comments is:
+
+ /*
+ * This is the preferred style for multi-line
+ * comments in the Linux kernel source code.
+ * Please use it consistently.
+ */
+
+It's also important to comment data, whether they are basic types or
+derived types. To this end, use just one data declaration per line
+(no commas for multiple data declarations). This leaves you room for
+a small comment on each item, explaining its use.
+
+
Chapter 9: You've made a mess of it
That's OK, we all do. You've probably been told by your long-time Unix
@@ -591,4 +688,4 @@ Kernel CodingStyle, by greg@kroah.com at
http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/
--
-Last updated on 30 April 2006.
+Last updated on 2006-December-06.
---
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 8:48 [PATCH/RFC] CodingStyle updates Randy Dunlap
@ 2006-12-07 8:54 ` Jesper Juhl
2006-12-07 11:11 ` Jan Engelhardt
` (3 subsequent siblings)
4 siblings, 0 replies; 20+ messages in thread
From: Jesper Juhl @ 2006-12-07 8:54 UTC (permalink / raw)
To: Randy Dunlap; +Cc: lkml, akpm
On 07/12/06, Randy Dunlap <randy.dunlap@oracle.com> wrote:
> From: Randy Dunlap <randy.dunlap@oracle.com>
>
> Add some kernel coding style comments, mostly pulled from emails
> by Andrew Morton, Jesper Juhl, and Randy Dunlap.
>
> - add paragraph on switch/case indentation
> - add paragraph on multiple-assignments
> - add more on Braces
> - add section on Spaces
> - add paragraph on function breaks in source files
> - add paragraph on EXPORT_SYMBOL placement
> - add section on /*-comment style, long-comment style, and data
> declarations and comments
> - correct some chapter number references that were missed when
> chapters were renumbered
>
> Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Acked-by: Jesper Juhl <jesper.juhl@gmail.com>
--
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 8:48 [PATCH/RFC] CodingStyle updates Randy Dunlap
2006-12-07 8:54 ` Jesper Juhl
@ 2006-12-07 11:11 ` Jan Engelhardt
2006-12-07 16:01 ` Chris Friesen
2006-12-07 21:36 ` Randy Dunlap
2006-12-07 22:54 ` Alistair John Strachan
` (2 subsequent siblings)
4 siblings, 2 replies; 20+ messages in thread
From: Jan Engelhardt @ 2006-12-07 11:11 UTC (permalink / raw)
To: Randy Dunlap; +Cc: lkml, akpm, jesper.juhl
On Dec 7 2006 00:48, Randy Dunlap wrote:
>+The preferred way to ease multiple indentation levels in a switch
>+statement is to align the "switch" and its subordinate "case" labels in
>+the same column instead of "double-indenting" the "case" labels. E.g.:
>+
>+ switch (suffix) {
>+ case 'G':
>+ case 'g':
>+ mem <<= 10;
>+ case 'M':
>+ case 'm':
>+ mem << 10;
^^^^^^^^^^
Statement has no effect ;-)
>+ case 'K':
>+ case 'k':
>+ mem << 10;
Make that <<=.
>+Use one space around (on each side of) most binary operators, such as
>+any of these:
>+ = + - < > * / % | & ^ <= >= == !=
And the ternary operator ?:
>+but no space after unary operators:
>+ sizeof ++ -- & * + - ~ ! defined
And no space before these unary operators,
++ (postincrement) -- (postdecrement)
What keyword is "defined"? Did you have too much Perl coffee? :)
>+and no space around the '.' unary operator.
Same goes for ->
>+Linux style for comments is the pre-C99 "/* ... */" style.
Aka C89.
>+Don't use C99-style "// ..." comments.
>+
>+The preferred style for long (multi-line) comments is:
>+
>+ /*
>+ * This is the preferred style for multi-line
>+ * comments in the Linux kernel source code.
>+ * Please use it consistently.
>+ */
Description: Stars to the left with two almost blank (/*, */) lines.
-`J'
--
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 11:11 ` Jan Engelhardt
@ 2006-12-07 16:01 ` Chris Friesen
2006-12-07 18:27 ` Jan Engelhardt
2006-12-07 21:36 ` Randy Dunlap
1 sibling, 1 reply; 20+ messages in thread
From: Chris Friesen @ 2006-12-07 16:01 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: Randy Dunlap, lkml, akpm, jesper.juhl
Jan Engelhardt wrote:
> What keyword is "defined"? Did you have too much Perl coffee? :)
Maybe macro formatting?
#if defined(CONFIG_FOO)
Chris
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 16:01 ` Chris Friesen
@ 2006-12-07 18:27 ` Jan Engelhardt
2006-12-07 21:36 ` Randy Dunlap
0 siblings, 1 reply; 20+ messages in thread
From: Jan Engelhardt @ 2006-12-07 18:27 UTC (permalink / raw)
To: Chris Friesen; +Cc: Randy Dunlap, lkml, akpm, jesper.juhl
>> What keyword is "defined"? Did you have too much Perl coffee? :)
>
> Maybe macro formatting?
>
> #if defined(CONFIG_FOO)
Ah thanks for the hint. This also raises another stylistic aspect:
#ifdef XYZ over #if defined(XYZ) when there is only one macro to be
tested for.
-`J'
--
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 11:11 ` Jan Engelhardt
2006-12-07 16:01 ` Chris Friesen
@ 2006-12-07 21:36 ` Randy Dunlap
1 sibling, 0 replies; 20+ messages in thread
From: Randy Dunlap @ 2006-12-07 21:36 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: lkml, akpm, jesper.juhl
Jan Engelhardt wrote:
> On Dec 7 2006 00:48, Randy Dunlap wrote:
>> +The preferred way to ease multiple indentation levels in a switch
>> +statement is to align the "switch" and its subordinate "case" labels in
>> +the same column instead of "double-indenting" the "case" labels. E.g.:
>> +
>> + switch (suffix) {
>> + case 'G':
>> + case 'g':
>> + mem <<= 10;
>> + case 'M':
>> + case 'm':
>> + mem << 10;
> ^^^^^^^^^^
>
> Statement has no effect ;-)
Argh, thanks, fixed these.
And removed most fall-throughs to make it a better example.
>> +Use one space around (on each side of) most binary operators, such as
>> +any of these:
>> + = + - < > * / % | & ^ <= >= == !=
>
> And the ternary operator ?:
Added.
>> +but no space after unary operators:
>> + sizeof ++ -- & * + - ~ ! defined
>
> And no space before these unary operators,
> ++ (postincrement) -- (postdecrement)
>
> What keyword is "defined"? Did you have too much Perl coffee? :)
>
>> +and no space around the '.' unary operator.
>
> Same goes for ->
Added.
>> +Linux style for comments is the pre-C99 "/* ... */" style.
>
> Aka C89.
Changed.
>> +Don't use C99-style "// ..." comments.
>> +
>> +The preferred style for long (multi-line) comments is:
>> +
>> + /*
>> + * This is the preferred style for multi-line
>> + * comments in the Linux kernel source code.
>> + * Please use it consistently.
>> + */
>
> Description: Stars to the left with two almost blank (/*, */) lines.
Added.
Thanks. Will resend later today...
--
~Randy
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 18:27 ` Jan Engelhardt
@ 2006-12-07 21:36 ` Randy Dunlap
0 siblings, 0 replies; 20+ messages in thread
From: Randy Dunlap @ 2006-12-07 21:36 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: Chris Friesen, lkml, akpm, jesper.juhl
Jan Engelhardt wrote:
>>> What keyword is "defined"? Did you have too much Perl coffee? :)
>> Maybe macro formatting?
>>
>> #if defined(CONFIG_FOO)
Yes, that's it.
> Ah thanks for the hint. This also raises another stylistic aspect:
>
> #ifdef XYZ over #if defined(XYZ) when there is only one macro to be
> tested for.
I'm not sure that we care enough to put it into CodingStyle.
--
~Randy
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 8:48 [PATCH/RFC] CodingStyle updates Randy Dunlap
2006-12-07 8:54 ` Jesper Juhl
2006-12-07 11:11 ` Jan Engelhardt
@ 2006-12-07 22:54 ` Alistair John Strachan
2006-12-07 23:00 ` Randy Dunlap
2006-12-14 22:38 ` David Weinehall
2006-12-14 23:33 ` Scott Preece
4 siblings, 1 reply; 20+ messages in thread
From: Alistair John Strachan @ 2006-12-07 22:54 UTC (permalink / raw)
To: Randy Dunlap; +Cc: lkml, akpm, jesper.juhl
Hi Randy,
On Thursday 07 December 2006 08:48, Randy Dunlap wrote:
[snip]
> + 3.1: Spaces
> +
> +Linux kernel style for use of spaces depends (mostly) on
> +function-versus-keyword usage. Use a space after (most) keywords.
> +The notable exception is "sizeof", which looks like a function
> +(and is usually used with parentheses in Linux, although they are
> +not required in the language, as in: "sizeof struct file").
> +So use a space after these keywords:
> + if, switch, case, for, do, while
> +but not with "sizeof". E.g.,
> + s = sizeof(struct file);
> +
> +Do not add spaces around (inside) parenthesized expressions.
> +This example is *bad*:
> +
> + s = sizeof( struct file );
> +
> +When declaring pointer data or a function that returns a pointer type,
> +the preferred use of '*' is adjacent to the data name or function name
> +and not adjacent to the type name. Examples:
> +
> + char *linux_banner;
> + unsigned long long memparse(char *ptr, char **retptr);
> + char *match_strdup(substring_t *s);
> +
> +Use one space around (on each side of) most binary operators, such as
> +any of these:
> + = + - < > * / % | & ^ <= >= == !=
> +
> +but no space after unary operators:
> + sizeof ++ -- & * + - ~ ! defined
You could mention typeof too, which is a keyword but should be done like
sizeof.
--
Cheers,
Alistair.
Final year Computer Science undergraduate.
1F2 55 South Clerk Street, Edinburgh, UK.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 22:54 ` Alistair John Strachan
@ 2006-12-07 23:00 ` Randy Dunlap
2006-12-07 23:06 ` David Miller
2006-12-07 23:23 ` Jan Engelhardt
0 siblings, 2 replies; 20+ messages in thread
From: Randy Dunlap @ 2006-12-07 23:00 UTC (permalink / raw)
To: Alistair John Strachan; +Cc: lkml, akpm, jesper.juhl
Alistair John Strachan wrote:
>> +but no space after unary operators:
>> + sizeof ++ -- & * + - ~ ! defined
>
> You could mention typeof too, which is a keyword but should be done like
> sizeof.
Hm, is that a gcc-ism? It's not listed in the C99 spec.
Are there other gcc-isms that I should add?
Thanks.
--
~Randy
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 23:00 ` Randy Dunlap
@ 2006-12-07 23:06 ` David Miller
2006-12-07 23:15 ` Randy Dunlap
2006-12-07 23:23 ` Jan Engelhardt
1 sibling, 1 reply; 20+ messages in thread
From: David Miller @ 2006-12-07 23:06 UTC (permalink / raw)
To: randy.dunlap; +Cc: s0348365, linux-kernel, akpm, jesper.juhl
From: Randy Dunlap <randy.dunlap@oracle.com>
Date: Thu, 07 Dec 2006 15:00:31 -0800
> Alistair John Strachan wrote:
>
> >> +but no space after unary operators:
> >> + sizeof ++ -- & * + - ~ ! defined
> >
> > You could mention typeof too, which is a keyword but should be done like
> > sizeof.
>
> Hm, is that a gcc-ism? It's not listed in the C99 spec.
>
> Are there other gcc-isms that I should add?
Perhaps you should add typeof and alignof, for starters.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 23:06 ` David Miller
@ 2006-12-07 23:15 ` Randy Dunlap
0 siblings, 0 replies; 20+ messages in thread
From: Randy Dunlap @ 2006-12-07 23:15 UTC (permalink / raw)
To: David Miller; +Cc: s0348365, linux-kernel, akpm, jesper.juhl
On Thu, 07 Dec 2006 15:06:35 -0800 (PST) David Miller wrote:
> From: Randy Dunlap <randy.dunlap@oracle.com>
> Date: Thu, 07 Dec 2006 15:00:31 -0800
>
> > Alistair John Strachan wrote:
> >
> > >> +but no space after unary operators:
> > >> + sizeof ++ -- & * + - ~ ! defined
> > >
> > > You could mention typeof too, which is a keyword but should be done like
> > > sizeof.
> >
> > Hm, is that a gcc-ism? It's not listed in the C99 spec.
> >
> > Are there other gcc-isms that I should add?
>
> Perhaps you should add typeof and alignof, for starters.
OK, I added both of those. Thanks.
Will resend soon.
---
~Randy
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 23:00 ` Randy Dunlap
2006-12-07 23:06 ` David Miller
@ 2006-12-07 23:23 ` Jan Engelhardt
1 sibling, 0 replies; 20+ messages in thread
From: Jan Engelhardt @ 2006-12-07 23:23 UTC (permalink / raw)
To: Randy Dunlap; +Cc: Alistair John Strachan, lkml, akpm, jesper.juhl
On Dec 7 2006 15:00, Randy Dunlap wrote:
>
>> > +but no space after unary operators:
>> > + sizeof ++ -- & * + - ~ ! defined
>>
>> You could mention typeof too, which is a keyword but should be done like
>> sizeof.
>
> Hm, is that a gcc-ism? It's not listed in the C99 spec.
>
> Are there other gcc-isms that I should add?
__attribute__(()) perhaps, which is often seen in kernel code.
-fno-gnu-keywords
Do not recognize "typeof" as a keyword, so that code can use this
word as an identifier. You can use the keyword "__typeof__"
instead. -ansi implies -fno-gnu-keywords.
Ergo it's a GNUism/GCCism. As long as <whatever> is used in kernel code,
it should be documented.
-`J'
--
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 8:48 [PATCH/RFC] CodingStyle updates Randy Dunlap
` (2 preceding siblings ...)
2006-12-07 22:54 ` Alistair John Strachan
@ 2006-12-14 22:38 ` David Weinehall
2006-12-14 22:42 ` Randy Dunlap
2006-12-14 23:33 ` Scott Preece
4 siblings, 1 reply; 20+ messages in thread
From: David Weinehall @ 2006-12-14 22:38 UTC (permalink / raw)
To: Randy Dunlap; +Cc: lkml, akpm, jesper.juhl
On Thu, Dec 07, 2006 at 12:48:38AM -0800, Randy Dunlap wrote:
[snip]
> +but no space after unary operators:
> + sizeof ++ -- & * + - ~ ! defined
Uhm, that doesn't compute... If you don't put a space after sizeof,
the program won't compile.
int c;
printf("%d", sizeofc);
Options are:
sizeof c
sizeof(c)
or
sizeof (c)
If you take sizeof the type rather than the variable, the options are
sizeof(int)
or
sizeof (int)
[snip]
Regards: David Weinehall
--
/) David Weinehall <tao@acc.umu.se> /) Northern lights wander (\
// Maintainer of the v2.0 kernel // Dance across the winter sky //
\) http://www.acc.umu.se/~tao/ (/ Full colour fire (/
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-14 22:38 ` David Weinehall
@ 2006-12-14 22:42 ` Randy Dunlap
2006-12-15 0:07 ` Robert P. J. Day
0 siblings, 1 reply; 20+ messages in thread
From: Randy Dunlap @ 2006-12-14 22:42 UTC (permalink / raw)
To: Randy Dunlap, lkml, akpm, jesper.juhl
David Weinehall wrote:
> On Thu, Dec 07, 2006 at 12:48:38AM -0800, Randy Dunlap wrote:
>
> [snip]
>
>> +but no space after unary operators:
>> + sizeof ++ -- & * + - ~ ! defined
>
> Uhm, that doesn't compute... If you don't put a space after sizeof,
> the program won't compile.
>
> int c;
> printf("%d", sizeofc);
Uh, we prefer not to see "sizeof c". IOW, we prefer to have
the parentheses use all the time. Maybe I need to say that better?
> Options are:
>
> sizeof c
> sizeof(c)
>
> or
>
> sizeof (c)
>
> If you take sizeof the type rather than the variable, the options are
>
> sizeof(int)
>
> or
>
> sizeof (int)
>
> [snip]
>
>
> Regards: David Weinehall
--
~Randy
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-07 8:48 [PATCH/RFC] CodingStyle updates Randy Dunlap
` (3 preceding siblings ...)
2006-12-14 22:38 ` David Weinehall
@ 2006-12-14 23:33 ` Scott Preece
2006-12-14 23:43 ` Randy Dunlap
4 siblings, 1 reply; 20+ messages in thread
From: Scott Preece @ 2006-12-14 23:33 UTC (permalink / raw)
To: Randy Dunlap; +Cc: lkml, akpm, jesper.juhl
> Outside of comments, documentation and except in Kconfig, spaces are never
> used for indentation, and the above example is deliberately broken.
---
I realize it isn't text you added, but what's that supposed to mean?
Surely the 8-character indents are made up of spaces. Does it mean
"spaces other than 8-space blocks"? In any case, how does it synch
with the following chapter's statement that continuations " are placed
substantially to the right" - isn't that done with spaces, too?
Or am I just totally spacing out on what was meant?
scott
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-14 23:33 ` Scott Preece
@ 2006-12-14 23:43 ` Randy Dunlap
2006-12-14 23:54 ` Scott Preece
0 siblings, 1 reply; 20+ messages in thread
From: Randy Dunlap @ 2006-12-14 23:43 UTC (permalink / raw)
To: Scott Preece; +Cc: lkml, akpm, jesper.juhl
Scott Preece wrote:
[1]
>> Outside of comments, documentation and except in Kconfig, spaces are
>> never
>> used for indentation, and the above example is deliberately broken.
> ---
>
> I realize it isn't text you added, but what's that supposed to mean?
> Surely the 8-character indents are made up of spaces. Does it mean
No, the 8-character indents are made of one ASCII TAB character.
> "spaces other than 8-space blocks"? In any case, how does it synch
> with the following chapter's statement that continuations " are placed
> substantially to the right" - isn't that done with spaces, too?
That's usually (preferably) done with tab(s). Sometimes it is done
with a few spaces instead. (and we put up with it :)
> Or am I just totally spacing out on what was meant?
I take [1] to mean that this example:
if (condition) do_this;
do_something_everytime;
is broken in at least 3 ways:
1/ do_this(); should be on a separate line;
2/ do_something_everytime() should not be indented more than the "if"
above it; and
3/ *if* do_something_everytime() were to be indented more than it is,
it should be done with a tab, not spaces.
--
~Randy
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-14 23:43 ` Randy Dunlap
@ 2006-12-14 23:54 ` Scott Preece
0 siblings, 0 replies; 20+ messages in thread
From: Scott Preece @ 2006-12-14 23:54 UTC (permalink / raw)
To: Randy Dunlap; +Cc: lkml, akpm, jesper.juhl
On 12/14/06, Randy Dunlap <randy.dunlap@oracle.com> wrote:
> Scott Preece wrote:
> [1]
> >> Outside of comments, documentation and except in Kconfig, spaces are
> >> never
> >> used for indentation, and the above example is deliberately broken.
> > ---
> >
> > I realize it isn't text you added, but what's that supposed to mean?
> > Surely the 8-character indents are made up of spaces. Does it mean
>
> No, the 8-character indents are made of one ASCII TAB character.
----
Probably should say so, then. As it is, the only way to figure that
out (other than loking at code (:)) is to infer it from the .emacs
example, which doesn't come until 8 chapters later in the document.
Maybe:
Outside of comments, documentation, and Kconfig, use TAB characters
for indentation. Spaces are never used for indentation, and the above
example is deliberately broken in several ways, including use of
spaces.
scott
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-14 22:42 ` Randy Dunlap
@ 2006-12-15 0:07 ` Robert P. J. Day
2006-12-15 0:26 ` Randy Dunlap
0 siblings, 1 reply; 20+ messages in thread
From: Robert P. J. Day @ 2006-12-15 0:07 UTC (permalink / raw)
To: Randy Dunlap; +Cc: lkml, akpm, jesper.juhl
On Thu, 14 Dec 2006, Randy Dunlap wrote:
> David Weinehall wrote:
> > On Thu, Dec 07, 2006 at 12:48:38AM -0800, Randy Dunlap wrote:
> >
> > [snip]
> >
> > > +but no space after unary operators:
> > > + sizeof ++ -- & * + - ~ ! defined
> >
> > Uhm, that doesn't compute... If you don't put a space after sizeof,
> > the program won't compile.
> >
> > int c;
> > printf("%d", sizeofc);
>
> Uh, we prefer not to see "sizeof c". IOW, we prefer to have the
> parentheses use all the time. Maybe I need to say that better?
here's a *really* rough first pass, i'm sure the end result would need
some hand tweaking:
=============================================
#!/bin/sh
DIR=$1
#
# Put in missing parentheses.
#
for f in $(grep -Erl "sizeof [^\(]" ${DIR}) ; do
echo $f
perl -pi -e "s/sizeof ([*]?[A-Za-z0-9_>\[\]\.-]+)( *)/sizeof\(\1\)\2/g" $f
done
#
# Delete possible space between "sizeof" and "(".
#
for f in $(grep -rl "sizeof (" ${DIR}) ; do
perl -pi -e "s/sizeof \(/sizeof\(/g" $f
done
#
# Delete obnoxious spaces inside parentheses.
#
for f in $(grep -rl "sizeof( " ${DIR}) ; do
perl -pi -e "s/sizeof\( *([^ \)]+) *\)/sizeof\(\1\)/g" $f
done
===========================================
rday
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-15 0:07 ` Robert P. J. Day
@ 2006-12-15 0:26 ` Randy Dunlap
2006-12-15 0:44 ` Robert P. J. Day
0 siblings, 1 reply; 20+ messages in thread
From: Randy Dunlap @ 2006-12-15 0:26 UTC (permalink / raw)
To: Robert P. J. Day; +Cc: lkml, akpm, jesper.juhl
On Thu, 14 Dec 2006 19:07:27 -0500 (EST) Robert P. J. Day wrote:
> On Thu, 14 Dec 2006, Randy Dunlap wrote:
>
> > David Weinehall wrote:
> > > On Thu, Dec 07, 2006 at 12:48:38AM -0800, Randy Dunlap wrote:
> > >
> > > [snip]
> > >
> > > > +but no space after unary operators:
> > > > + sizeof ++ -- & * + - ~ ! defined
> > >
> > > Uhm, that doesn't compute... If you don't put a space after sizeof,
> > > the program won't compile.
> > >
> > > int c;
> > > printf("%d", sizeofc);
> >
> > Uh, we prefer not to see "sizeof c". IOW, we prefer to have the
> > parentheses use all the time. Maybe I need to say that better?
>
> here's a *really* rough first pass, i'm sure the end result would need
> some hand tweaking:
You can certainly send such (generated) patches to Andrew or other
subsystem maintainers if you'd like, but I'm more interested in
not adding more crud to the tree in the future.
IOW, sure, we prefer sizeof(foo) to sizeof foo, but the latter isn't
killing us. If someone is there making other changes, it would be
OK to change that also.
Compare: http://lkml.org/lkml/2006/12/7/191
---
~Randy
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH/RFC] CodingStyle updates
2006-12-15 0:26 ` Randy Dunlap
@ 2006-12-15 0:44 ` Robert P. J. Day
0 siblings, 0 replies; 20+ messages in thread
From: Robert P. J. Day @ 2006-12-15 0:44 UTC (permalink / raw)
To: Randy Dunlap; +Cc: lkml, akpm, jesper.juhl
On Thu, 14 Dec 2006, Randy Dunlap wrote:
> On Thu, 14 Dec 2006 19:07:27 -0500 (EST) Robert P. J. Day wrote:
>
> > On Thu, 14 Dec 2006, Randy Dunlap wrote:
> >
> > > David Weinehall wrote:
> > > > On Thu, Dec 07, 2006 at 12:48:38AM -0800, Randy Dunlap wrote:
> > > >
> > > > [snip]
> > > >
> > > > > +but no space after unary operators:
> > > > > + sizeof ++ -- & * + - ~ ! defined
> > > >
> > > > Uhm, that doesn't compute... If you don't put a space after sizeof,
> > > > the program won't compile.
> > > >
> > > > int c;
> > > > printf("%d", sizeofc);
> > >
> > > Uh, we prefer not to see "sizeof c". IOW, we prefer to have the
> > > parentheses use all the time. Maybe I need to say that better?
> >
> > here's a *really* rough first pass, i'm sure the end result would need
> > some hand tweaking:
>
> You can certainly send such (generated) patches to Andrew or other
> subsystem maintainers if you'd like, but I'm more interested in not
> adding more crud to the tree in the future.
>
> IOW, sure, we prefer sizeof(foo) to sizeof foo, but the latter isn't
> killing us. If someone is there making other changes, it would be
> OK to change that also.
the advantage to standardizing what's there is that it makes it easier
to make subsequent changes. as a perfect example, because there are
several variations to the use of "sizeof", trying to catch every
combination that might be replaceable by the use of ARRAY_SIZE() is
just that much harder since you'd have to (as i had to) use regular
expressions to check for every variant -- parentheses or no
parentheses? space after the word or not? internal spaces within the
parentheses?
all that variation makes global changes for more useful stuff a real
pain.
rday
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2006-12-15 0:49 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-07 8:48 [PATCH/RFC] CodingStyle updates Randy Dunlap
2006-12-07 8:54 ` Jesper Juhl
2006-12-07 11:11 ` Jan Engelhardt
2006-12-07 16:01 ` Chris Friesen
2006-12-07 18:27 ` Jan Engelhardt
2006-12-07 21:36 ` Randy Dunlap
2006-12-07 21:36 ` Randy Dunlap
2006-12-07 22:54 ` Alistair John Strachan
2006-12-07 23:00 ` Randy Dunlap
2006-12-07 23:06 ` David Miller
2006-12-07 23:15 ` Randy Dunlap
2006-12-07 23:23 ` Jan Engelhardt
2006-12-14 22:38 ` David Weinehall
2006-12-14 22:42 ` Randy Dunlap
2006-12-15 0:07 ` Robert P. J. Day
2006-12-15 0:26 ` Randy Dunlap
2006-12-15 0:44 ` Robert P. J. Day
2006-12-14 23:33 ` Scott Preece
2006-12-14 23:43 ` Randy Dunlap
2006-12-14 23:54 ` Scott Preece
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).