mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Shaohua Li <shaohua.li@intel.com>,
	lkml <linux-kernel@vger.kernel.org>,
	Arjan van de Ven <arjan@infradead.org>
Subject: Re: [patch]fastboot: remove duplicate unpack_to_rootfs()
Date: Wed, 13 Aug 2008 11:14:17 +0200	[thread overview]
Message-ID: <20080813091417.GH23417@elte.hu> (raw)
In-Reply-To: <20080813010605.b4a55f9b.akpm@linux-foundation.org>


* 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

  reply	other threads:[~2008-08-13  9:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-13  6:07 Shaohua Li
2008-08-13  7:45 ` Ingo Molnar
2008-08-13  7:52   ` Ingo Molnar
2008-08-13  8:06     ` Andrew Morton
2008-08-13  9:14       ` Ingo Molnar [this message]
2008-08-13  8:11     ` Frans Meulenbroeks
2008-08-13  9:15       ` Ingo Molnar
2008-08-13  8:00   ` Li, Shaohua
2008-08-13  9:26   ` Li, Shaohua
2009-03-15 18:23 [2.6.30] What's in the async boot tree Arjan van de Ven
2009-03-15 18:25 ` [PATCH] fastboot: remove duplicate unpack_to_rootfs() Arjan van de Ven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080813091417.GH23417@elte.hu \
    --to=mingo@elte.hu \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shaohua.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®