public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Question about style when converting from K&R to ANSI C.
@ 2003-06-01  5:56 Steven Cole
  2003-06-01  6:39 ` Arnaldo Carvalho de Melo
  2003-06-01 13:26 ` Larry McVoy
  0 siblings, 2 replies; 42+ messages in thread
From: Steven Cole @ 2003-06-01  5:56 UTC (permalink / raw)
  To: linux-kernel

Greetings all,

I've been converting the few files with old-style function prototypes to
ANSI C, and I would like to make sure the following is acceptable. 

Original form:

int
foo()
{
   	/* body here */
}	

Proposed conversion:

int foo(void)
{
   	/* body here */
}	

The above should be straightforward, but if there are any problems with
that, please holler.  I'll be sending patches through the maintainers
soon.

Steven


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01  5:56 Question about style when converting from K&R to ANSI C Steven Cole
@ 2003-06-01  6:39 ` Arnaldo Carvalho de Melo
  2003-06-01  6:43   ` Zwane Mwaikambo
  2003-06-01 13:26 ` Larry McVoy
  1 sibling, 1 reply; 42+ messages in thread
From: Arnaldo Carvalho de Melo @ 2003-06-01  6:39 UTC (permalink / raw)
  To: Steven Cole; +Cc: linux-kernel

Em Sat, May 31, 2003 at 11:56:16PM -0600, Steven Cole escreveu:
> Greetings all,
> 
> I've been converting the few files with old-style function prototypes to
> ANSI C, and I would like to make sure the following is acceptable. 
> 
> Original form:
> 
> int
> foo()
> {
>    	/* body here */
> }	
> 
> Proposed conversion:
> 
> int foo(void)
> {
>    	/* body here */
> }	
> 
> The above should be straightforward, but if there are any problems with
> that, please holler.  I'll be sending patches through the maintainers
> soon.

Perfect!

- Arnaldo

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01  6:39 ` Arnaldo Carvalho de Melo
@ 2003-06-01  6:43   ` Zwane Mwaikambo
  2003-06-01 13:14     ` Alan Cox
  0 siblings, 1 reply; 42+ messages in thread
From: Zwane Mwaikambo @ 2003-06-01  6:43 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Steven Cole, Linux Kernel

On Sun, 1 Jun 2003, Arnaldo Carvalho de Melo wrote:

> > The above should be straightforward, but if there are any problems with
> > that, please holler.  I'll be sending patches through the maintainers
> > soon.
> 
> Perfect!

Why not just do this then;

Index: linux-2.5/scripts/Lindent
===================================================================
RCS file: /home/cvs/linux-2.5/scripts/Lindent,v
retrieving revision 1.16
diff -u -p -B -r1.16 Lindent
--- linux-2.5/scripts/Lindent	31 May 2003 18:57:19 -0000	1.16
+++ linux-2.5/scripts/Lindent	1 Jun 2003 05:46:02 -0000
@@ -1,2 +1,2 @@
 #!/bin/sh
-indent -kr -i8 -ts8 -sob -l80 -ss -bs -psl "$@"
+indent -kr -i8 -ts8 -sob -l80 -ss -bs "$@"

-- 
function.linuxpower.ca

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01  6:43   ` Zwane Mwaikambo
@ 2003-06-01 13:14     ` Alan Cox
  2003-06-01 19:10       ` Zwane Mwaikambo
  0 siblings, 1 reply; 42+ messages in thread
From: Alan Cox @ 2003-06-01 13:14 UTC (permalink / raw)
  To: Zwane Mwaikambo
  Cc: Arnaldo Carvalho de Melo, Steven Cole, Linux Kernel Mailing List

On Sul, 2003-06-01 at 07:43, Zwane Mwaikambo wrote:
> --- linux-2.5/scripts/Lindent	31 May 2003 18:57:19 -0000	1.16
> +++ linux-2.5/scripts/Lindent	1 Jun 2003 05:46:02 -0000
> @@ -1,2 +1,2 @@
>  #!/bin/sh
> -indent -kr -i8 -ts8 -sob -l80 -ss -bs -psl "$@"
> +indent -kr -i8 -ts8 -sob -l80 -ss -bs "$@"

Take out the -l80 as well, it makes indent do horrific things to code,
and mangled 80 column wrapping is not the normal Linux style


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01  5:56 Question about style when converting from K&R to ANSI C Steven Cole
  2003-06-01  6:39 ` Arnaldo Carvalho de Melo
@ 2003-06-01 13:26 ` Larry McVoy
  2003-06-01 13:49   ` Willy Tarreau
                     ` (2 more replies)
  1 sibling, 3 replies; 42+ messages in thread
From: Larry McVoy @ 2003-06-01 13:26 UTC (permalink / raw)
  To: Steven Cole; +Cc: linux-kernel

On Sat, May 31, 2003 at 11:56:16PM -0600, Steven Cole wrote:
> Proposed conversion:
> 
> int foo(void)
> {
>    	/* body here */
> }	

Sometimes it is nice to be able to see function names with a 

	grep '^[a-zA-Z].*(' *.c

which is why I've always preferred

int
foo(void)
{
	/* body here */
}	

Is there some reason that I'm missing that the kernel folks like it the other
way?  
-- 
---
Larry McVoy              lm at bitmover.com          http://www.bitmover.com/lm

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 13:26 ` Larry McVoy
@ 2003-06-01 13:49   ` Willy Tarreau
  2003-06-01 14:06     ` Larry McVoy
  2003-06-01 13:53   ` Scott Robert Ladd
  2003-06-02  2:09   ` Linus Torvalds
  2 siblings, 1 reply; 42+ messages in thread
From: Willy Tarreau @ 2003-06-01 13:49 UTC (permalink / raw)
  To: Larry McVoy, Steven Cole, linux-kernel

Hi Larry !

On Sun, Jun 01, 2003 at 06:26:26AM -0700, Larry McVoy wrote:
> On Sat, May 31, 2003 at 11:56:16PM -0600, Steven Cole wrote:
> > Proposed conversion:
> > 
> > int foo(void)
> > {
> >    	/* body here */
> > }	
> 
> Sometimes it is nice to be able to see function names with a 
> 
> 	grep '^[a-zA-Z].*(' *.c

This will return 'int foo(void)', what's the problem ?

> which is why I've always preferred
> 
> int
> foo(void)
> {
> 	/* body here */
> }	
> 
> Is there some reason that I'm missing that the kernel folks like it the other
> way?  

It will only return 'foo(void)', and you won't find its return type.
Personally, I strongly prefer getting maximum information in one line, and
I find it useful to have the return type, the name and the args together.

If you still need the name and only the name, use some sed on the output :

   sed 's/^\([^ ]* \)*\([^]*\)(.*/\2/'

Cheers,
Willy

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 13:26 ` Larry McVoy
  2003-06-01 13:49   ` Willy Tarreau
@ 2003-06-01 13:53   ` Scott Robert Ladd
  2003-06-02  2:09   ` Linus Torvalds
  2 siblings, 0 replies; 42+ messages in thread
From: Scott Robert Ladd @ 2003-06-01 13:53 UTC (permalink / raw)
  To: Larry McVoy; +Cc: Steven Cole, linux-kernel

Larry McVoy wrote:
>>Proposed conversion:
>>
>>int foo(void)
>>{
>>   	/* body here */
>>}	
> 
> which is why I've always preferred
> 
> int
> foo(void)
> {
> 	/* body here */
> }	
> 
> Is there some reason that I'm missing that the kernel folks like it the other
> way?  

Just my personal opinion:

The return value is part of the function signature; placing it on a 
separate line implies a disconnect between the return value and the rest 
of the declaration.

It's a matter of psychology; your mileage may vary.

-- 
Scott Robert Ladd
Coyote Gulch Productions (http://www.coyotegulch.com)


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 13:49   ` Willy Tarreau
@ 2003-06-01 14:06     ` Larry McVoy
  2003-06-01 14:22       ` Willy Tarreau
                         ` (4 more replies)
  0 siblings, 5 replies; 42+ messages in thread
From: Larry McVoy @ 2003-06-01 14:06 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: Larry McVoy, Steven Cole, linux-kernel

> > Sometimes it is nice to be able to see function names with a 
> > 
> > 	grep '^[a-zA-Z].*(' *.c
> 
> This will return 'int foo(void)', what's the problem ?

You get a lot of other false hits, like globals.  I don't feel strongly
about this, I'm more wondering why this style was choosen.  The way
I showed is pretty common,  it's sort of the "Unix" way (it's how the
original Unix guys did it, how BSD did it, and how the GNU guys do it), so
it's a somewhat surprising difference.  I've never understood the logic.
The more I think about it the less I understand it, doing it that way
means you are more likely to have to wrap a function definition which
is ugly:

static inline int cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason)
{
}

vs

static inline int
cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason)
{
}

It may be just what you are used to but I also find that when reading lots
of code it is nice to have it look like

return type
function_name(args)

because the function_name() stands out more, it's always at the left side so
I tend to parse it a little more quickly.

Don't get me wrong, I'm not arguing that you should go reformat all your
code (I tend to agree with Linus, if it's not your code, don't stick your
fingers in there just because you want to reformat it).  All I'm doing
is trying to understand why in this instance did Linux diverage from 
common practice.  
-- 
---
Larry McVoy              lm at bitmover.com          http://www.bitmover.com/lm

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 14:06     ` Larry McVoy
@ 2003-06-01 14:22       ` Willy Tarreau
  2003-06-01 15:02       ` Steven Cole
                         ` (3 subsequent siblings)
  4 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2003-06-01 14:22 UTC (permalink / raw)
  To: Larry McVoy, Willy Tarreau, Larry McVoy, Steven Cole,
	linux-kernel

On Sun, Jun 01, 2003 at 07:06:02AM -0700, Larry McVoy wrote:
 
> It may be just what you are used to but I also find that when reading lots
> of code it is nice to have it look like

Well, I think it's the _main_ reason for most of us coding this way. When
you're used to read it this way, it seems completely normal, and other methods
seem strange. I even used to put the opening brace on the same line as the
function, because I don't like having a line with a single char, I find it a
wast of screen space. But the kernel coding style slowly makes me move forward
to its method.

> return type
> function_name(args)
> 
> because the function_name() stands out more, it's always at the left side so
> I tend to parse it a little more quickly.

I can agree with you on this point. It's only that since I'm not used to read
it this way, I have to make an effort finding the type, even if it's just above.
I will try to use this method just to see if I can feel comfortable with it.

> Don't get me wrong, I'm not arguing that you should go reformat all your
> code (I tend to agree with Linus, if it's not your code, don't stick your
> fingers in there just because you want to reformat it).  All I'm doing
> is trying to understand why in this instance did Linux diverage from 
> common practice.  

I just found through google that C programs are indeed formated as you say,
but C++ programs have the type on the same line as the name. So if this
comes from this origin, we'll be able to say that Linux contains no C++ except
its formating :-)

Cheers,
Willy


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 14:06     ` Larry McVoy
  2003-06-01 14:22       ` Willy Tarreau
@ 2003-06-01 15:02       ` Steven Cole
  2003-06-01 15:09         ` Larry McVoy
                           ` (2 more replies)
  2003-06-01 16:04       ` Jonathan Lundell
                         ` (2 subsequent siblings)
  4 siblings, 3 replies; 42+ messages in thread
From: Steven Cole @ 2003-06-01 15:02 UTC (permalink / raw)
  To: Larry McVoy; +Cc: Willy Tarreau, linux-kernel

On Sun, 2003-06-01 at 08:06, Larry McVoy wrote:
> > > Sometimes it is nice to be able to see function names with a 
> > > 
> > > 	grep '^[a-zA-Z].*(' *.c
> > 
> > This will return 'int foo(void)', what's the problem ?
> 
> You get a lot of other false hits, like globals.  I don't feel strongly
> about this, I'm more wondering why this style was choosen.  The way
> I showed is pretty common,  it's sort of the "Unix" way (it's how the
> original Unix guys did it, how BSD did it, and how the GNU guys do it), so
> it's a somewhat surprising difference.  I've never understood the logic.
> The more I think about it the less I understand it, doing it that way
> means you are more likely to have to wrap a function definition which
> is ugly:
> 
> static inline int cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason)
> {
> }
> 
> vs
> 
> static inline int
> cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason)
> {
> }
> 
> It may be just what you are used to but I also find that when reading lots
> of code it is nice to have it look like
> 
> return type
> function_name(args)
> 
> because the function_name() stands out more, it's always at the left side so
> I tend to parse it a little more quickly.
> 
> Don't get me wrong, I'm not arguing that you should go reformat all your
> code (I tend to agree with Linus, if it's not your code, don't stick your
> fingers in there just because you want to reformat it).  All I'm doing
> is trying to understand why in this instance did Linux diverage from 
> common practice.  

OK, here is a little more divergence from common practice, but please
don't throw too many stones (at least not large ones).  The following
style was invoked by Linus recently in the first of the zlib
conversions. 

Here is a snippet of a patch from arch/ppc/xmon/ppc-opc.c:

@@ -420,19 +420,19 @@
    same.  */

/*ARGSUSED*/
-static unsigned long
-insert_bba (insn, value, errmsg)
-     unsigned long insn;
-     long value;
-     const char **errmsg;
+static unsigned long insert_bba(
+       unsigned long insn,
+       long value,
+       const char **errmsg
+)
{
   return insn | (((insn >> 16) & 0x1f) << 11);
}


One added bonus of the above style is that it leaves the line count
unchanged. ;)

Steven



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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 15:02       ` Steven Cole
@ 2003-06-01 15:09         ` Larry McVoy
  2003-06-01 15:50           ` Steven Cole
  2003-06-01 23:01         ` Paul Mackerras
  2003-06-03  3:29         ` Robert White
  2 siblings, 1 reply; 42+ messages in thread
From: Larry McVoy @ 2003-06-01 15:09 UTC (permalink / raw)
  To: Steven Cole; +Cc: Larry McVoy, Willy Tarreau, linux-kernel

> /*ARGSUSED*/
> -static unsigned long
> -insert_bba (insn, value, errmsg)
> -     unsigned long insn;
> -     long value;
> -     const char **errmsg;
> +static unsigned long insert_bba(
> +       unsigned long insn,
> +       long value,
> +       const char **errmsg
> +)
> {
>    return insn | (((insn >> 16) & 0x1f) << 11);
> }

Of the following, the original is clearly outdated so we can all agree that
can go.  I'm not real found of Linus' style either.  What's wrong with the
two traditional forms?

/* ============== original ============== */
static unsigned long
insert_bba (insn, value, errmsg)
	unsigned long insn;
	long value;
	const char **errmsg;
{
	return insn | (((insn >> 16) & 0x1f) << 11);
}

/* ============== linus ============== */
static unsigned long insert_bba(
	unsigned long insn;
	long value;
	const char **errmsg;
)
{
	return insn | (((insn >> 16) & 0x1f) << 11);
}

/* ============== traditional ============== */
static unsigned long
insert_bba(unsigned long insn; long value; const char **errmsg)
{
	return insn | (((insn >> 16) & 0x1f) << 11);
}

/* ============== traditional (lotso args) ============== */
static unsigned long
insert_bba(
	register unsigned const int some_big_fat_variable_name;
	unsigned long insn;
	long value;
	const char **errmsg)
{
	return insn | (((insn >> 16) & 0x1f) << 11);
}

-- 
---
Larry McVoy              lm at bitmover.com          http://www.bitmover.com/lm

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 15:09         ` Larry McVoy
@ 2003-06-01 15:50           ` Steven Cole
  2003-06-01 16:02             ` Larry McVoy
  0 siblings, 1 reply; 42+ messages in thread
From: Steven Cole @ 2003-06-01 15:50 UTC (permalink / raw)
  To: Larry McVoy; +Cc: Willy Tarreau, linux-kernel

On Sun, 2003-06-01 at 09:09, Larry McVoy wrote:
> > /*ARGSUSED*/
> > -static unsigned long
> > -insert_bba (insn, value, errmsg)
> > -     unsigned long insn;
> > -     long value;
> > -     const char **errmsg;
> > +static unsigned long insert_bba(
> > +       unsigned long insn,
> > +       long value,
> > +       const char **errmsg
> > +)
> > {
> >    return insn | (((insn >> 16) & 0x1f) << 11);
> > }
> 
> Of the following, the original is clearly outdated so we can all agree that
> can go.  I'm not real found of Linus' style either.  What's wrong with the
> two traditional forms?
> 
> /* ============== original ============== */
> static unsigned long
> insert_bba (insn, value, errmsg)
> 	unsigned long insn;
> 	long value;
> 	const char **errmsg;
> {
> 	return insn | (((insn >> 16) & 0x1f) << 11);
> }
> 
> /* ============== linus ============== */
> static unsigned long insert_bba(
> 	unsigned long insn;
> 	long value;
> 	const char **errmsg;
> )
> {
> 	return insn | (((insn >> 16) & 0x1f) << 11);
> }
> 
> /* ============== traditional ============== */
> static unsigned long
> insert_bba(unsigned long insn; long value; const char **errmsg)
> {
> 	return insn | (((insn >> 16) & 0x1f) << 11);
> }
> 
> /* ============== traditional (lotso args) ============== */
> static unsigned long
> insert_bba(
> 	register unsigned const int some_big_fat_variable_name;
> 	unsigned long insn;
> 	long value;
> 	const char **errmsg)
> {
> 	return insn | (((insn >> 16) & 0x1f) << 11);
> }

Umm, I think those ";" should be "," otherwise you get a
parameter `insn' has just a forward declaration or some such error.

I have used more traditional style where the new Linus style was not
warranted.  Here is the patch for fs/jfs/jfs_xtree.c:

--- bk-current/fs/jfs/jfs_xtree.c	2003-05-31 20:30:47.000000000 -0600
+++ linux/fs/jfs/jfs_xtree.c	2003-05-31 21:02:14.000000000 -0600
@@ -4225,8 +4225,7 @@
  *      at the current entry at the current subtree root page
  *
  */
-int xtGather(t)
-btree_t *t;
+int xtGather(btree_t *t)
 {
 	int rc = 0;
 	xtpage_t *p;

I haven't yet sent that to the maintainer (worked until late last night
and still getting -ENOTENOUGHCOFFEE from brain).  

Anyway, I agree that more traditional styles should be used unless
otherwise indicated, but having the return type on the same line as the
function name is something I've warmed up to.  And I can remember
14-character filenames and being able to print out the entire kernel in
less than 20 minutes on the line printer.  That was 8 or 9 years before
linux 0.01.  Yes, I'm an old-fogey.

Steven


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 15:50           ` Steven Cole
@ 2003-06-01 16:02             ` Larry McVoy
  2003-06-01 16:18               ` Steven Cole
  0 siblings, 1 reply; 42+ messages in thread
From: Larry McVoy @ 2003-06-01 16:02 UTC (permalink / raw)
  To: Steven Cole; +Cc: Larry McVoy, Willy Tarreau, linux-kernel

> I have used more traditional style where the new Linus style was not
> warranted.  Here is the patch for fs/jfs/jfs_xtree.c:
> 
> --- bk-current/fs/jfs/jfs_xtree.c	2003-05-31 20:30:47.000000000 -0600
> +++ linux/fs/jfs/jfs_xtree.c	2003-05-31 21:02:14.000000000 -0600
> @@ -4225,8 +4225,7 @@
>   *      at the current entry at the current subtree root page
>   *
>   */
> -int xtGather(t)
> -btree_t *t;
> +int xtGather(btree_t *t)
>  {
>  	int rc = 0;
>  	xtpage_t *p;
> 
> I haven't yet sent that to the maintainer (worked until late last night
> and still getting -ENOTENOUGHCOFFEE from brain).  
> 
> Anyway, I agree that more traditional styles should be used unless
> otherwise indicated, but having the return type on the same line as the
> function name is something I've warmed up to.  

OK, whatever.  But are you planning on trying to reformat the kernel and
get that pushed into the mainline?  That's a fool's errand for lots of 
reasons.  Nobody is going to get excited about having to look through 
tons of patches which are all white space changes.  And it screws up
the revision history.  Annotated listings and being able to go from that
to the patch are a nice thing.  If you get all this stuff applied you 
are hiding the real authorship of each of these function declarations.
-- 
---
Larry McVoy              lm at bitmover.com          http://www.bitmover.com/lm

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 14:06     ` Larry McVoy
  2003-06-01 14:22       ` Willy Tarreau
  2003-06-01 15:02       ` Steven Cole
@ 2003-06-01 16:04       ` Jonathan Lundell
  2003-06-01 16:11         ` Larry McVoy
  2003-06-02 12:39       ` Jesse Pollard
  2003-06-03  3:15       ` Robert White
  4 siblings, 1 reply; 42+ messages in thread
From: Jonathan Lundell @ 2003-06-01 16:04 UTC (permalink / raw)
  To: linux-kernel

At 7:06am -0700 6/1/03, Larry McVoy wrote:
>It may be just what you are used to but I also find that when reading lots
>of code it is nice to have it look like
>
>return type
>function_name(args)
>
>because the function_name() stands out more, it's always at the left side so
>I tend to parse it a little more quickly.

The reason I've liked this format is that it gives me a quick and 
universal way to find *specific* functions with vi or grep, by 
searching for "^function_name(".

I'm less concerned with global function searches; there I don't mind 
the overhead of more sophisticated tools.

When we're done with this thread, perhaps we can return to endian arguments....
-- 
/Jonathan Lundell.

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 16:04       ` Jonathan Lundell
@ 2003-06-01 16:11         ` Larry McVoy
  2003-06-01 16:46           ` Steven Cole
  0 siblings, 1 reply; 42+ messages in thread
From: Larry McVoy @ 2003-06-01 16:11 UTC (permalink / raw)
  To: Jonathan Lundell; +Cc: linux-kernel

On Sun, Jun 01, 2003 at 09:04:22AM -0700, Jonathan Lundell wrote:
> The reason I've liked this format is that it gives me a quick and 
> universal way to find *specific* functions with vi or grep, by 
> searching for "^function_name(".

Exactly.  I thought of making that point in my original posting and 
figured everyone would tell me to use tags and I didn't want to have
to remember all the other reasons I wanted this.

It really is nice knowing that "^function_name(" is the definition.
-- 
---
Larry McVoy              lm at bitmover.com          http://www.bitmover.com/lm

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 16:02             ` Larry McVoy
@ 2003-06-01 16:18               ` Steven Cole
  0 siblings, 0 replies; 42+ messages in thread
From: Steven Cole @ 2003-06-01 16:18 UTC (permalink / raw)
  To: Larry McVoy; +Cc: Willy Tarreau, linux-kernel

On Sun, 2003-06-01 at 10:02, Larry McVoy wrote:
> > I have used more traditional style where the new Linus style was not
> > warranted.  Here is the patch for fs/jfs/jfs_xtree.c:
> > 
> > --- bk-current/fs/jfs/jfs_xtree.c	2003-05-31 20:30:47.000000000 -0600
> > +++ linux/fs/jfs/jfs_xtree.c	2003-05-31 21:02:14.000000000 -0600
> > @@ -4225,8 +4225,7 @@
> >   *      at the current entry at the current subtree root page
> >   *
> >   */
> > -int xtGather(t)
> > -btree_t *t;
> > +int xtGather(btree_t *t)
> >  {
> >  	int rc = 0;
> >  	xtpage_t *p;
> > 
> > I haven't yet sent that to the maintainer (worked until late last night
> > and still getting -ENOTENOUGHCOFFEE from brain).  
> > 
> > Anyway, I agree that more traditional styles should be used unless
> > otherwise indicated, but having the return type on the same line as the
> > function name is something I've warmed up to.  
> 
> OK, whatever.  But are you planning on trying to reformat the kernel and
> get that pushed into the mainline?  That's a fool's errand for lots of 
> reasons.  Nobody is going to get excited about having to look through 
> tons of patches which are all white space changes.  And it screws up
> the revision history.  Annotated listings and being able to go from that
> to the patch are a nice thing.  If you get all this stuff applied you 
> are hiding the real authorship of each of these function declarations.

Nope.  I'm just doing the absolute minimum.  Others have suggested using
Lindent and friends, but that would result in the undesirable
side-effects you've pointed out, and for little or no gain.  So, I for
one, will _not_ be doing that.

Obfuscating real authorship is a definite problem however.  But I'm
confident that you and your Bitkeeper elves can come up with a good
solution to this.  Surely this problem must slop over into other areas.

Steven


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 16:11         ` Larry McVoy
@ 2003-06-01 16:46           ` Steven Cole
  2003-06-01 16:52             ` Larry McVoy
  0 siblings, 1 reply; 42+ messages in thread
From: Steven Cole @ 2003-06-01 16:46 UTC (permalink / raw)
  To: Larry McVoy; +Cc: Jonathan Lundell, linux-kernel

On Sun, 2003-06-01 at 10:11, Larry McVoy wrote:
> On Sun, Jun 01, 2003 at 09:04:22AM -0700, Jonathan Lundell wrote:
> > The reason I've liked this format is that it gives me a quick and 
> > universal way to find *specific* functions with vi or grep, by 
> > searching for "^function_name(".
> 
> Exactly.  I thought of making that point in my original posting and 
> figured everyone would tell me to use tags and I didn't want to have
> to remember all the other reasons I wanted this.
> 
> It really is nice knowing that "^function_name(" is the definition.

Thanks for the input.  You've convinced me.  When going through
arch/ppc/xmon/xmon.c, I will leave things like the following unchanged:

/* Command interpreting routine */
static int
cmds(struct pt_regs *excp)
{

My changes will be similar to the following:

@@ -1837,9 +1818,7 @@
        return *lineptr++;
 }

-void
-take_input(str)
-char *str;
+void take_input(char *str)
 {
        lineptr = str;
 }

I'll be changing the return type/function name line orientation only
when making other changes. And these will still go through the
applicable maintainers.

Steven


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 16:46           ` Steven Cole
@ 2003-06-01 16:52             ` Larry McVoy
  2003-06-01 17:18               ` Steven Cole
  0 siblings, 1 reply; 42+ messages in thread
From: Larry McVoy @ 2003-06-01 16:52 UTC (permalink / raw)
  To: Steven Cole; +Cc: Larry McVoy, Jonathan Lundell, linux-kernel

> Thanks for the input.  You've convinced me.  When going through
> arch/ppc/xmon/xmon.c, I will leave things like the following unchanged:
> 
> /* Command interpreting routine */
> static int
> cmds(struct pt_regs *excp)
> {

Great.

> My changes will be similar to the following:
> 
> @@ -1837,9 +1818,7 @@
>         return *lineptr++;
>  }
> 
> -void
> -take_input(str)
> -char *str;
> +void take_input(char *str)
>  {
>         lineptr = str;
>  }

OK, I'm confused.  You said you were convinced but then shouldn't that be

void
take_input(char *str)
{
       lineptr = str;
}

??
-- 
---
Larry McVoy              lm at bitmover.com          http://www.bitmover.com/lm

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 16:52             ` Larry McVoy
@ 2003-06-01 17:18               ` Steven Cole
  0 siblings, 0 replies; 42+ messages in thread
From: Steven Cole @ 2003-06-01 17:18 UTC (permalink / raw)
  To: Larry McVoy; +Cc: Jonathan Lundell, linux-kernel

On Sun, 2003-06-01 at 10:52, Larry McVoy wrote:
> > Thanks for the input.  You've convinced me.  When going through
> > arch/ppc/xmon/xmon.c, I will leave things like the following unchanged:
> > 
> > /* Command interpreting routine */
> > static int
> > cmds(struct pt_regs *excp)
> > {
> 
> Great.
> 
> > My changes will be similar to the following:
> > 
> > @@ -1837,9 +1818,7 @@
> >         return *lineptr++;
> >  }
> > 
> > -void
> > -take_input(str)
> > -char *str;
> > +void take_input(char *str)
> >  {
> >         lineptr = str;
> >  }
> 
> OK, I'm confused.  You said you were convinced but then shouldn't that be
> 
> void
> take_input(char *str)
> {
>        lineptr = str;
> }
> 
> ??
Yeah, I realized the inconsistency of that after sending.  This is with
that change backed out (same as your example above):

@@ -1838,8 +1819,7 @@
 }

 void
-take_input(str)
-char *str;
+take_input(char *str)
 {
        lineptr = str;
 }


My guiding principle in all this is "first, do no harm".  That's why I
posted my question in the first place.  Thanks for the help.

Steven


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 13:14     ` Alan Cox
@ 2003-06-01 19:10       ` Zwane Mwaikambo
  0 siblings, 0 replies; 42+ messages in thread
From: Zwane Mwaikambo @ 2003-06-01 19:10 UTC (permalink / raw)
  To: Alan Cox; +Cc: Arnaldo Carvalho de Melo, Steven Cole, Linux Kernel Mailing List

On Sun, 1 Jun 2003, Alan Cox wrote:

> On Sul, 2003-06-01 at 07:43, Zwane Mwaikambo wrote:
> > --- linux-2.5/scripts/Lindent	31 May 2003 18:57:19 -0000	1.16
> > +++ linux-2.5/scripts/Lindent	1 Jun 2003 05:46:02 -0000
> > @@ -1,2 +1,2 @@
> >  #!/bin/sh
> > -indent -kr -i8 -ts8 -sob -l80 -ss -bs -psl "$@"
> > +indent -kr -i8 -ts8 -sob -l80 -ss -bs "$@"
> 
> Take out the -l80 as well, it makes indent do horrific things to code,
> and mangled 80 column wrapping is not the normal Linux style

It shan't be missed ;)

Index: linux-2.5/scripts/Lindent
===================================================================
RCS file: /home/cvs/linux-2.5/scripts/Lindent,v
retrieving revision 1.16
diff -u -p -B -r1.16 Lindent
--- linux-2.5/scripts/Lindent	31 May 2003 18:57:19 -0000	1.16
+++ linux-2.5/scripts/Lindent	1 Jun 2003 18:12:43 -0000
@@ -1,2 +1,2 @@
 #!/bin/sh
-indent -kr -i8 -ts8 -sob -l80 -ss -bs -psl "$@"
+indent -kr -i8 -ts8 -sob -ss -bs "$@"

-- 
function.linuxpower.ca

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 15:02       ` Steven Cole
  2003-06-01 15:09         ` Larry McVoy
@ 2003-06-01 23:01         ` Paul Mackerras
  2003-06-01 23:30           ` Steven Cole
  2003-06-03  3:29         ` Robert White
  2 siblings, 1 reply; 42+ messages in thread
From: Paul Mackerras @ 2003-06-01 23:01 UTC (permalink / raw)
  To: Steven Cole; +Cc: linux-kernel

Steven Cole writes:

> Here is a snippet of a patch from arch/ppc/xmon/ppc-opc.c:

Given that that file is a direct lift from binutils, I would rather
update it with the latest version from binutils than waste time on
reformatting, if it really bothers you.

My opinion is that changing code that works and that doesn't need
attention is a waste of time.  If you're working on some code (or even
if you are just trying to understand it and you want to make it clearer),
then fine, reformat/re-indent/fix argument declarations/whatever, but
if you're not, find something more productive to do.

Paul.

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 23:01         ` Paul Mackerras
@ 2003-06-01 23:30           ` Steven Cole
  0 siblings, 0 replies; 42+ messages in thread
From: Steven Cole @ 2003-06-01 23:30 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: linux-kernel

On Sun, 2003-06-01 at 17:01, Paul Mackerras wrote:
> Steven Cole writes:
> 
> > Here is a snippet of a patch from arch/ppc/xmon/ppc-opc.c:
> 
> Given that that file is a direct lift from binutils, I would rather
> update it with the latest version from binutils than waste time on
> reformatting, if it really bothers you.
> 
> My opinion is that changing code that works and that doesn't need
> attention is a waste of time.  If you're working on some code (or even
> if you are just trying to understand it and you want to make it clearer),
> then fine, reformat/re-indent/fix argument declarations/whatever, but
> if you're not, find something more productive to do.
> 
> Paul.
> 
The only purpose was to convert from K&R style:

int foo(bar, baz)
long bar;
long baz;
{
}

to ANSI C style:

int foo(long bar, long baz)
{
}

The purpose of the above is that Linus's new sparse checker purposefully
ignores K&R style, and he has indicated a willingness to accept patches
for the conversion.  In fact, he began the conversion himself.

If you'd rather me not touch arch/ppc/xmon/ppc-opc.c and xmon.c, then I
won't.  I was about ready to send those patches to you.  Please let me
know what you'd prefer.  The default will be no action. Thanks.

Steven


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 13:26 ` Larry McVoy
  2003-06-01 13:49   ` Willy Tarreau
  2003-06-01 13:53   ` Scott Robert Ladd
@ 2003-06-02  2:09   ` Linus Torvalds
  2003-06-02  2:21     ` Larry McVoy
                       ` (3 more replies)
  2 siblings, 4 replies; 42+ messages in thread
From: Linus Torvalds @ 2003-06-02  2:09 UTC (permalink / raw)
  To: linux-kernel

In article <20030601132626.GA3012@work.bitmover.com>,
Larry McVoy  <lm@bitmover.com> wrote:
>On Sat, May 31, 2003 at 11:56:16PM -0600, Steven Cole wrote:
>> Proposed conversion:
>> 
>> int foo(void)
>> {
>>    	/* body here */
>> }	
>
>Sometimes it is nice to be able to see function names with a 
>
>	grep '^[a-zA-Z].*(' *.c
>
>which is why I've always preferred
>
>int
>foo(void)
>{
>	/* body here */
>}	

That makes no sense.

Do you write your normal variable definitions like

	int
	a,b,c;

too? No you don't, because that would be totally idiotic.

A function declaration is no different. The type of the function is very
important to the function itself (along with the arguments), and I
personally want to see _all_ of it when I grep for functions. 

You should just do

	grep -i '^[a-z_ ]*(' *.c 

and you'll get a nice function declaration with the standard kernel
coding style.

And I personally don't normally do "grep for random function
declarations", that just sounds like a contrieved example.  I grep for
specific function names to find usage, and then it's _doubly_ important
to see that the return (and argument) types match and make sense.

So I definitely prefer all the arguments on the same line too, even if
that makes the line be closer to 100 chars than 80.  The zlib K&R->ANSI
conversion was a special case, and I'd be happy if somebody were to have
the energy to convert it all the way (which implies moving comments
around etc). 

			Linus

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-02  2:09   ` Linus Torvalds
@ 2003-06-02  2:21     ` Larry McVoy
  2003-06-02  2:26       ` Davide Libenzi
  2003-06-02  3:15     ` Steven Cole
                       ` (2 subsequent siblings)
  3 siblings, 1 reply; 42+ messages in thread
From: Larry McVoy @ 2003-06-02  2:21 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

> >which is why I've always preferred
> >
> >int
> >foo(void)
> >{
> >	/* body here */
> >}	
> 
> That makes no sense.

Whatever, it's your tree.  I'd rather have you force everything to the same
style, any style, than tolerate all sorts of different styles.  
-- 
---
Larry McVoy              lm at bitmover.com          http://www.bitmover.com/lm

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-02  2:21     ` Larry McVoy
@ 2003-06-02  2:26       ` Davide Libenzi
  0 siblings, 0 replies; 42+ messages in thread
From: Davide Libenzi @ 2003-06-02  2:26 UTC (permalink / raw)
  To: Larry McVoy; +Cc: Linux Kernel Mailing List

On Sun, 1 Jun 2003, Larry McVoy wrote:

> Whatever, it's your tree.  I'd rather have you force everything to the same
> style, any style, than tolerate all sorts of different styles.

Agree here. Personally I don't care of using whatever non-brain damaged
style but I like to see projects using a consistent coding style. Whatever
it is ...



- Davide


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-02  2:09   ` Linus Torvalds
  2003-06-02  2:21     ` Larry McVoy
@ 2003-06-02  3:15     ` Steven Cole
  2003-06-02 15:54     ` Erik Hensema
  2003-06-03 12:32     ` Martin Waitz
  3 siblings, 0 replies; 42+ messages in thread
From: Steven Cole @ 2003-06-02  3:15 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

On Sun, 2003-06-01 at 20:09, Linus Torvalds wrote:
> In article <20030601132626.GA3012@work.bitmover.com>,
> Larry McVoy  <lm@bitmover.com> wrote:
> >On Sat, May 31, 2003 at 11:56:16PM -0600, Steven Cole wrote:
> >> Proposed conversion:
> >> 
> >> int foo(void)
> >> {
> >>    	/* body here */
> >> }	
> >
> >Sometimes it is nice to be able to see function names with a 
> >
> >	grep '^[a-zA-Z].*(' *.c
> >
> >which is why I've always preferred
> >
> >int
> >foo(void)
> >{
> >	/* body here */
> >}	
> 
> That makes no sense.
> 
> Do you write your normal variable definitions like
> 
> 	int
> 	a,b,c;
> 
> too? No you don't, because that would be totally idiotic.
> 
> A function declaration is no different. The type of the function is very
> important to the function itself (along with the arguments), and I
> personally want to see _all_ of it when I grep for functions. 
> 
> You should just do
> 
> 	grep -i '^[a-z_ ]*(' *.c 
> 
> and you'll get a nice function declaration with the standard kernel
> coding style.
> 
> And I personally don't normally do "grep for random function
> declarations", that just sounds like a contrieved example.  I grep for
> specific function names to find usage, and then it's _doubly_ important
> to see that the return (and argument) types match and make sense.
> 
> So I definitely prefer all the arguments on the same line too, even if
> that makes the line be closer to 100 chars than 80.  The zlib K&R->ANSI
> conversion was a special case, and I'd be happy if somebody were to have
> the energy to convert it all the way (which implies moving comments
> around etc). 
> 
How is this? I don't know about the energy part as xor'ed with itself
leaves the value unchanged right now.

I've tried to follow Documentation/kernel-doc-nano-HOWTO.txt
as suggested by acme.

Putting all the arguments on the same line gives 103 characters, if I
counted correctly.  Others will be longer, so this is chosen as a folded
example.

Steven

--- linux/lib/zlib_inflate/inftrees.c.orig	2003-06-01 20:50:57.000000000 -0600
+++ linux/lib/zlib_inflate/inftrees.c	2003-06-01 20:58:51.000000000 -0600
@@ -288,14 +288,17 @@
   return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
 }
 
+/**
+ *	zlib_inflate_trees_bits:
+ *	@uIntf *c:                19 code lengths
+ *	@uIntf *bb:               bits tree desired/actual depth
+ *	@inflate_huft * FAR *tb:  bits tree result
+ *	@inflate_huft *hp:        space for trees
+ *	@z_streamp z:             for messages
+ */
 
-int zlib_inflate_trees_bits(
-	uIntf *c,               /* 19 code lengths */
-	uIntf *bb,              /* bits tree desired/actual depth */
-	inflate_huft * FAR *tb, /* bits tree result */
-	inflate_huft *hp,       /* space for trees */
-	z_streamp z             /* for messages */
-)
+int zlib_inflate_trees_bits(uIntf *c, uIntf *bb, inflate_huft * FAR *tb,
+	inflate_huft *hp, z_streamp z)
 {
   int r;
   uInt hn = 0;          /* hufts used in space */




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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-01 14:06     ` Larry McVoy
                         ` (2 preceding siblings ...)
  2003-06-01 16:04       ` Jonathan Lundell
@ 2003-06-02 12:39       ` Jesse Pollard
  2003-06-03  3:15       ` Robert White
  4 siblings, 0 replies; 42+ messages in thread
From: Jesse Pollard @ 2003-06-02 12:39 UTC (permalink / raw)
  To: Larry McVoy, Willy Tarreau; +Cc: Larry McVoy, Steven Cole, linux-kernel

On Sunday 01 June 2003 09:06, Larry McVoy wrote:
> > > Sometimes it is nice to be able to see function names with a
> > >
> > > 	grep '^[a-zA-Z].*(' *.c
> >
> > This will return 'int foo(void)', what's the problem ?
>
> You get a lot of other false hits, like globals.  I don't feel strongly
> about this, I'm more wondering why this style was choosen.  The way
> I showed is pretty common,  it's sort of the "Unix" way (it's how the
> original Unix guys did it, how BSD did it, and how the GNU guys do it), so
> it's a somewhat surprising difference.  I've never understood the logic.
> The more I think about it the less I understand it, doing it that way
> means you are more likely to have to wrap a function definition which
> is ugly:
>
> static inline int cdrom_write_check_ireason(ide_drive_t *drive, int len,
> int ireason) {
> }

Actually, that would most likely be:
static inline int cdrom_write_check_ireason(
			ide_drive_t *drive,
			int len,
			int ireason
)
{
...
}

At least If I were doing it. Over my 20 years, I've found that many of MY
type errors are due to returning or expecting the wrong structure/variable
because I forgot the type of the function.

I rarely have to look at the parameters (though when I do, I locate them
via the function name, then scan the parameters...) sometimes just to count
the number of parameters, or the order, which is easier when the parameters
are one to a line. Either as in K&R, or the new style.


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-02  2:09   ` Linus Torvalds
  2003-06-02  2:21     ` Larry McVoy
  2003-06-02  3:15     ` Steven Cole
@ 2003-06-02 15:54     ` Erik Hensema
  2003-06-03 12:32     ` Martin Waitz
  3 siblings, 0 replies; 42+ messages in thread
From: Erik Hensema @ 2003-06-02 15:54 UTC (permalink / raw)
  To: linux-kernel

Linus Torvalds (torvalds@transmeta.com) wrote:
> In article <20030601132626.GA3012@work.bitmover.com>,
> Larry McVoy  <lm@bitmover.com> wrote:
>>On Sat, May 31, 2003 at 11:56:16PM -0600, Steven Cole wrote:
>>> Proposed conversion:
>>> 
>>> int foo(void)
>>> {
>>>    	/* body here */
>>> }	
>>
>>Sometimes it is nice to be able to see function names with a 
>>
>>	grep '^[a-zA-Z].*(' *.c
>>
>>which is why I've always preferred
>>
>>int
>>foo(void)
>>{
>>	/* body here */
>>}	
> 
> That makes no sense.

But it does. Type /^foo <enter> and you're at the function definition. At
least when using vi, which is the editor everybody's using, right? ;-)

Also, when in working in a (too) long function body, type ?^{ and you're
at the start of the function body.

> Do you write your normal variable definitions like
> 
> 	int
> 	a,b,c;
> 
> too? No you don't, because that would be totally idiotic.

Indeed, searching for ^a will fail. There's no reason whatsoever why you'd
declare your variables that way.

-- 
Erik Hensema <erik@hensema.net>

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

* Re: Question about style when converting from K&R to ANSI C.
       [not found]     ` <20030602160025$70e8@gated-at.bofh.it>
@ 2003-06-02 16:09       ` Pascal Schmidt
  0 siblings, 0 replies; 42+ messages in thread
From: Pascal Schmidt @ 2003-06-02 16:09 UTC (permalink / raw)
  To: erik; +Cc: linux-kernel

On Mon, 02 Jun 2003 18:00:25 +0200, you wrote in linux-kernel:

> But it does. Type /^foo <enter> and you're at the function definition. At
> least when using vi, which is the editor everybody's using, right? ;-)

vi can do better than that, man ctags. No need to search function
definitions that way...

-- 
Ciao,
Pascal

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

* RE: Question about style when converting from K&R to ANSI C.
  2003-06-01 14:06     ` Larry McVoy
                         ` (3 preceding siblings ...)
  2003-06-02 12:39       ` Jesse Pollard
@ 2003-06-03  3:15       ` Robert White
  4 siblings, 0 replies; 42+ messages in thread
From: Robert White @ 2003-06-03  3:15 UTC (permalink / raw)
  To: Larry McVoy, Willy Tarreau; +Cc: Steven Cole, linux-kernel

My personal preference(s) are:

In C or naked scope of C++:

static inline
int function_name(type arg, type arg)
{
  body
}

By putting the scope modifiers and compiler directives on one line and the
calling conventions on another it makes a distinction between what the user
needs to know as opposed to the compiler.

In C++ classes:

class   				ClassName {
	static inline int		function_name(type arg, type arg) { return expression; }
	static inline int       function_name(type arg, type arg) {
						complex body;
					}
					ClassName();
	virtual		     ~ClassName();
};

(If the above doesn't look right because of email handling cruft) The names
of the class and members all line up vertically, the destructor is proceeded
by seven spaces and a tilde instead of a tab (so the destructor "stands out"
in a quick code scan) and the "static" and "inline" in this usage are
actually part of the type of the member function of a class in a way that
they are only hints in a naked scope, so they move down onto the line
itself.

There is no good "find it" trick if you don't do the below, but if you do
use the rest of "my personal standard" then doing "egrep ')$'" gets you all
of the function definitions with only the occasional split-line-conditional,
and since I also "&&" and "||" those at the end of the line I never have
that problem either...


(And not that anybody asked)

if (test) {
  code
} else {
  more code
}

while (test) {
  code
}

do {
  code
} while (test);

and so on...

and also (for the advanced reader):

if ((conditional) &&
    (conditional)) {
}

This one being "advanced" because it reads like a book but you have to "hold
in your head" were you are in the conditional more aggressively than the
prefixing version.

These preferences go back to when vi would delete lines if you scrolled down
through a file quickly using the arrow keys.  Even in the absence of that
particular annoyance (because we don't need a vi versus emacs holy war flare
up, they are both evil anyway, even if I do use vi constantly 8-), I have
never liked the floating brace styles like

  if (test)
  {
     code
  }


because the code still works and even looks right if you accidentally
damage/remove the if.  Just like "while (test);" on a line by itself is
transformed into a hang if the "do" ten pages up is removed.

  if ((conditional)
    &&(conditional))
  {
    code
  }

is subject to problems on line delete too.  Accidentally remove the "&&"
line and it is really easy to decide you made a parenthesis counting
mistake.  If the conditional is on the leading line then when you see

  if ((conditional) &&
  {
    code
  }

you instantly know something is amiss.

Fully correct, the dropped line would leave
  if ((conditional) &&
    code
  }

because the leading brace would have been eaten with the bad line too.
Neither positioning will protect you from dropping a middle term of three,
for obvious reasons.

AND MOST IMPORTANTLY:

while (test)
  one line of code;

AND

if (test)
  one line of code;

(etc) are fundamentally _*EVIL*_  (evil I say! do you hear me? EVIL!!!!! 8-)

Whatever the language designers might say, braces are not optional in
"morally correct" C or C++.

(I have maintained too much crappy code in my life, most of it written by
students, to think the other "standards" are anything but accidents waiting
to happen.  The only reason the floating-brace standard is taught in schools
is because it makes red-pen grading easier because of the blank page space.)


Rob.

-----Original Message-----
From: linux-kernel-owner@vger.kernel.org
[mailto:linux-kernel-owner@vger.kernel.org]On Behalf Of Larry McVoy

static inline int cdrom_write_check_ireason(ide_drive_t *drive, int len, int
ireason)
{
}

vs

static inline int
cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason)
{
}


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

* RE: Question about style when converting from K&R to ANSI C.
  2003-06-01 15:02       ` Steven Cole
  2003-06-01 15:09         ` Larry McVoy
  2003-06-01 23:01         ` Paul Mackerras
@ 2003-06-03  3:29         ` Robert White
  2 siblings, 0 replies; 42+ messages in thread
From: Robert White @ 2003-06-03  3:29 UTC (permalink / raw)
  To: Steven Cole, Larry McVoy; +Cc: Willy Tarreau, linux-kernel

Um... ich!  (ignoring the return type debate)

static unsigned long
insert_bba(unsigned long insn,
           long value,
           const char **errmsg)
{
   return insn | (((insn >> 16) & 0x1f) << 11);
}


...OR...

static unsigned long insert_bba(unsigned long insn,
                                long value,
                                const char **errmsg)
{
   return insn | (((insn >> 16) & 0x1f) << 11);
}


NEVER line up the return type and the argument type like the text below.  It
is mind-clobbering after a couple hundred pages.

Also, though it didn't come up, once you decide to put the arguments on
separate lines for readability never mix the styles in one function call.

int X(int A, int B,
      char **errormsg)
{
}

is "very bad".  the above "looks ok" in that one instance but it isn't.
Either I have to count the arguments, or there is one per line, but never
seven arguments on five lines (if you please) as that is evil!  (It is good
for driving instructors crazy too... 8-)


Also, in your automatics, it is never ok to write

   int A, *b;
or even
   int A, B;

One variable per line please.

  int A;
  int *b;

  (Especially if you are programming, or ever hope to program, tiny little
embedded systems where you really have to visualize your stack requirements.
8-)  The real reason is to facilitate and encourage automatic
initializations.  Particularly of classes in C++, but profoundly so in basic
C none the less.  Uninitialized variables should look bare and lonely, and
perhaps even a tad wrong.  (Not to mention having more than one alphabetic
character as a name, but I was being minimalist... 8-)

Rob.



-----Original Message-----
From: linux-kernel-owner@vger.kernel.org
[mailto:linux-kernel-owner@vger.kernel.org]On Behalf Of Steven Cole

/*ARGSUSED*/
-static unsigned long
-insert_bba (insn, value, errmsg)
-     unsigned long insn;
-     long value;
-     const char **errmsg;
+static unsigned long insert_bba(
+       unsigned long insn,
+       long value,
+       const char **errmsg
+)
{
   return insn | (((insn >> 16) & 0x1f) << 11);
}



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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-02  2:09   ` Linus Torvalds
                       ` (2 preceding siblings ...)
  2003-06-02 15:54     ` Erik Hensema
@ 2003-06-03 12:32     ` Martin Waitz
  2003-06-03 12:45       ` Dave Jones
  3 siblings, 1 reply; 42+ messages in thread
From: Martin Waitz @ 2003-06-03 12:32 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]

hi :)

On Mon, Jun 02, 2003 at 02:09:17AM +0000, Linus Torvalds wrote:
> And I personally don't normally do "grep for random function
> declarations", that just sounds like a contrieved example.  I grep for
> specific function names to find usage, and then it's _doubly_ important
> to see that the return (and argument) types match and make sense.
well, but it is nice to be able to grep for the declaration of a
function like

	grep "^where_is_it" *.c

without showing all the uses of that function.

also, putting the return type on its own line makes sure that
the function name is always at the same position.
this greatly enhances readability (at least for me ;)

-- 
CU,		  / Friedrich-Alexander University Erlangen, Germany
Martin Waitz	//  Department of Computer Science 3       _________
______________/// - - - - - - - - - - - - - - - - - - - - ///
dies ist eine manuell generierte mail, sie beinhaltet    //
tippfehler und ist auch ohne grossbuchstaben gueltig.   /

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-03 12:32     ` Martin Waitz
@ 2003-06-03 12:45       ` Dave Jones
  2003-06-03 12:51         ` Jörn Engel
  2003-06-03 13:18         ` Henning P. Schmiedehausen
  0 siblings, 2 replies; 42+ messages in thread
From: Dave Jones @ 2003-06-03 12:45 UTC (permalink / raw)
  To: linux-kernel

On Tue, Jun 03, 2003 at 02:32:56PM +0200, Martin Waitz wrote:

 > well, but it is nice to be able to grep for the declaration of a
 > function like
 > 
 > 	grep "^where_is_it" *.c
 > 
 > without showing all the uses of that function.

What's wrong with ctags for this?

		Dave


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-03 12:45       ` Dave Jones
@ 2003-06-03 12:51         ` Jörn Engel
  2003-06-03 13:18         ` Henning P. Schmiedehausen
  1 sibling, 0 replies; 42+ messages in thread
From: Jörn Engel @ 2003-06-03 12:51 UTC (permalink / raw)
  To: Dave Jones, linux-kernel

On Tue, 3 June 2003 13:45:01 +0100, Dave Jones wrote:
> On Tue, Jun 03, 2003 at 02:32:56PM +0200, Martin Waitz wrote:
> 
>  > well, but it is nice to be able to grep for the declaration of a
>  > function like
>  > 
>  > 	grep "^where_is_it" *.c
>  > 
>  > without showing all the uses of that function.
> 
> What's wrong with ctags for this?

- You have to set it up (hackers are lazy)
- You generate an extra file that some people might not want

imo it doesn't really matter much either way.  Whatever you prefer,
there are greater evils in the kernel, even in relatively important
parts.  So why bother with such minor and highly personal issues.

Jörn

-- 
Jörn Engel
mailto: joern@wohnheim.fh-wedel.de
http://wohnheim.fh-wedel.de/~joern
Phone: +49 179 6704074

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-03 12:45       ` Dave Jones
  2003-06-03 12:51         ` Jörn Engel
@ 2003-06-03 13:18         ` Henning P. Schmiedehausen
  2003-06-03 13:27           ` Richard B. Johnson
  2003-06-03 13:39           ` William Lee Irwin III
  1 sibling, 2 replies; 42+ messages in thread
From: Henning P. Schmiedehausen @ 2003-06-03 13:18 UTC (permalink / raw)
  To: linux-kernel

Dave Jones <davej@codemonkey.org.uk> writes:

>On Tue, Jun 03, 2003 at 02:32:56PM +0200, Martin Waitz wrote:

> > well, but it is nice to be able to grep for the declaration of a
> > function like
> > 
> > 	grep "^where_is_it" *.c
> > 
> > without showing all the uses of that function.

>What's wrong with ctags for this?

<sarcasm>
Bah, all this newfangled crap like ctags. We've used grep for 30 years
and there is no reason to change this now. 
</sarcasm>

Dave, the arguments some people bring to simply cling to their
formatting reminds me of the arguments that the church had in the 14th
century to still prove that the sun revolves around the earth. Simply
ignore them. I'm grateful that there are programming environments
beyond vi. [1] :-)

	Regards
		Henning

[1] emacs 

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

Java, perl, Solaris, Linux, xSP Consulting, Web Services 
freelance consultant -- Jakarta Turbine Development  -- hero for hire

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-03 13:18         ` Henning P. Schmiedehausen
@ 2003-06-03 13:27           ` Richard B. Johnson
  2003-06-03 13:39           ` William Lee Irwin III
  1 sibling, 0 replies; 42+ messages in thread
From: Richard B. Johnson @ 2003-06-03 13:27 UTC (permalink / raw)
  To: Henning P. Schmiedehausen; +Cc: Linux kernel

On Tue, 3 Jun 2003, Henning P. Schmiedehausen wrote:
> Dave Jones <davej@codemonkey.org.uk> writes:
> >On Tue, Jun 03, 2003 at 02:32:56PM +0200, Martin Waitz wrote:
>
[SNIPPED...]
> ignore them. I'm grateful that there are programming environments
> beyond vi. [1] :-)
>
> 	Regards
> 		Henning

(1) ed

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-03 13:18         ` Henning P. Schmiedehausen
  2003-06-03 13:27           ` Richard B. Johnson
@ 2003-06-03 13:39           ` William Lee Irwin III
  2003-06-03 14:44             ` Henning Schmiedehausen
  1 sibling, 1 reply; 42+ messages in thread
From: William Lee Irwin III @ 2003-06-03 13:39 UTC (permalink / raw)
  To: Henning P. Schmiedehausen; +Cc: linux-kernel

On Tue, Jun 03, 2003 at 01:18:43PM +0000, Henning P. Schmiedehausen wrote:
> <sarcasm>
> Bah, all this newfangled crap like ctags. We've used grep for 30 years
> and there is no reason to change this now. 
> </sarcasm>
> Dave, the arguments some people bring to simply cling to their
> formatting reminds me of the arguments that the church had in the 14th
> century to still prove that the sun revolves around the earth. Simply
> ignore them. I'm grateful that there are programming environments
> beyond vi. [1] :-)
> 	Regards
> 		Henning
> [1] emacs 

Spraying garbage all over source code destroys editor agnosticism, even
if some editor exists that can hide all the crap like trailing
whitespace, spaces where tabs belong, and screwed-up indentation. Use
emacs all you want. Don't force others to use some particular editor by
spewing garbage all over the kernel source that requires some special
editor to hide.


-- wli

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-03 13:39           ` William Lee Irwin III
@ 2003-06-03 14:44             ` Henning Schmiedehausen
  2003-06-03 15:16               ` William Lee Irwin III
  2003-06-03 15:25               ` Randy.Dunlap
  0 siblings, 2 replies; 42+ messages in thread
From: Henning Schmiedehausen @ 2003-06-03 14:44 UTC (permalink / raw)
  To: William Lee Irwin III; +Cc: Linux Kernel Mailing List

The footnote was a non-native language speakers' attempt at self-irony.

If normal people think about development environments beyond vi, they
would consider VisualStudio an improvement. Or eclipse.

Trust me, "whitespace" or "tabs" are the smallest of your problems
there.

Ah well, silly me, trying humour on LKLM. ;-)

	Regards
		Henning


On Tue, 2003-06-03 at 15:39, William Lee Irwin III wrote:
> On Tue, Jun 03, 2003 at 01:18:43PM +0000, Henning P. Schmiedehausen wrote:
> > <sarcasm>
> > Bah, all this newfangled crap like ctags. We've used grep for 30 years
> > and there is no reason to change this now. 
> > </sarcasm>
> > Dave, the arguments some people bring to simply cling to their
> > formatting reminds me of the arguments that the church had in the 14th
> > century to still prove that the sun revolves around the earth. Simply
> > ignore them. I'm grateful that there are programming environments
> > beyond vi. [1] :-)
> > 	Regards
> > 		Henning
> > [1] emacs 
> 
> Spraying garbage all over source code destroys editor agnosticism, even
> if some editor exists that can hide all the crap like trailing
> whitespace, spaces where tabs belong, and screwed-up indentation. Use
> emacs all you want. Don't force others to use some particular editor by
> spewing garbage all over the kernel source that requires some special
> editor to hide.
> 
> 
> -- wli
-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

Java, perl, Solaris, Linux, xSP Consulting, Web Services 
freelance consultant -- Jakarta Turbine Development  -- hero for hire


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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-03 14:44             ` Henning Schmiedehausen
@ 2003-06-03 15:16               ` William Lee Irwin III
  2003-06-03 15:25               ` Randy.Dunlap
  1 sibling, 0 replies; 42+ messages in thread
From: William Lee Irwin III @ 2003-06-03 15:16 UTC (permalink / raw)
  To: Henning Schmiedehausen; +Cc: Linux Kernel Mailing List

On Tue, Jun 03, 2003 at 04:44:05PM +0200, Henning Schmiedehausen wrote:
> The footnote was a non-native language speakers' attempt at self-irony.
> If normal people think about development environments beyond vi, they
> would consider VisualStudio an improvement. Or eclipse.
> Trust me, "whitespace" or "tabs" are the smallest of your problems
> there.
> Ah well, silly me, trying humour on LKLM. ;-)
> 	Regards
> 		Henning

We're not normal people. We're UNIX kernel hackers. We often do things
in crusty old ways.

Dead serious. Mandating emacs and/or some UNIX-based Visual C++
workalike in order to cope with utter garbage code formatting is not
going to fly.


-- wli

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-03 14:44             ` Henning Schmiedehausen
  2003-06-03 15:16               ` William Lee Irwin III
@ 2003-06-03 15:25               ` Randy.Dunlap
  2003-06-03 15:38                 ` William Lee Irwin III
  1 sibling, 1 reply; 42+ messages in thread
From: Randy.Dunlap @ 2003-06-03 15:25 UTC (permalink / raw)
  To: Henning Schmiedehausen; +Cc: linux-kernel

You did good (or even well considering that you are a
non-native speaker).  Yes, whitespace is a trivial problem.

~Randy


On 03 Jun 2003 16:44:05 +0200 Henning Schmiedehausen <hps@intermeta.de> wrote:

| The footnote was a non-native language speakers' attempt at self-irony.
| 
| If normal people think about development environments beyond vi, they
| would consider VisualStudio an improvement. Or eclipse.
| 
| Trust me, "whitespace" or "tabs" are the smallest of your problems
| there.
| 
| Ah well, silly me, trying humour on LKLM. ;-)
| 
| 	Regards
| 		Henning
| 
| 
| On Tue, 2003-06-03 at 15:39, William Lee Irwin III wrote:
| > On Tue, Jun 03, 2003 at 01:18:43PM +0000, Henning P. Schmiedehausen wrote:
| > > <sarcasm>
| > > Bah, all this newfangled crap like ctags. We've used grep for 30 years
| > > and there is no reason to change this now. 
| > > </sarcasm>
| > > Dave, the arguments some people bring to simply cling to their
| > > formatting reminds me of the arguments that the church had in the 14th
| > > century to still prove that the sun revolves around the earth. Simply
| > > ignore them. I'm grateful that there are programming environments
| > > beyond vi. [1] :-)
| > > 	Regards
| > > 		Henning
| > > [1] emacs 
| > 
| > Spraying garbage all over source code destroys editor agnosticism, even
| > if some editor exists that can hide all the crap like trailing
| > whitespace, spaces where tabs belong, and screwed-up indentation. Use
| > emacs all you want. Don't force others to use some particular editor by
| > spewing garbage all over the kernel source that requires some special
| > editor to hide.
| > 
| > 
| > -- wli

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-03 15:25               ` Randy.Dunlap
@ 2003-06-03 15:38                 ` William Lee Irwin III
  2003-06-03 15:40                   ` Randy.Dunlap
  0 siblings, 1 reply; 42+ messages in thread
From: William Lee Irwin III @ 2003-06-03 15:38 UTC (permalink / raw)
  To: Randy.Dunlap; +Cc: Henning Schmiedehausen, linux-kernel

On Tue, Jun 03, 2003 at 08:25:05AM -0700, Randy.Dunlap wrote:
> You did good (or even well considering that you are a
> non-native speaker).  Yes, whitespace is a trivial problem.
> ~Randy

Bad whitespace, along with all other coding style violations, is
a very serious maintainability problem.


-- wli

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

* Re: Question about style when converting from K&R to ANSI C.
  2003-06-03 15:38                 ` William Lee Irwin III
@ 2003-06-03 15:40                   ` Randy.Dunlap
  0 siblings, 0 replies; 42+ messages in thread
From: Randy.Dunlap @ 2003-06-03 15:40 UTC (permalink / raw)
  To: William Lee Irwin III; +Cc: hps, linux-kernel

On Tue, 3 Jun 2003 08:38:59 -0700 William Lee Irwin III <wli@holomorphy.com> wrote:

| On Tue, Jun 03, 2003 at 08:25:05AM -0700, Randy.Dunlap wrote:
| > You did good (or even well considering that you are a
| > non-native speaker).  Yes, whitespace is a trivial problem.
| > ~Randy
| 
| Bad whitespace, along with all other coding style violations, is
| a very serious maintainability problem.

I agree.  I mean that it's a trivial problem to fix... if the
patches were to be accepted.  But that's another problem.

--
~Randy

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

end of thread, other threads:[~2003-06-03 15:27 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-01  5:56 Question about style when converting from K&R to ANSI C Steven Cole
2003-06-01  6:39 ` Arnaldo Carvalho de Melo
2003-06-01  6:43   ` Zwane Mwaikambo
2003-06-01 13:14     ` Alan Cox
2003-06-01 19:10       ` Zwane Mwaikambo
2003-06-01 13:26 ` Larry McVoy
2003-06-01 13:49   ` Willy Tarreau
2003-06-01 14:06     ` Larry McVoy
2003-06-01 14:22       ` Willy Tarreau
2003-06-01 15:02       ` Steven Cole
2003-06-01 15:09         ` Larry McVoy
2003-06-01 15:50           ` Steven Cole
2003-06-01 16:02             ` Larry McVoy
2003-06-01 16:18               ` Steven Cole
2003-06-01 23:01         ` Paul Mackerras
2003-06-01 23:30           ` Steven Cole
2003-06-03  3:29         ` Robert White
2003-06-01 16:04       ` Jonathan Lundell
2003-06-01 16:11         ` Larry McVoy
2003-06-01 16:46           ` Steven Cole
2003-06-01 16:52             ` Larry McVoy
2003-06-01 17:18               ` Steven Cole
2003-06-02 12:39       ` Jesse Pollard
2003-06-03  3:15       ` Robert White
2003-06-01 13:53   ` Scott Robert Ladd
2003-06-02  2:09   ` Linus Torvalds
2003-06-02  2:21     ` Larry McVoy
2003-06-02  2:26       ` Davide Libenzi
2003-06-02  3:15     ` Steven Cole
2003-06-02 15:54     ` Erik Hensema
2003-06-03 12:32     ` Martin Waitz
2003-06-03 12:45       ` Dave Jones
2003-06-03 12:51         ` Jörn Engel
2003-06-03 13:18         ` Henning P. Schmiedehausen
2003-06-03 13:27           ` Richard B. Johnson
2003-06-03 13:39           ` William Lee Irwin III
2003-06-03 14:44             ` Henning Schmiedehausen
2003-06-03 15:16               ` William Lee Irwin III
2003-06-03 15:25               ` Randy.Dunlap
2003-06-03 15:38                 ` William Lee Irwin III
2003-06-03 15:40                   ` Randy.Dunlap
     [not found] <20030601060013$0d74@gated-at.bofh.it>
     [not found] ` <20030601134006$4765@gated-at.bofh.it>
     [not found]   ` <20030602022006$78ca@gated-at.bofh.it>
     [not found]     ` <20030602160025$70e8@gated-at.bofh.it>
2003-06-02 16:09       ` Pascal Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox