On Thu, Jan 12, 2017 at 02:42:52AM -0500, Boris Zbarsky wrote:
> On 1/12/17 2:30 AM, gsquel...@mozilla.com wrote:
> > This way all users of SomeClass only need to include SomeClass.h, not 
> > SomeType.h, when they want to call SomeClass::foo.
> 
> They don't need to have SomeType.h included merely to call SomeClass::foo.
> They have the forward-declaration in scope, so they can pass along SomeType*
> values they get from somewhere, and don't even have to forward-declare it
> themselves to do so.  e.g. this would be a perfectly sane consumer of
> SomeClass:
> 
>   #include "SomeClass.h"
>   #include "SomeOtherClass.h" // also forward-declares SomeType
> 
>   void PassLongFoo(SomeClass* inst)
>   {
>     inst->foo(SomeOtherClass::getSomeType());
>   }
> 
> where SomeOtherClass has a static getSomeType() returning SomeType*. None of
> this requires any of the files involved to include SomeType.h.
> 
> What _does_ require including SomeType.h is if you plan to construct a
> SomeType, or manipulate SomeType instances in some way.  But in that case,
> you really should be including SomeType.h yourself instead of relying on
> SomeClass to do it for you, in my opinion.
> 
> > I can see how nice this can be for users of SomeClass.
> 
> Until SomeClass stops using SomeType and those users stop compiling because
> they are still doing things with it but no longer getting the include
> courtesy of SomeClass.  This is especially pernicious with unified
> compilation, because it can take some time to notice.
> 
> > So I personally still prefer the coding style as is
> 
> I do too.

+1

The sad part is that it's not followed enough.

Mike
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to