From: David Benfell <benfell@parts-unknown.org>
To: Linux Kernel List <linux-kernel@vger.kernel.org>
Subject: Re: [OT?] Coding Style
Date: Tue, 23 Jan 2001 13:16:53 -0800 [thread overview]
Message-ID: <20010123131652.B2356@parts-unknown.org> (raw)
In-Reply-To: <3A6D78EA.5B09C379@coppice.org> <Pine.LNX.4.21.0101231716001.1713-100000@the-babel-tower.nobis-crew.org>
In-Reply-To: <Pine.LNX.4.21.0101231716001.1713-100000@the-babel-tower.nobis-crew.org>; from Pixel@the-babel-tower.nobis-crew.org on Tue, Jan 23, 2001 at 05:17:15PM +0100
[-- Attachment #1: Type: text/plain, Size: 3364 bytes --]
On Tue, Jan 23, 2001 at 05:17:15PM +0100, Nicolas Noble wrote:
>
> > a = b + c; /* add a to b, and store it as c */
>
> I think *this* comment is very fun, since it make me asking myself if I
> really know the C language :)
>
I trust we all got a chuckle out of this one.
I come from an era where obscure code was the rule and we were just
glad to have comments. So it's a little bit of a wake-up call when I
see the current debate.
There are a couple of memorable points I've seen so far here:
1) Linus points out that if you change the code, it will usually break
the formatting of a trailing comment.
2) A complaint that comments often don't jive with the code.
I think we're missing something here, mainly point #2. If you're
paying attention to the comments when you're modifying the code, point
#1 becomes a lot less critical because you should also be updating the
comments.
To state what (to me) seems like it must be obvious:
Sometimes solutions to problems are obviously correct. Sometimes they
aren't so obviously correct (emphasis on obviously). And, try as you
might, the increased complexity of modern code must surely have led to
new boobytraps. Comments are appropriate whenever the right solution
is not obviously correct or whenever you're tiptoeing through a
minefield of issues. They are appropriate whenever and wherever you
choose an efficient solution over one which is "human-readable."
Comments should be mandatory wherever you generate code which might be
misunderstood or when an obvious solution to one problem also happens
to fix something else which is a less obvious.
The argument which was made a while ago, which I think bears repeating
here, is that code serves two purposes:
1) the mechanical process of instructing the machine to do something.
2) to clearly communicate its purpose to any who may come later.
The first point is obvious. The second leads to lots of arguments on
style. (So programmers still don't want to type out long variable
names?)
What I would argue for here is the application of common sense. Write
a piece of code. Comment it as appropriate. Then look at it as if
you were attempting to explain it to someone else, not necessarily as
gifted as yourself. All of your explanation should be there, in
writing in well-formatted comments or in readable code. Your code has
a purpose (to solve a problem); it often helps to clearly state what
that problem is, then how your code addresses it.
Very often, this explanation takes a lot more space than you can tack
on at the end of a line of code. In that case, the comments should go
right where Linus says he wants them, in advance of the code you're
documenting, in near-essay form.
The point here is that the communication is the important thing. In
your haste to just generate that quick fix, you waste time later when
you or someone else tries to unravel what the hell you did. This is
not a new argument. I remember hearing it in school 25 years ago (so
you know it must be even older than that).
--
David Benfell
benfell@greybeard95a.com
---
The grand leap of the whale up the Fall of Niagara is esteemed, by all
who have seen it, as one of the finest spectacles in nature.
-- Benjamin Franklin.
[from fortune]
[-- Attachment #2: Type: application/pgp-signature, Size: 240 bytes --]
next prev parent reply other threads:[~2001-01-23 21:17 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-01-22 16:04 [OT?] Coding Style Jonathan Earle
2001-01-22 16:19 ` Mike Harrold
2001-01-22 16:22 ` Larry McVoy
2001-01-22 18:29 ` Richard B. Johnson
2001-01-22 23:20 ` Admin Mailing Lists
2001-01-23 0:54 ` Werner Almesberger
2001-01-23 12:28 ` Steve Underwood
2001-01-23 16:17 ` Nicolas Noble
2001-01-23 21:16 ` David Benfell [this message]
2001-01-23 12:52 ` Andrew Morton
2001-01-23 18:10 ` Stephen Satchell
2001-01-22 17:43 ` Gregory Maxwell
-- strict thread matches above, loose matches on Subject: below --
2001-01-23 22:22 Jonathan Earle
2001-01-23 16:47 Jesse Pollard
2001-01-24 0:07 ` Stephen Satchell
2001-01-23 15:41 Jonathan Earle
2001-01-23 15:58 ` Larry McVoy
2001-01-23 16:00 ` Mike Harrold
2001-01-23 16:14 ` Georg Nikodym
2001-01-23 18:05 ` Christopher Friesen
2001-01-23 18:41 ` Mathieu Chouquet-Stringer
2001-01-23 18:44 ` Georg Nikodym
2001-01-23 18:53 ` James Kelly
2001-01-23 16:32 ` Joe deBlaquiere
2001-01-24 1:14 ` Steve Underwood
2001-01-25 13:33 ` Kai Henningsen
2001-01-24 5:42 ` Brent Rowland
2001-01-24 5:50 ` Andre Hedrick
2001-01-25 13:25 ` Kai Henningsen
2001-01-25 19:30 ` Harald Arnesen
2001-01-26 0:20 ` James Stevenson
2001-01-23 17:42 ` John Kodis
2001-01-25 13:38 ` Kai Henningsen
2001-01-22 21:09 Stephen Satchell
2001-01-22 16:42 ` Mark I Manning IV
2001-01-22 23:56 ` Anton Altaparmakov
2001-01-23 0:01 ` Larry McVoy
2001-01-23 6:37 ` Stephen Satchell
2001-01-23 8:37 ` Helge Hafting
2001-01-23 18:58 ` Alan Olsen
2001-01-22 17:53 Jonathan Earle
2001-01-20 15:32 Anton Altaparmakov
2001-01-20 16:19 ` [OT?] " profmakx.fmp
2001-01-21 5:10 ` Ragnar Hojland Espinosa
2001-01-21 5:50 ` Admin Mailing Lists
2001-01-21 5:58 ` Mike A. Harris
2001-01-21 7:07 ` Josh Myer
2001-01-21 7:20 ` Alan Olsen
2001-01-21 22:40 ` Mo McKinlay
2001-01-22 0:23 ` Admin Mailing Lists
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=20010123131652.B2356@parts-unknown.org \
--to=benfell@parts-unknown.org \
--cc=linux-kernel@vger.kernel.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