Tor Didriksen wrote:
> On Wed, 24 Jun 2009 17:14:03 +0200, Michael Widenius
> <monty@stripped> wrote:
>> 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.
This is one of the first things we tackled in Drizzle. We found that
there was a spiderweb of #includes that made it:
* Nearly impossible to easily state which files were being included in
the current source compilation, and more importantly *which order* files
were being included (#ifdef MYSQL_SERVER anyone?!)
* Difficult to determine *where* key structures and classes were defined
(sql_class.h, sql_base.h, structs.h, definitions.h, unireg.h,
mysql_priv.h, etc etc etc...)
* SLOWER compilation speeds since large numbers of class and struct
definitions needed to be "pulled in" to a source compilation for no
reason whatsoever -- Drizzle's compilation speed has dramatically
improved since we tackled the #include mess.
One thing I *still* haven't been able to "unplug" is the mess in
sql_lex.h which partially compiles the parser with this wonderful block
of ugly:
/*
The following hack is needed because mysql_yacc.cc does not define
YYSTYPE before including this file
*/
#ifdef DRIZZLE_SERVER
# include <drizzled/set_var.h>
# include <drizzled/item/func.h>
# ifdef DRIZZLE_YACC
# define LEX_YYSTYPE void *
# else
# if defined(DRIZZLE_LEX)
# include <drizzled/lex_symbol.h>
# include <drizzled/sql_yacc.h>
# define LEX_YYSTYPE YYSTYPE *
# else
# define LEX_YYSTYPE void *
# endif /* defined(DRIZZLE_LEX) */
# endif /* DRIZZLE_YACC */
#endif /* DRIZZLE_SERVER */
I believe this is the very last place that DRIZZLE_SERVER (MYSQL_SERVER)
is used in the Drizzle source code. Every time I've tried to break this
monster up, I've gone down a rathole...but I know it's possible to do
it. Maybe Mats will figure it out and I can buy him a beer or two :)
Cheers,
Jay