From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [U-Boot, 2/3] image: move all function comments to header file
Date: Sat, 20 Sep 2014 09:39:29 +0200 [thread overview]
Message-ID: <E1XVFGV-0006Yf-0X@janus> (raw)
In-Reply-To: <CAMhH57SBL4dLBpQmphkijZEQtkY0jF4g3hE6eCi8qU=i98m42Q@mail.gmail.com>
Hi Masahiro,
On Sat, 20 Sep 2014 14:34:29 +0900, Masahiro YAMADA
<yamada.m@jp.panasonic.com> wrote:
> Hi.
>
> I vote for comments near the implementation.
>
> I have been digging into the driver model code recently,
> but I have to admit it is unreadable because most of comments
> are placed in its header files.
> (and I am planning to send a patch to move comments to C sources.)
>
> I really want to know "what does this function do?" and "How is it used?" things
> before I start to read the detailed implementation.
>
> If they are written separately, I need to open two windows of my editor,
> one for reading the comments in a header file,
> the other for reading the implementation in a C source.
> I am really unhappy about that.
>
> I guess people often use tag jump utilities.
> (I like GNU Global, someone may use ctags/etags, cscope, etc. I don't know..)
>
> Such utilities allow us to jump over to the implementation place.
> If comments are not there, we have to look for comments by hand.
>
> I think we should keep in our mind this: source files are much more
> read than written.
> I believe we put the readers' benefits at the top priority.
The way I comment my own code (i.e., when not trying to adhere to
coding rules/guidelines, or to the custom in existing code) is that I
put comments in both places, declaration and definition, for two
different purposes.
I put a block comment before the declaration to tell readers how to
*use* the function -- what the arguments mean, what the result shall
be, what particular conditions should be met on call, etc.
That's for people who *use* my code.
I put a block comment before the definition to tell readers how the
function does its job, similar to a detailed design description but
without the algorithm, because I consider the source code to *be* the
detailed design algorithm.
That's for people who need to *change* my code.
(Then I put comments in the body code either to break it into
identified steps, or to indicate things that do not derive from the
design, e.g. compiler or linker bug workarounds, etc. but that's a bit
beyond the point.)
As I said, that's /my/ way of writing /my/ code, my .02 EUR given just
to point out that we don't necessarily have to decide to put comments in
header *xor* body.
Amicalement,
--
Albert.
next prev parent reply other threads:[~2014-09-20 7:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-15 20:55 [U-Boot] [PATCH v2 1/3] image: fix bootm failure for FIT image Bryan Wu
2014-08-15 20:55 ` [U-Boot] [PATCH 2/3] image: move all function comments to header file Bryan Wu
2014-08-15 22:01 ` Jeroen Hofstee
2014-08-15 22:07 ` Bryan Wu
2014-08-15 22:10 ` York Sun
2014-08-15 22:11 ` Bryan Wu
2014-08-15 22:14 ` Stephen Warren
2014-08-15 22:25 ` York Sun
2014-08-15 22:56 ` Bryan Wu
2014-08-18 18:18 ` Simon Glass
2014-08-23 12:42 ` [U-Boot] [U-Boot, " Tom Rini
2014-08-23 17:48 ` Tom Rini
2014-09-19 23:17 ` Simon Glass
2014-09-20 5:34 ` Masahiro YAMADA
2014-09-20 7:39 ` Albert ARIBAUD [this message]
2014-09-22 6:41 ` Simon Glass
2014-08-15 20:55 ` [U-Boot] [PATCH 3/3] bootm: make sure pass NULL when argc < 1 Bryan Wu
2014-08-22 20:36 ` [U-Boot] [PATCH v2 1/3] image: fix bootm failure for FIT image Simon Glass
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=E1XVFGV-0006Yf-0X@janus \
--to=albert.u.boot@aribaud.net \
--cc=u-boot@lists.denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.