Messages in this thread | | | Date | Tue, 30 Sep 2008 10:33:52 +0200 | From | Ingo Molnar <> | Subject | Re: A style question: repeated return value check |
| |
* 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
| |