--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
--
the other hacker pointed out the benefits to build speed, and declined to include-what-he-uses.
--
Just to clarify for myself: if I include class X which derives from class Y, I don't have to also include Y's header right?
In your example, X *must* include Y.h, since you cannot derive from a
forward-declared base class (the size of the base class must be
known). So your class (B?) should be guaranteed that Y.h is always
included if X.h is included. From what I've seen in the current
codebase, this seems to be consistent assumption.
If X is refactored to no longer be-a Y, then adding Y.h (if needed)
should be part of the normal cleanup involved with breaking the X is-a
Y relationship, since B is a dependent on that is-a relation.
In the context of the larger question, I had assumed that IWYU
naturally followed from the comments on forward declares at
http://www.chromium.org/developers/coding-style/cpp-dos-and-donts
Since the preference when defining any interface/implementation is to
forward declare, dependents of anything but an is-a relationship
should be including what they use, since the dependency may be
refactored at any point to forward declare the types, rather than
include their headers.
So if code is calling a method on X, |Z* X::DoFoo()|, then that caller
should be including Z.h in it's implementation file, since X may have
followed (or be made to follow) the C++ Dos and Dont's and just
forward declared Z.
The same would apply for |Z X::DoFoo()| (note: no pointer), since X
can still forward declare Z safely.
So if X can ever forward declare the type (which it can, in many
cases), you should include Z.h. If X cannot forward declare (for
example, it has-a Z member), you should still include Z.h, since
depending on that has-a relationship is an implementation detail, and
not part of the public interface. That's why I thought IWYU was
implied.
We tried it a while ago, and it wasn't ready back then. Maybe that has
changed, but chances are there is some upstream work involved.
Nico
On Fri, Nov 18, 2011 at 19:12, John Abd-El-Malek <j...@chromium.org> wrote:Just to clarify for myself: if I include class X which derives from class Y, I don't have to also include Y's header right?I would go with this. In fact, I would go further (this may be controversial): If a method Foo() of X requires that it have defined Z (e.g., by including Z's header), then I may use Z in direct connection with X::Foo() without including Z's header.E.g., if the method is |Z X::Foo()|, I would allow |Z z = x.Foo();| without an explicit inclusion of Z.h. But if I have an independent use of Z elsewhere, I would want to include Z.h.
On Fri, Nov 18, 2011 at 7:20 PM, Viet-Trung Luu <viettr...@chromium.org> wrote:On Fri, Nov 18, 2011 at 19:12, John Abd-El-Malek <j...@chromium.org> wrote:Just to clarify for myself: if I include class X which derives from class Y, I don't have to also include Y's header right?I would go with this. In fact, I would go further (this may be controversial): If a method Foo() of X requires that it have defined Z (e.g., by including Z's header), then I may use Z in direct connection with X::Foo() without including Z's header.E.g., if the method is |Z X::Foo()|, I would allow |Z z = x.Foo();| without an explicit inclusion of Z.h. But if I have an independent use of Z elsewhere, I would want to include Z.h.As we enumerate reasonable exceptions to the rule like these, I start to question the value of the rule. The rule is no longer simple, and it seems like there will just remain a constant din of confusion around this rule.
On Fri, Nov 18, 2011 at 7:20 PM, Viet-Trung Luu <viettr...@chromium.org> wrote:On Fri, Nov 18, 2011 at 19:12, John Abd-El-Malek <j...@chromium.org> wrote:Just to clarify for myself: if I include class X which derives from class Y, I don't have to also include Y's header right?I would go with this. In fact, I would go further (this may be controversial): If a method Foo() of X requires that it have defined Z (e.g., by including Z's header), then I may use Z in direct connection with X::Foo() without including Z's header.E.g., if the method is |Z X::Foo()|, I would allow |Z z = x.Foo();| without an explicit inclusion of Z.h. But if I have an independent use of Z elsewhere, I would want to include Z.h.As we enumerate reasonable exceptions to the rule like these, I start to question the value of the rule. The rule is no longer simple, and it seems like there will just remain a constant din of confusion around this rule.
On Fri, Nov 18, 2011 at 7:20 PM, Viet-Trung Luu <viettr...@chromium.org> wrote:On Fri, Nov 18, 2011 at 19:12, John Abd-El-Malek <j...@chromium.org> wrote:Just to clarify for myself: if I include class X which derives from class Y, I don't have to also include Y's header right?I would go with this. In fact, I would go further (this may be controversial): If a method Foo() of X requires that it have defined Z (e.g., by including Z's header), then I may use Z in direct connection with X::Foo() without including Z's header.E.g., if the method is |Z X::Foo()|, I would allow |Z z = x.Foo();| without an explicit inclusion of Z.h. But if I have an independent use of Z elsewhere, I would want to include Z.h.As we enumerate reasonable exceptions to the rule like these, I start to question the value of the rule. The rule is no longer simple, and it seems like there will just remain a constant din of confusion around this rule.
On Fri, Nov 18, 2011 at 7:20 PM, Viet-Trung Luu <viettr...@chromium.org> wrote:On Fri, Nov 18, 2011 at 19:12, John Abd-El-Malek <j...@chromium.org> wrote:Just to clarify for myself: if I include class X which derives from class Y, I don't have to also include Y's header right?I would go with this. In fact, I would go further (this may be controversial): If a method Foo() of X requires that it have defined Z (e.g., by including Z's header), then I may use Z in direct connection with X::Foo() without including Z's header.E.g., if the method is |Z X::Foo()|, I would allow |Z z = x.Foo();| without an explicit inclusion of Z.h. But if I have an independent use of Z elsewhere, I would want to include Z.h.As we enumerate reasonable exceptions to the rule like these, I start to question the value of the rule. The rule is no longer simple, and it seems like there will just remain a constant din of confusion around this rule.Maybe I'm just biased since I've always been happy including only what I need.One pet-peeve I have is when I see someone unnecessarily including build/build_config.h. It is included by base/basictypes.h, and therefore it is pretty much included into every since .cc file. It feels like unnecessary verbosity to have to include build/build_config.h everywhere, redundantly. IWYU would suggest that you should.
- Gavin
- Gavin- Gavin
-Darin- Gavin- Gavin
As we enumerate reasonable exceptions to the rule like these, I start to question the value of the rule. The rule is no longer simple, and it seems like there will just remain a constant din of confusion around this rule.Maybe I'm just biased since I've always been happy including only what I need.
One pet-peeve I have is when I see someone unnecessarily including build/build_config.h. It is included by base/basictypes.h, and therefore it is pretty much included into every since .cc file. It feels like unnecessary verbosity to have to include build/build_config.h everywhere, redundantly. IWYU would suggest that you should.
On Tue, Nov 22, 2011 at 12:41, Darin Fisher <da...@chromium.org> wrote:As we enumerate reasonable exceptions to the rule like these, I start to question the value of the rule. The rule is no longer simple, and it seems like there will just remain a constant din of confusion around this rule.Maybe I'm just biased since I've always been happy including only what I need.We can argue about the extent and details of the rule, but I think that IWYU is important and prevents fragility. It's quite annoying to remove an include from your header, only to have to track down and fix a bunch of other places which were unwittingly relying on it.
One pet-peeve I have is when I see someone unnecessarily including build/build_config.h. It is included by base/basictypes.h, and therefore it is pretty much included into every since .cc file. It feels like unnecessary verbosity to have to include build/build_config.h everywhere, redundantly. IWYU would suggest that you should.In this particular example, I have to disagree: The (very common)#if defined(OS_FOO)...#endifconstruct is exceedingly fragile, and will fail silently if somehow build/build_config.h isn't included. (Arguably, we should replace that construct with something less fragile, though that ship sailed a long time ago.) I'd say that this is even more important in headers that use OS_FOO macros, since they're less likely to include base/basictypes.h.
On Tue, Nov 22, 2011 at 7:04 PM, Viet-Trung Luu <viettr...@chromium.org> wrote:On Tue, Nov 22, 2011 at 12:41, Darin Fisher <da...@chromium.org> wrote:As we enumerate reasonable exceptions to the rule like these, I start to question the value of the rule. The rule is no longer simple, and it seems like there will just remain a constant din of confusion around this rule.Maybe I'm just biased since I've always been happy including only what I need.We can argue about the extent and details of the rule, but I think that IWYU is important and prevents fragility. It's quite annoying to remove an include from your header, only to have to track down and fix a bunch of other places which were unwittingly relying on it.Yes, I agree that can be annoying. It certainly isn't very easy to search-n-replace to resolve such errors. Many try bot runs are often required. Hmm...It seems like a similar problem exists with IWYU. Suppose everyone is happily including X.h, but I want to factor out a portion of X.h to create Y.h. If the rule is that everyone should exactly include what they use, then I will now need to hunt down everyone who needs Y.h instead of X.h and either add a Y.h include or change the X.h include to a Y.h include. This seems fairly tedious too. However, I suppose we could have tools to help us here.
Cheers,
Jói
2011/11/23 James Hawkins <jhaw...@chromium.org>: