mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Daniel Barkalow <barkalow@iabervon.org>
Cc: Michael Gerdau <mgerdau@tiscali.de>,
	Philippe Elie <phil.el@wanadoo.fr>,
	Russell Leighton <russ@elegant-software.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: OT: Does Linux have any "Perfect Code"
Date: Sat, 17 Nov 2007 09:44:14 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.64.0711170941340.32153@anakin> (raw)
In-Reply-To: <Pine.LNX.4.64.0711150940560.12193@iabervon.org>

On Thu, 15 Nov 2007, Daniel Barkalow wrote:
> On Thu, 15 Nov 2007, Michael Gerdau wrote:
> > > This code is far to be perfect, some part is outdated, bcopy() use instead
> > > of memcpy() for example. More annoying are the comment, the file is 3306
> > > lines while there is only 1640 line of code, nothing bad per se but looking
> > > some comments:
> > > 
> > >  		/*
> > >  		 * Before we begin this operation, disable kernel preemption.
> > >  		 */
> > >  		kpreempt_disable();
> > 
> > <disclaimer>
> > I'm not a kernel developer.
> > </disclaimer>
> > 
> > That having said:
> > I really do like such obvious (as in: for those knowing the stuff anyway)
> > comments when looking at code and probably concepts I'm not familiar with.
> >
> > ...
> > 
> > I mean, isn't the whole purpose of comments to help those not familiar
> > with the code to understand it's purpose and possibly the intention of
> > the author (just in case the author had coded a bug) ?
> 
> That's the problem with really obvious comments. In the example above, 
> that function had better disable kernel preemption with a name like that, 
> and, assuming it's before the code begins the operation in sequence, we 
> know when we're doing it. But the comment fails to explain why we need to 
> disable kernel preemption before beginning the operation, just that we are 
> doing so. Having the comment merely distracts the reader from the fact 
> that the purpose of the code and the intention of the author are 
> completely undocumented. And there's a realy chance that this comment or 
> ones like it cause this statement and the place in the code where things 
> would go wrong if preemption weren't disabled to not fit on the reader's 
> screen together, so it is not only unclear what the author's intention 
> was, but it is harder to figure out from looking at the code than it would 
> be without comments, because fewer clues are actually visible at the same 
> time, since each of them takes up extra screen space.
> 
> The code itself should be written to tell the reader everything there is 
> to know about what it does, and the comments in code should only tell the 
> reader why it does that.

Agreed!

At work we used to have a contractor who documented _every_ single statement
with a literal C/C++-to-English translation. Nobody liked it, except
him. It was completely unreadable.
Of course a few of these comments went out-of-sync with the actual
code...

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

  reply	other threads:[~2007-11-17  8:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-15  1:21 Russell Leighton
2007-11-15  1:33 ` David Miller
2007-11-15  6:29 ` Eric Dumazet
2007-11-15  7:11   ` David Miller
2007-11-15  7:43   ` Andi Kleen
2007-11-15  8:27 ` Philippe Elie
2007-11-15 13:16   ` Michael Gerdau
2007-11-15 15:10     ` Daniel Barkalow
2007-11-17  8:44       ` Geert Uytterhoeven [this message]
2007-11-15 17:05     ` Chris Friesen

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=Pine.LNX.4.64.0711170941340.32153@anakin \
    --to=geert@linux-m68k.org \
    --cc=barkalow@iabervon.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgerdau@tiscali.de \
    --cc=phil.el@wanadoo.fr \
    --cc=russ@elegant-software.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®