Controversy!

Our beloved coding style reads:
"Forward-declare classes in your header files instead of including them 
whenever possible."
https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style#CC_practices

I guess the main goal is to keep build times lower by reducing the number of 
nested includes.

Now I've heard the view is that if a public function takes a type, the header 
should include the necessary dependent header for that type instead of just a 
forward declaration, so that users of that function will not have to include it 
themselves.
(But forward-declaring types only used internally by the header's own types is 
still fine.)

E.g., for:
  class SomeClass
  {
  public:
    void foo(SomeType* aPtr);
  private:
    SomeOtherType* mValue;
  }

Our coding style says that we should just have `class SomeType; class 
SomeOtherType;` above that class.

My friend would prefer `#include "SomeType.h" class SomeOtherType;`.
This way all users of SomeClass only need to include SomeClass.h, not 
SomeType.h, when they want to call SomeClass::foo.


My personal thoughts:

I can see how nice this can be for users of SomeClass.

But then, maybe not all includers of SomeClass.h would use foo (assuming 
there's more in that file).
Also some callers of SomeClass::foo may also just be passing a pointer (e.g. a 
proxy), so they don't need to include "SomeType.h" either.
And of course, this could add to the overall build time.

So I personally still prefer the coding style as is, but I wanted to discuss 
this here to see how others feel...

Flame away!
Gerald
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to