#ifdef considered harmful (was: DData)

Wolfgang Jeltsch wolfgang at jeltsch.net
Fri Apr 16 15:25:44 EDT 2004

Am Donnerstag, 15. April 2004 12:13 schrieb Simon Marlow:
> Robert Will writes:
> > I think what Haskellers (and others) can do in most cases is
> > to factor out
> > platform dependent parts to mini-modules which have different
> > implementations but the same interface.  The version of such
> > a module is
> > choosen by the path it resides in during the build process.  (Simplest
> > case: the -i option of the compiler.)
> I have to say, I dislike this approach to conditional compilation.
>   - it puts the conditional in the build system rather than the source
>     code, which means you have to look in the build system to find out
>     what the code means.

If the places for the modules for the different platforms are standardized 
then you don't have to look into the build system, do you?

>   - it means if I want to ask questions like "hmm, how does this differ
>     from the Windows version?"  I have to go find the windows version of
>     the file.

Is this a problem? The very big problem with the preprocessor approach is, in 
my opinion, that it's awkward to add a new platform.  With Robert's approach 
you just add some new files and don't touch the existing code.  With the 
preprocessor approach you need write access to the source code of the library 
in question, I'd say.

>   - the interface to the module is duplicated, and nothing is checking
>     that all your implementations have the same interface.

That's a problem, of course.

> [...]

> Cheers,
> 	Simon


More information about the Libraries mailing list