lkml.org 
[lkml]   [2008]   [Aug]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch]fastboot: remove duplicate unpack_to_rootfs()

* Andrew Morton <akpm@linux-foundation.org> wrote:

> On Wed, 13 Aug 2008 09:52:36 +0200 Ingo Molnar <mingo@elte.hu> wrote:
>
> > no-newline-before-return:
> >
> > kfree(header_buf);
> > return message;
> > }
>
> I accidentally delete those newlines when nobody is looking. They
> don't seem worth the space they consume.

yeah - for me it's case-dependent. My benchmark for it is absolutely
objective and easy to describe: i add a newline when it looks nicer and
more maintainable that way ;-)

> (what do we do with a function which has multiple `return's?)

i really didnt want to make a full scale style discussion out of this.
Lets ignore my suggestion. The valid case when i use a newline is for
example when the return obscures what happens:

if (something) {
do_one();
repeat_this();
return;
}

as visually it's easy to miss the return - especially if the lines above
it look similar. So i use:

if (something) {
do_one();
repeat_this();

return;
}

because way too often do i miss a stray return somewhere and
misunderstand the code flow of a function if it does not stand out, even
with syntax highlighting.

Another case is when there's a long linear block of cleanup statements
followed by a return:

q->mode = mode;
strcpy(q->name, name);
q->next = NULL;
*p = q;
return NULL;
}

i usually add a newline:

q->mode = mode;
strcpy(q->name, name);
q->next = NULL;
*p = q;

return NULL;
}

as the 'return NULL' is a separate concept from the preceding
activities.

So in this case it is not really because the return is specialy, this is
because i like to separate groups of statements per type of activity. So
i'd do the same if there were two groups of statements, i'd turn this:

q->mode = mode;
strcpy(q->name, name);
q->next = NULL;
*p = q;
other_stuff = 2;
some_other_stuff(other_stuff)

into this:

q->mode = mode;
strcpy(q->name, name);
q->next = NULL;
*p = q;

other_stuff = 2;
some_other_stuff(other_stuff)

to make sure the two groups of statements stand out. (Sometimes a pure
newline does a better job at inserting the right kind of visual
structure than a comment line.)

but again ... these are nuances where reasonable people might disagree,
and i only made them because this topic lives, is developed and tested
in tip/fastboot at the moment.

Ingo


\
 
 \ /
  Last update: 2008-08-13 11:17    [W:0.047 / U:0.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site