On Wed, 24 Jun 2009 17:14:03 +0200, Michael Widenius <monty@stripped>
wrote:
>
> Hi!
>
>>>>>> "Tor" == Tor Didriksen <Tor.Didriksen@stripped> writes:
>
> <cut>
>
>>> class Table_ident; /* Need to be before include of sql_yacc.h */
>>> class Item_num;
>>> class String;
>>> class Key_part_spec;
>>> struct TABLE_LIST;
>>> typedef struct st_udf_func udf_func;
>>> typedef struct st_lex_user LEX_USER;
>>> #include "sql_list.h" /* Pull in List<> */
>>> #include "set_var.h" /* Pull in sys_var_with_base */
>>> #include "sql_yacc.h" /* Pull in symbol definitions */
>>>
>>> For each line, I had to do a symbol search to find the definition of it
>>> and see
>>> how and where it was defined. Most other files have similar
>>> dependencies...
>>>
>>> /Matz
>
> Tor> wow!
> Tor> Each header file should have been self-contained of course, there
> should
> Tor> be no need for forward declarations before #include
>
> There is no 'of course' in that.
>
> If you try to do every include file self-contained, you need a LOT of
> more includes 'just in case' and dependents that just creates more
> code, more parsing without giving you anything.
>
> 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.
#include mysql_priv which pulls in just about everything, yes.
This practice makes it impossible to do unit testing.
'include or declare what you use' is a very simple rule,
and makes the code much more maintainable and testable.
-- didrik
>
> The benefit of this is:
> - Easier to decide what to include
> - Faster compile time for all compilers
> - MUCH faster compile time for compilers that support precompiled
> headers.
> - Easier to handle header files with conditionals as you are less
> likely to include these before all the required definitions are
> defined.
>
> Regards,
> Monty