remove keywords
Walter Bright
newshound1 at digitalmars.com
Fri Dec 7 12:10:09 PST 2007
Jarrett Billingsley wrote:
> You tell me which is more readable:
>
> version(linux || darwin || bsd)
> version = UseDlfcn;
> else
> version = UseDLLs;
>
> vs.
>
> version(linux)
> version = UseDlfcn;
> else version(darwin)
> version = UseDlfcn;
> else version(bsd)
> version = UseDlfcn;
> else
> version = UseDLLs;
I'm going to say the latter is more readable, especially when under each
os there are a series of version declarations. The former approach is
used by, for example, the Hans Boehm garbage collector, and I have found
it very difficult to follow.
> It only gets worse when you actually *need* complex versioning, and when the
> contents of those version blocks become more than trivial. Yes, you can
> define intermediate versions like I've done here, but even that becomes
> tedious and hard to read.
When the versioning becomes complex, there are alternative ways of
managing it. One way that works well is to factor out version
differences into version specific modules, with a general purpose api to
those modules. Yes, this is more work, but when I've done it the results
have been well worthwhile.
More information about the Digitalmars-d
mailing list