Board index » cppbuilder » Couldn't BCB's form designer automatically forward declare?

Couldn't BCB's form designer automatically forward declare?


2005-05-12 06:21:06 AM
cppbuilder37
When BCB's desgner sticks #include statements for their classes in a .h file couldn't
it instead put forward declares in the .h and the real includes in the .cpp?
 
 

Re:Couldn't BCB's form designer automatically forward declare?

In article <42828551$ XXXX@XXXXX.COM >,
Randall Parker < XXXX@XXXXX.COM >wrote:
Quote
When BCB's desgner sticks #include statements for their classes in a .h file
couldn't
it instead put forward declares in the .h and the real includes in the .cpp?
Put the suggestion into QC.
<qc.borland.com/wc/qcmain.aspx>
 

Re:Couldn't BCB's form designer automatically forward declare?

"Randall Parker" < XXXX@XXXXX.COM >wrote in
message news:42828551$ XXXX@XXXXX.COM ...
Quote
When BCB's desgner sticks #include statements for their classes in
a .h file couldn't it instead put forward declares in the .h and the real
includes in the .cpp?
Why?
Gambit
 

{smallsort}

Re:Couldn't BCB's form designer automatically forward declare?

Remy Lebeau (TeamB) wrote:
Quote
"Randall Parker" < XXXX@XXXXX.COM >wrote in
message news:42828551$ XXXX@XXXXX.COM ...
>When BCB's desgner sticks #include statements for their classes in
>a .h file couldn't it instead put forward declares in the .h and the real
>includes in the .cpp?


Why?
So if you include that that form's .h file in another file you do not get as much
stuff to compile.
Quote


Gambit


 

Re:Couldn't BCB's form designer automatically forward declare?

"Randall Parker" < XXXX@XXXXX.COM >wrote in
message news: XXXX@XXXXX.COM ...
Quote
So if you include that that form's .h file in another file you do
not get as much stuff to compile.
There won't be that much to compile, since every header has a guard to
prevent from exactly that.
Gambit
 

Re:Couldn't BCB's form designer automatically forward declare?

Remy Lebeau (TeamB) wrote:
Quote
"Randall Parker" < XXXX@XXXXX.COM >wrote in
message news: XXXX@XXXXX.COM ...


>So if you include that that form's .h file in another file you do
>not get as much stuff to compile.


There won't be that much to compile, since every header has a guard to
prevent from exactly that.

Do you mean include guards ?
If so they arenīt of that much help. They prevent the header to be
compiled multiple times in the same cpp unit, but not from being parsed.
To prevent the header from being parsed you have to wrap all include
instructions including the header file with the same include guards.
E.g.:
File: Other.h
#ifndef HEADERH
#include "HEADER.h"
#endif
.....
File: header.h
#ifndef HEADERH
#define HEADERH
....
Each cpp file, which is including this header file, has to compile the
header file again, if thereīs no additional include guard around the
include instruction.
So if you have a header file being 1 MB large (Ok heavily oversized ;-)
) which is included in every cpp file, the compiler has to parse and
compile 1 MB for each cpp unit.
Even worse if you include this header file multiple times AFAIK the
compiler will add this file multiple times to the cpp file.
Even if the compiler will preprocess the files and wonīt add them to the
"in memory" built cpp file, it at least has to parse the header file
each time itīs included.
Which IMHO is a huge waste of performance and resources.
The only way to prevent this is:
a) Additional guards around each include instruction
b) Precompiled header file (prevents multiple compilation - not parsing)
c) Pimpl idiom, with forward declaration
d) Forward declaration
e) Unit concept should be added to the standard
Quote

Gambit


Andre
 

Re:Couldn't BCB's form designer automatically forward declare?

Remy Lebeau (TeamB) wrote:
Quote

There won't be that much to compile, since every header has a guard to
prevent from exactly that.

The guard only prevents multiple compilations, but each header will
still be compiled once.
I think this would be a very worthwhile feature.
Cheers
Russell
 

Re:Couldn't BCB's form designer automatically forward declare?

"Russell Hind" < XXXX@XXXXX.COM >wrote in message news: XXXX@XXXXX.COM ...
Quote
The guard only prevents multiple compilations, but each header will
still be compiled once.

I think this would be a very worthwhile feature.
Making it stop declaring the class extern at the end
of the header and inserting a global points in the
beginning of the cpp file would be a good thing
as well. I usually have to change both of these things
whenever using the designer.
 

Re:Couldn't BCB's form designer automatically forward declare?

On Wed, 11 May 2005 15:21:06 -0700, Randall Parker wrote:
Quote
When BCB's desgner sticks #include statements for their classes in a .h file couldn't
it instead put forward declares in the .h and the real includes in the .cpp?
It would still need the definition of the TForm base class. The
header file containing this needs most of the classes header files as
well including other base classes. Even if it could sensibly be
separated into two parts, the effort might be better spent in smarter
handling of re-included header files so that compiler doesn't have to
re-scan the file looking for #if #else #endif tokens.
Graeme
 

Re:Couldn't BCB's form designer automatically forward declare?

Randall Parker wrote:
Quote
When BCB's desgner sticks #include statements for their classes in a .h
file couldn't it instead put forward declares in the .h and the real
includes in the .cpp?
I like the idea. I always try to forward declare stuff, whenever it's
possible.
Furthermore, I think it would be very helpful to have an option of
declaring all components on a form private. It helps maintaining a
better encapsulation and improve code quality. Right now it's way too
tempting to refer from one form to components on another form, which
kills reusability and introduces unnecessary dependencies, which is a
maintenance hazard in the long run. Visual Studio .NET has this feature,
and by default all components dropped on forms are declared private.
This makes programmers less lazy and enforces them to rethink their
design. Of course for compatibility reasons and for RAD/prototyping you
still want to have the freedom of declaring everything public, but in a
large-scale project it doesn't work out well.
I don't think __published and private are mutually exclusive. It should
be possible for the IDE/designer to see your components on a form via
reflection, while the same declarations be private from the compiler's
point of view.
I'm only talking about components dropped on a form or frame. Published
properties of a component are expected to be public of course.
Tom
 

Re:Couldn't BCB's form designer automatically forward declare?

Andre Kaufmann wrote:
Quote
e) Unit concept should be added to the standard
You mean something like this? <g>
www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1778.pdf
AlisdairM(TeamB)
 

Re:Couldn't BCB's form designer automatically forward declare?

Remy Lebeau (TeamB) wrote:
Quote
Why?
Improved modularity.
Every header you include introduces new names, and increases chances
for accidental (or at least undocumented) dependencies to creep in. It
is not so much the headers, as the additional headers they bring in
turn.
Worse, BCB pollutes the global namespace with a lot of these names, so
it can be hard to defend yourself against some accidental name
overloads, and this is a really subtle bug when it occurs (read, hard
and therefore expensive to track and fix.)
Note that this rampant fowarding of include files is banned in some
coding conventions (our own for instance) and the only place we can do
nothing about it is the generated header files Borland give us.
Even if we fix them manually, the includes are added back so this is
not something we can solve ourselves - it needs Borland action.
That said, I would rather see compiler bug fixes given a higher
priority, but that has been my hobby horse for some time <g>
I agree this is a great issue to have in QC.
AlisdairM(TeamB)
 

Re:Couldn't BCB's form designer automatically forward declare?

Andre Kaufmann wrote:
Quote
Even if the compiler will preprocess the files and wonīt add them to
the "in memory" built cpp file, it at least has to parse the header
file each time itīs included. Which IMHO is a huge waste of
performance and resources.

The only way to prevent this is:

a) Additional guards around each include instruction
b) Precompiled header file (prevents multiple compilation - not
parsing)
Note that these 2 solutions may reduce the parsing overhead, but do
nothing to address the name pollution. The more names that are in
scope, the more work the compiler must do to resolve name lookup - so
this is a cost that is continually paid even after initial mechanical
parsing.
And still ignores the risk introduced of changing overload resolution
to match functions you did not even know existed...
AlisdairM(TeamB)
 

Re:Couldn't BCB's form designer automatically forward declare?

Andre Kaufmann wrote:
Quote

Do you mean include guards ?
If so they arenīt of that much help. They prevent the header to be
compiled multiple times in the same cpp unit, but not from being parsed.
To prevent the header from being parsed you have to wrap all include
instructions including the header file with the same include guards.
Instead of #ifdef and #endif we need something like:
#endfile
or
#pragma stopparsingfile
That way it wouldn't have to scan for the #endif to see if anything is after it.
Though a really smart build system could in theory remember that a given file has
nothing after the #endif and know it doesn't have to look at it again.
 

Re:Couldn't BCB's form designer automatically forward declare?

Randall Parker wrote:
Quote
#pragma stopparsingfile

That way it wouldn't have to scan for the #endif to see if anything is
after it.

Though a really smart build system could in theory remember that a given
file has nothing after the #endif and know it doesn't have to look at it
again.
If a first line of a header file is the #ifdef guard, then Borland C++
compiler will ignore that file if it has already seen it. It won't parse
it again to search for the #endif, it will simply abort this repeated
#include.
.a