From: Miles Bader <miles@gnu.org>
To: git@vger.kernel.org
Subject: Re: [RFC] struct *_struct
Date: Fri, 06 Aug 2010 11:28:23 +0900 [thread overview]
Message-ID: <87y6ckiiew.fsf@catnip.gol.com> (raw)
In-Reply-To: AANLkTin_6gaYF++N2GBgDsedfo7mY7yG5H99=-DxCa5E@mail.gmail.com
Michael Witten <mfwitten@gmail.com> writes:
> On Wed, Aug 4, 2010 at 14:24, Junio C Hamano <gitster@pobox.com> wrote:
>> I hate... "typedef foo struct foo"
>
> How come?
There is a practical issue in that "struct foo *" can be used with just
a forward declaration (or no declaration at all), whereas "foo *"
requires the declaration of foo be visible. This is especially handy
given C's use of #include, because in cases where there are circular
type references, it can be very annoying to get things #included in the
right order; being able to use a forward declaration instead of #include
makes it easy to break such loops. One can still use "struct foo *"
even if there are typedefs, of course, but that breaks the illusion that
"foo" is an abstract type, and I gather that illusion is one reason
people like the typedefs in the first place.
But I think mainly it's an issue of style/culture:
Some codebases use "typedef style" (obviously those in C++, since the
typedefs are automatically), and in those codebases programmers will
naturally choose typenames that are more distinct (e.g., the common
convention of using StudlyCaps for types). Some codebases use "struct
style" (in C programs I think this is more common, as C-programming
culture tends to value explicitness and simplicity).
One should use follow whatever style is common in the codebase one is
working on. If git uses "struct foo" generally, new code should use
"struct bar".
-miles
--
Arrest, v. Formally to detain one accused of unusualness.
prev parent reply other threads:[~2010-08-06 2:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-04 15:08 [RFC] struct *_struct Jared Hance
2010-08-04 19:24 ` Junio C Hamano
2010-08-04 21:38 ` [PATCH] Refactor structures in the form of *_struct Jared Hance
2010-08-05 16:20 ` [RFC] struct *_struct Michael Witten
2010-08-05 22:43 ` Jared Hance
2010-08-06 3:57 ` Michael Witten
2010-08-06 12:29 ` Jared Hance
2010-08-06 2:28 ` Miles Bader [this message]
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=87y6ckiiew.fsf@catnip.gol.com \
--to=miles@gnu.org \
--cc=git@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;
as well as URLs for NNTP newsgroup(s).