I don't think the importance of forward declarations is build speed (nor,
relatedly, size of .o files).
Post by William Chan (éæºæ)Do you have data you can share here on how forward declarations affect
build time? The reason I ask is because, internally within Google (for
Googlers, look for the internal C++ style mailing list thread titled
"Forward Declaration Efficiency Benefits") for our server-side code,
people have questioned this benefit and haven't found any supporting
evidence that forward declarations speed up the build. But Google's
internal code dependency graph is...special...and the build
infrastructure is special there too. But people are questioning the
benefit for that code base, which makes me wonder how much we benefit
in Chromium. If anyone has data, I'd love to see it.
Post by Philip JägenstedtYes, please! When trying to reduce compile time by removing includes a
few months ago, after the easy stuff it was usually enums that got in
the way of breaking dependencies further.
Philip
Post by Mounir LamouriAllow enum to be marked as classes.
Being able to forward declare enums which can be very good for public
interfaces and generally speaking reduces headers inclusions.
Internally, many people are unhappy with forward declaring classes. We
don't allow forward declaring functions, variables, etc. Why classes?
See 2) below.
Post by William Chan (éæºæ)For Googlers, you can read more details about this line of argument at
https://goto.google.com/fwd_decl_harmful.
I find that a dubious, one-sided document.
To my mind, there are two important uses for forward declarations (apart
from pure stupidity imposed by the language, such as allowing circular
references, even when the classes in question are in the same compilation
unit):
1) #includes in C++ are viral. Whatever you include in a header becomes
part of its public interface, whether you like it or not. I.e., if you
include a header, even if only for a private implementation detail, others
can and will rely on that include. If you remove that include, you'll have
to fix them. Compare .proto's "import" versus "import public".
Forward declarations allow you to avoid many such "private" inclusions,
even if they're not perfect (e.g., others will be able to rely on your
forward declaration). The only way of strictly avoiding this problem is
extreme and un-C++: separate things into interfaces and private impls, and
make factories for everything (and allocate everything on the head,
disallow construction of things on the stack or as member variables).
Being able to forward-declare enums also helps on this front -- e.g., if
you want to have a private member variable of some enum type (defined in
some other header).
2) There's a use-mention kind of distinction. It makes sense to, e.g., pass
pointers to objects around (i.e., "mention" objects) without knowing
anything about them. (E.g., a function/method may return a Foo*, and maybe
all the caller will ever do with that value is pass it on to something else
that takes a Foo* argument, without ever dereferencing it. There are
similar cases for other types.)
Types are different from functions and variables -- the latter are actual
instances of things.
Sadly, C++ breaks forward declarations (and/or makes them fragile) in
various ways: structs versus classes versus typedefs versus integral types,
templates, functions declared inline in headers, nested classes, and so on.
(Discussion of these breakages are the primary content of the above
document.)
Post by William Chan (éæºæ)The public Google C++ style
guide does provide a list of some of the downsides at
http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Forward_Declarations
.
Anyway, I'm just pointing this out because there's _some_ chance that
the internal version of the style guide might change, although no one
has enough data on non-internal code bases to bother with changing our
public C++ style guide. But if people have data to share, that'd be
very informative.
Post by Philip JägenstedtPost by Mounir LamouriThis is not about specifying a type on an enum for which I have no
opinion and no strong use cases.
http://en.cppreference.com/w/cpp/language/enum
-- Mounir
--
--
http://groups.google.com/a/chromium.org/group/chromium-dev
To unsubscribe from this group and stop receiving emails from it, send
To unsubscribe from this group and stop receiving emails from it, send an
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+***@chromium.org.