From: "Robert White" <rwhite@casabyte.com>
To: "Larry McVoy" <lm@bitmover.com>, "Willy Tarreau" <willy@w.ods.org>
Cc: "Steven Cole" <elenstev@mesatop.com>, <linux-kernel@vger.kernel.org>
Subject: RE: Question about style when converting from K&R to ANSI C.
Date: Mon, 2 Jun 2003 20:15:22 -0700 [thread overview]
Message-ID: <PEEPIDHAKMCGHDBJLHKGAEBLCOAA.rwhite@casabyte.com> (raw)
In-Reply-To: <20030601140602.GA3641@work.bitmover.com>
My personal preference(s) are:
In C or naked scope of C++:
static inline
int function_name(type arg, type arg)
{
body
}
By putting the scope modifiers and compiler directives on one line and the
calling conventions on another it makes a distinction between what the user
needs to know as opposed to the compiler.
In C++ classes:
class ClassName {
static inline int function_name(type arg, type arg) { return expression; }
static inline int function_name(type arg, type arg) {
complex body;
}
ClassName();
virtual ~ClassName();
};
(If the above doesn't look right because of email handling cruft) The names
of the class and members all line up vertically, the destructor is proceeded
by seven spaces and a tilde instead of a tab (so the destructor "stands out"
in a quick code scan) and the "static" and "inline" in this usage are
actually part of the type of the member function of a class in a way that
they are only hints in a naked scope, so they move down onto the line
itself.
There is no good "find it" trick if you don't do the below, but if you do
use the rest of "my personal standard" then doing "egrep ')$'" gets you all
of the function definitions with only the occasional split-line-conditional,
and since I also "&&" and "||" those at the end of the line I never have
that problem either...
(And not that anybody asked)
if (test) {
code
} else {
more code
}
while (test) {
code
}
do {
code
} while (test);
and so on...
and also (for the advanced reader):
if ((conditional) &&
(conditional)) {
}
This one being "advanced" because it reads like a book but you have to "hold
in your head" were you are in the conditional more aggressively than the
prefixing version.
These preferences go back to when vi would delete lines if you scrolled down
through a file quickly using the arrow keys. Even in the absence of that
particular annoyance (because we don't need a vi versus emacs holy war flare
up, they are both evil anyway, even if I do use vi constantly 8-), I have
never liked the floating brace styles like
if (test)
{
code
}
because the code still works and even looks right if you accidentally
damage/remove the if. Just like "while (test);" on a line by itself is
transformed into a hang if the "do" ten pages up is removed.
if ((conditional)
&&(conditional))
{
code
}
is subject to problems on line delete too. Accidentally remove the "&&"
line and it is really easy to decide you made a parenthesis counting
mistake. If the conditional is on the leading line then when you see
if ((conditional) &&
{
code
}
you instantly know something is amiss.
Fully correct, the dropped line would leave
if ((conditional) &&
code
}
because the leading brace would have been eaten with the bad line too.
Neither positioning will protect you from dropping a middle term of three,
for obvious reasons.
AND MOST IMPORTANTLY:
while (test)
one line of code;
AND
if (test)
one line of code;
(etc) are fundamentally _*EVIL*_ (evil I say! do you hear me? EVIL!!!!! 8-)
Whatever the language designers might say, braces are not optional in
"morally correct" C or C++.
(I have maintained too much crappy code in my life, most of it written by
students, to think the other "standards" are anything but accidents waiting
to happen. The only reason the floating-brace standard is taught in schools
is because it makes red-pen grading easier because of the blank page space.)
Rob.
-----Original Message-----
From: linux-kernel-owner@vger.kernel.org
[mailto:linux-kernel-owner@vger.kernel.org]On Behalf Of Larry McVoy
static inline int cdrom_write_check_ireason(ide_drive_t *drive, int len, int
ireason)
{
}
vs
static inline int
cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason)
{
}
next prev parent reply other threads:[~2003-06-03 3:02 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-01 5:56 Steven Cole
2003-06-01 6:39 ` Arnaldo Carvalho de Melo
2003-06-01 6:43 ` Zwane Mwaikambo
2003-06-01 13:14 ` Alan Cox
2003-06-01 19:10 ` Zwane Mwaikambo
2003-06-01 13:26 ` Larry McVoy
2003-06-01 13:49 ` Willy Tarreau
2003-06-01 14:06 ` Larry McVoy
2003-06-01 14:22 ` Willy Tarreau
2003-06-01 15:02 ` Steven Cole
2003-06-01 15:09 ` Larry McVoy
2003-06-01 15:50 ` Steven Cole
2003-06-01 16:02 ` Larry McVoy
2003-06-01 16:18 ` Steven Cole
2003-06-01 23:01 ` Paul Mackerras
2003-06-01 23:30 ` Steven Cole
2003-06-03 3:29 ` Robert White
2003-06-01 16:04 ` Jonathan Lundell
2003-06-01 16:11 ` Larry McVoy
2003-06-01 16:46 ` Steven Cole
2003-06-01 16:52 ` Larry McVoy
2003-06-01 17:18 ` Steven Cole
2003-06-02 12:39 ` Jesse Pollard
2003-06-03 3:15 ` Robert White [this message]
2003-06-01 13:53 ` Scott Robert Ladd
2003-06-02 2:09 ` Linus Torvalds
2003-06-02 2:21 ` Larry McVoy
2003-06-02 2:26 ` Davide Libenzi
2003-06-02 3:15 ` Steven Cole
2003-06-02 15:54 ` Erik Hensema
2003-06-03 12:32 ` Martin Waitz
2003-06-03 12:45 ` Dave Jones
2003-06-03 12:51 ` Jörn Engel
2003-06-03 13:18 ` Henning P. Schmiedehausen
2003-06-03 13:27 ` Richard B. Johnson
2003-06-03 13:39 ` William Lee Irwin III
2003-06-03 14:44 ` Henning Schmiedehausen
2003-06-03 15:16 ` William Lee Irwin III
2003-06-03 15:25 ` Randy.Dunlap
2003-06-03 15:38 ` William Lee Irwin III
2003-06-03 15:40 ` Randy.Dunlap
[not found] <20030601060013$0d74@gated-at.bofh.it>
[not found] ` <20030601134006$4765@gated-at.bofh.it>
[not found] ` <20030602022006$78ca@gated-at.bofh.it>
[not found] ` <20030602160025$70e8@gated-at.bofh.it>
2003-06-02 16:09 ` Pascal Schmidt
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=PEEPIDHAKMCGHDBJLHKGAEBLCOAA.rwhite@casabyte.com \
--to=rwhite@casabyte.com \
--cc=elenstev@mesatop.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lm@bitmover.com \
--cc=willy@w.ods.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
all inboxes | Powered by JetHome®