public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Pekka Paalanen <pq@iki.fi>
Cc: linux-kernel@vger.kernel.org,
	Frederic Weisbecker <fweisbec@gmail.com>,
	rostedt@goodmis.org
Subject: Re: A style question: repeated return value check
Date: Tue, 30 Sep 2008 10:33:52 +0200	[thread overview]
Message-ID: <20080930083352.GA10374@elte.hu> (raw)
In-Reply-To: <20080929221439.547d65ec@daedalus.pq.iki.fi>


* Pekka Paalanen <pq@iki.fi> wrote:

> >  kernel/trace/trace.c |   77 ++++++++++++++++++++++++++-----------------------
> >  kernel/trace/trace.h |   10 ++++++-
> >  2 files changed, 50 insertions(+), 37 deletions(-)
> > 
> > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> > index 6ada059..61f33da 100644
> > --- a/kernel/trace/trace.c
> > +++ b/kernel/trace/trace.c
> [...]
> > @@ -1633,24 +1633,24 @@ static int print_trace_fmt(struct trace_iterator *iter)
> >  
> >  	ret = trace_seq_printf(s, "%16s-%-5d ", comm, field->pid);
> >  	if (!ret)
> > -		return 0;
> > +		return TRACE_TYPE_PARTIAL_LINE;
> >  	ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
> >  	if (!ret)
> > -		return 0;
> > +		return TRACE_TYPE_PARTIAL_LINE;
> >  	ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
> >  	if (!ret)
> > -		return 0;
> > +		return TRACE_TYPE_PARTIAL_LINE;
> 
> Off-thread style question: Would it be better or worse to write the 
> above as
> 
> 	ret = trace_seq_printf(s, "%16s-%-5d ", comm, field->pid);
> 	ret = ret && trace_seq_printf(s, "[%03d] ", iter->cpu);
> 	ret = ret && trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
> 	if (!ret)
> 		return TRACE_TYPE_PARTIAL_LINE;
> 
> which would do exactly the same, but is more compact.
> Good or bad style?

in this particular case it's marginally worse style i think, even 
considering that it makes the code more compact. The reason is that it 
makes the code a tiny bit less obvious: the flow looks a bit unusual and 
when skimming it i'd have to look once more to understand its purpose. 
With the returns its more verbose but also plain obvious. YMMV.

	Ingo

  reply	other threads:[~2008-09-30  8:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-29 18:18 [PATCH V2 -tip 1/4] Tracing/ftrace: Change the type of the print_line callback Frederic Weisbecker
2008-09-29 19:14 ` A style question: repeated return value check Pekka Paalanen
2008-09-30  8:33   ` Ingo Molnar [this message]
2008-09-30  8:48     ` Frédéric Weisbecker
2008-09-30  8:50       ` Frédéric Weisbecker

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=20080930083352.GA10374@elte.hu \
    --to=mingo@elte.hu \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pq@iki.fi \
    --cc=rostedt@goodmis.org \
    /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