My undesired 2 cents on include style (that I don't always follow)...

1.  I try not to include headers from within headers.  If I need to include
"header_a.h" in order for "header_b.h" to work then I do that in the source
file unless "header_a.h" is an invisible header that will never be included
only from within "header_b.h".  Like the g++ "bits" headers, for example.
 You'd never include them directly.  Similarly I include parent classes
headers in header files, but only if the parent class in never to be used
in the main source code.  Also, when I'm editing a source file, I prefer to
see the headers I've included.  The authors of wx apparently disagree.

2.  I think it's a bad idea to include standard headers and library headers
from within header files unless you're operating with explicit namespaces.
 (i.e. no "using" directives, which is a good idea in itself).

3.  I think that omnibus headers that include everything are bad, with the
exception where a compiler or OS is so broken that you need to put all of
the conditional fixes in one place. (cough... windows... cough).  But I
don't include that header in a build on other operating systems.  But even
then there will be files that need to unincluded from some source files or
included in different orders.  And then there's all the headers I don't
really need cluttering up my namespace.

4.  Headers aren't compiled for a reason.  Every file potentially sees a
conditionally different header.  Precompiliing assumes that every source
file is going to want to see about the same header and that will save time.
  But the most common use is speeding up compiles that use Omnibus
headers. Precompiling might save a few seconds (then again maybe not), but
the cost is compatibility between compilers and operating systems.  I've
never found a good reason to use them.

YMMV.

On Wed, Aug 1, 2012 at 1:32 PM, Rom Walton <[email protected]> wrote:

> The rule exists for Windows as well.
>
> Including the pre-compiled header via the command line avoids the compiler
> error.
>
> ----- Rom
>
> -----Original Message-----
> From: [email protected] [mailto:
> [email protected]] On Behalf Of [email protected]
> Sent: Wednesday, August 01, 2012 4:28 PM
> To: Nicolás Alvarez
> Cc: BOINC Developers Mailing List; [email protected]
> Subject: Re: [boinc_dev] Coding style and includes.
>
> If I recall correctly, the pre-compiled header has to be first in windows
> as well.
>
> jm7
>
>
> |------------>
> | From:      |
> |------------>
>
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
>   |Nicolás Alvarez <[email protected]>
>
> |
>
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
> |------------>
> | To:        |
> |------------>
>
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
>   |BOINC Developers Mailing List <[email protected]>
>                                                                            |
>
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
> |------------>
> | Date:      |
> |------------>
>
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
>   |08/01/2012 04:25 PM
>                                                                           |
>
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
> |------------>
> | Subject:   |
> |------------>
>
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
>   |Re: [boinc_dev] Coding style and includes.
>                                                                            |
>
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
> |------------>
> | Sent by:   |
> |------------>
>
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
>   |<[email protected]>
>                                                                            |
>
> >--------------------------------------------------------------------------------------------------------------------------------------------------|
>
>
>
>
>
> Well, gcc also supports "force-including" via the command line. But that's
> still a valid point. If the way we use precompiled headers needs it to be
> included in the .cpp file, I'd say it's a valid exception to the rule.
>
> --
> Nicolás
>
> 2012/8/1 Rom Walton <[email protected]>:
> > That might break pre-compiled header use on platforms other than Windows.
> I think I am force including the pre-compiled header in the Windows
> project files.
> >
> > Generally compilers enforce the first include file has to be the
> pre-compiled header file before all others.
> >
> > It may not be a big deal.
> >
> > ----- Rom
> >
> > -----Original Message-----
> > From: [email protected] [
> mailto:[email protected]] On Behalf Of David Anderson
> > Sent: Wednesday, August 01, 2012 4:15 PM
> > To: [email protected]
> > Subject: Re: [boinc_dev] Coding style and includes.
> >
> > OK, let's adopt this convention.
> > -- David
> >
> > On 01-Aug-2012 12:54 PM, Nicolás Alvarez wrote:
> >> I wouldn't really reverse it; going from general to specific is good
> >> too. As David Coss said, Google's C++ guidelines are worth looking.
> >> It's basically a combination of what you said and what I said: first
> >> the .h file for this .cpp file, and *then* go from general to
> >> specific (system headers, other libraries' headers, BOINC's headers).
> >>
> _______________________________________________
> boinc_dev mailing list
> [email protected]
> http://lists.ssl.berkeley.edu/mailman/listinfo/boinc_dev
> To unsubscribe, visit the above URL and
> (near bottom of page) enter your email address.
>
> _______________________________________________
> boinc_dev mailing list
> [email protected]
> http://lists.ssl.berkeley.edu/mailman/listinfo/boinc_dev
> To unsubscribe, visit the above URL and
> (near bottom of page) enter your email address.
> _______________________________________________
> boinc_dev mailing list
> [email protected]
> http://lists.ssl.berkeley.edu/mailman/listinfo/boinc_dev
> To unsubscribe, visit the above URL and
> (near bottom of page) enter your email address.
>
>
_______________________________________________
boinc_dev mailing list
[email protected]
http://lists.ssl.berkeley.edu/mailman/listinfo/boinc_dev
To unsubscribe, visit the above URL and
(near bottom of page) enter your email address.

Reply via email to