All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: CodingStyle
  2006-09-05  8:08         ` Pavel Machek
@ 2006-09-05 16:40             ` Stefan Richter
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Richter @ 2006-09-05 16:40 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Andrew Morton, alsa-devel, Takashi Iwai, kernel list,
	Randy.Dunlap, pshou, perex

Pavel Machek wrote:
> +Avoid extra spaces around ! operator, and do not place spaces around (s.

How about:

	Avoid extra spaces after the ! operator.
	Do not place spaces around parentheses.

Because "foo && !bar" is certainly OK.

Or more draconian for the former and less so for the latter rule:

	Do not put whitespace between any of the unary operators and
	their operand.

	It is usually unnecessary to have whitespace around parentheses
	as part of expressions, around brackets, or around the operators
	. and ->.

Rule 1 certainly applies likewise to ++, --, unary +, unary -, !, ~,
(typecast), unary *, unary &, sizeof.

Rule 2 applies to all of ( ), [ ], ., ->, except where line breaks and
indentation warrant whitespace, or where whitespace helps to read
expressions with more levels of braces. Although the latter should be
avoided anyway.
-- 
Stefan Richter
-=====-=-==- =--= --=-=
http://arcgraph.de/sr/

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

* Re: CodingStyle
@ 2006-09-05 16:40             ` Stefan Richter
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Richter @ 2006-09-05 16:40 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Randy.Dunlap, Takashi Iwai, Andrew Morton, kernel list, perex,
	alsa-devel, pshou

Pavel Machek wrote:
> +Avoid extra spaces around ! operator, and do not place spaces around (s.

How about:

	Avoid extra spaces after the ! operator.
	Do not place spaces around parentheses.

Because "foo && !bar" is certainly OK.

Or more draconian for the former and less so for the latter rule:

	Do not put whitespace between any of the unary operators and
	their operand.

	It is usually unnecessary to have whitespace around parentheses
	as part of expressions, around brackets, or around the operators
	. and ->.

Rule 1 certainly applies likewise to ++, --, unary +, unary -, !, ~,
(typecast), unary *, unary &, sizeof.

Rule 2 applies to all of ( ), [ ], ., ->, except where line breaks and
indentation warrant whitespace, or where whitespace helps to read
expressions with more levels of braces. Although the latter should be
avoided anyway.
-- 
Stefan Richter
-=====-=-==- =--= --=-=
http://arcgraph.de/sr/

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

* CodingStyle
       [not found] <90e6ba4fc2a4f7dd3c04971cb0fa@google.com>
@ 2010-12-11  7:18 ` HarryWei
  0 siblings, 0 replies; 6+ messages in thread
From: HarryWei @ 2010-12-11  7:18 UTC (permalink / raw)
  To: linux-kernel

> 2010/12/11 Robert P. J. Day <rpjday@crashcourse.ca>
> 
> > On Sat, 11 Dec 2010, HarryWei wrote:
> >
> > > Hi all,
> > >       I just read the CodingSyle at Documentation directory in
> > linux-2.6.23 kernel source code.
> > >       But a problem happened to me like following.
> > >       Functions in linux-2.6.23/fs/fs-writeback.c are "static int" and
> > function name are in different lines.(function name in following line)
> > >       I can't find the rule in CodingStyle. That We often program
> > functions are "static int" and function name are in the same line.
> > >       When do we do the first or second way? What is different between
> > them?
> > >
> > >   Any answer is okay.
> > >   Best regards.
> >
> >   the advantage to the form
> >
> > static int
> > function-name
> >
> > is that, if you're looking for the actual function *definition* in the
> > file, having the function name at the start of a new line means you
> > can search for it with the pattern "^function-name" so that you don't
> > have to wade through all of the invocations of that function.
> >
> >  i like that style; others claim that with proper cross-referencers
> > like cscope, doing that is redundant.  as far as i know, the kernel
> > coding style doesn't take a position on that, but i'm willing to be
> > corrected.
Thanks, i see :)
> >
> > rday
> >
> > --
> >
> > ========================================================================
> > Robert P. J. Day                               Waterloo, Ontario, CANADA
> >                        http://crashcourse.ca
> >
> > Twitter:                                       http://twitter.com/rpjday
> > LinkedIn:                               http://ca.linkedin.com/in/rpjday
> > ========================================================================
> >
> 
> 
> 
> -- 
> Best Regards.
> Harry Wei.
> Do what u like!

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

* CodingStyle
@ 2013-04-18 10:48 Opensource [Anthony Olech]
  2013-04-18 13:41 ` CodingStyle Guenter Roeck
  0 siblings, 1 reply; 6+ messages in thread
From: Opensource [Anthony Olech] @ 2013-04-18 10:48 UTC (permalink / raw)
  To: Guenter Roeck, Opensource [Anthony Olech]; +Cc: LKML

> -----Original Message-----
> From: Guenter Roeck [mailto:linux@roeck-us.net]
> Sent: 18 April 2013 05:14
> To: Opensource [Anthony Olech]
> Cc: Jean Delvare; Mark Brown; Randy Dunlap; lm-sensors@lm-sensors.org;
> LKML; David Dajun Chen
> Subject: Re: [NEW DRIVER V5 6/7] drivers/hwmon: DA9058 HWMON driver
> 
[...]
> > +	if (cell == NULL) {
> > +		ret = -ENODEV;
> > +		goto exit;
> 
> Just return -ENODEV is good enough here. See CodingStyle, chapter 7.
> 
[...]
> > +exit:
> > +	return ret;
> > +}
[...]

Hi Guenter,

I have read CodingStyle, chapter 7 and it seems to encourage a single exit point from functions.

During development there was some logging done at the (single) exit point but that has been stripped out for submission.
Whilst I can duplicate the logging and do an immediate 'return' at all those points, I am hesitant to do so when chapter 7 of the CodingStyle appears to say to use a single exit point. In addition I had thought that a single exit point from functions was a good thing.

Tony Olech



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

* Re: CodingStyle
  2013-04-18 10:48 CodingStyle Opensource [Anthony Olech]
@ 2013-04-18 13:41 ` Guenter Roeck
  2013-04-18 16:06   ` CodingStyle Opensource [Anthony Olech]
  0 siblings, 1 reply; 6+ messages in thread
From: Guenter Roeck @ 2013-04-18 13:41 UTC (permalink / raw)
  To: Opensource [Anthony Olech]; +Cc: LKML

On Thu, Apr 18, 2013 at 10:48:06AM +0000, Opensource [Anthony Olech] wrote:
> > -----Original Message-----
> > From: Guenter Roeck [mailto:linux@roeck-us.net]
> > Sent: 18 April 2013 05:14
> > To: Opensource [Anthony Olech]
> > Cc: Jean Delvare; Mark Brown; Randy Dunlap; lm-sensors@lm-sensors.org;
> > LKML; David Dajun Chen
> > Subject: Re: [NEW DRIVER V5 6/7] drivers/hwmon: DA9058 HWMON driver
> > 
> [...]
> > > +	if (cell == NULL) {
> > > +		ret = -ENODEV;
> > > +		goto exit;
> > 
> > Just return -ENODEV is good enough here. See CodingStyle, chapter 7.
> > 
> [...]
> > > +exit:
> > > +	return ret;
> > > +}
> [...]
> 
> Hi Guenter,
> 
> I have read CodingStyle, chapter 7 and it seems to encourage a single exit point from functions.
> 
Yes, unless you can return directly. There is even an example.
It actually says "... and some common work such as cleanup has to be done".

> During development there was some logging done at the (single) exit point but that has been stripped out for submission.
> Whilst I can duplicate the logging and do an immediate 'return' at all those points, I am hesitant to do so when chapter 7 of the CodingStyle appears to say to use a single exit point. In addition I had thought that a single exit point from functions was a good thing.
> 
Not if you add a goto to a return statement. That defeats the purpose
of easy readability.

Guenter

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

* RE: CodingStyle
  2013-04-18 13:41 ` CodingStyle Guenter Roeck
@ 2013-04-18 16:06   ` Opensource [Anthony Olech]
  0 siblings, 0 replies; 6+ messages in thread
From: Opensource [Anthony Olech] @ 2013-04-18 16:06 UTC (permalink / raw)
  To: Guenter Roeck, Opensource [Anthony Olech]; +Cc: LKML

> -----Original Message-----
> From: Guenter Roeck [mailto:linux@roeck-us.net]
> Sent: 18 April 2013 14:42
> To: Opensource [Anthony Olech]
> Cc: LKML
> Subject: Re: CodingStyle
> 
> On Thu, Apr 18, 2013 at 10:48:06AM +0000, Opensource [Anthony Olech]
> wrote:
> > > -----Original Message-----
> > > From: Guenter Roeck [mailto:linux@roeck-us.net]
> > > Sent: 18 April 2013 05:14
> > > To: Opensource [Anthony Olech]
> > > Cc: Jean Delvare; Mark Brown; Randy Dunlap;
> > > lm-sensors@lm-sensors.org; LKML; David Dajun Chen
> > > Subject: Re: [NEW DRIVER V5 6/7] drivers/hwmon: DA9058 HWMON driver
> > >
> > [...]
> > > > +	if (cell == NULL) {
> > > > +		ret = -ENODEV;
> > > > +		goto exit;
> > >
> > > Just return -ENODEV is good enough here. See CodingStyle, chapter 7.
> > >
> > [...]
> > > > +exit:
> > > > +	return ret;
> > > > +}
> > [...]
> >
> > Hi Guenter,
> >
> > I have read CodingStyle, chapter 7 and it seems to encourage a single exit
> point from functions.
> >
> Yes, unless you can return directly. There is even an example.
> It actually says "... and some common work such as cleanup has to be done".

OK, thank you for clarifying that. I will make the necessary changes.
 
> > During development there was some logging done at the (single) exit point
> but that has been stripped out for submission.
> > Whilst I can duplicate the logging and do an immediate 'return' at all those
> points, I am hesitant to do so when chapter 7 of the CodingStyle appears to say
> to use a single exit point. In addition I had thought that a single exit point from
> functions was a good thing.
> >
> Not if you add a goto to a return statement. That defeats the purpose of easy
> readability.
> Guenter

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

end of thread, other threads:[~2013-04-18 16:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <90e6ba4fc2a4f7dd3c04971cb0fa@google.com>
2010-12-11  7:18 ` CodingStyle HarryWei
2013-04-18 10:48 CodingStyle Opensource [Anthony Olech]
2013-04-18 13:41 ` CodingStyle Guenter Roeck
2013-04-18 16:06   ` CodingStyle Opensource [Anthony Olech]
  -- strict thread matches above, loose matches on Subject: below --
2006-08-31 12:37 sound/pci/hda/intel_hda: small cleanups Pavel Machek
2006-08-31 13:01 ` Takashi Iwai
2006-08-31 18:04   ` CodingStyle (was: Re: sound/pci/hda/intel_hda: small cleanups) Randy.Dunlap
2006-09-02 23:15     ` Pavel Machek
2006-09-03  4:30       ` Randy.Dunlap
2006-09-05  8:08         ` Pavel Machek
2006-09-05 16:40           ` CodingStyle Stefan Richter
2006-09-05 16:40             ` CodingStyle Stefan Richter

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