>>>>> "Tor" == Tor Didriksen <Tor.Didriksen@stripped> writes:
>> MySQL was design with the idea that you in most cases only have to
>> include one (but in practice a few) include files in each source file.
Tor> #include mysql_priv which pulls in just about everything, yes.
Tor> This practice makes it impossible to do unit testing.
There is nothing that stops you from testing one unit, just because
you include a more include files than you need.
Why would it do that ?
After all, when you include 'stdio.h', you are including a lot of
files and references to functions that you are not using and it
shouldn't stop you from doing an unit test.
Actually, you are at risk if having irrelevant unit tests if you don't
do things the same way for the unit test, as you do in the code your
are using it with. See below...
Tor> 'include or declare what you use' is a very simple rule,
Tor> and makes the code much more maintainable and testable.
I disagree strongly with this.
Having a 'master include' that everyone needs to include
makes life simpler and is less risky for bugs:
- You don't have to have a huge, impossible to maintain include list
in each .c file.
- You don't have to add new include files just because you add a call
to another function.
- People forget to remove include files when changing/moving code.
The include files in the beginning of the file will over time
include much 'noise'.
- Having different include files makes compilation notable slower on
all compilers/systems that supports precompiled headers.
- For example, Microsoft recommends one to have master include files,
just because of the above (at least they did when I last worked with
- You can not be sure that the 'unit test' you are using will
will not be tested in the right environments compared to the
original programs as some of the include files you don't include
may change the environment (for examples with defines or #ifdefs).
Having one or a many include files in each .c file is a matter of
taste and I personally prefer to have one major include file for each
From the practice I have with MySQL, I can say that it the current
style has made things much easier and have allowed us to avoid a lot
of bugs and time. It's true that this is at the expense that in the
few cases we have to add a new include file, one has to think a bit
where to include them but compared to the overall coding process
this time is neglectable.