Re: What sense do h files make in c/cpp?
On Jul 2, 11:33 pm, xz <zhang.xi...@gmail.com> wrote:
But I was not asking about Single File vs Multiple Files.
I definitely understand the significance of separating code into
different files.
However, why don't we always put the code describing one object, i.e.
both the declaration and the definition of one class, in the same
file, say, the cpp file?
Because that's a bad policy. The two are generally the
responsibility of two different people. It's important to keep
them separate, and since files seem to be the organisational
method of choice...
When using this class, you can simply include the corresponding cpp
file, instead of include the h file like what we are currently doing.
Again, files seem to be the organisational method of choice:-).
In this case, the choice has been made by the build
system---all of the build systems I know are file based.
Including a .cpp file will mean recompiling all of the client
code any time you make a minor change in the implementation.
Definitly to be avoided.
And again, it would mean that you cannot acquire modification
rights on the implementation without also acquiring them on the
interface. Which is not a good thing.
If the use of h file is only for the speed of compiling, I don't see
much significance.
You don't see much significance between having to recompiler 20
or 30 lines, and having to recompile 2 million lines, just
because of trivial change in the implementation?
It's not worth to make the structure of the files much more
complicated only to save a little compiling time.
First, I think that the "complexity" is necessary for other
reasons anyway. But I don't consider a difference between 5 or
10 seconds and several hours just "a little".
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34