remove keywords
Christopher Wright
dhasenan at gmail.com
Fri Dec 7 16:35:12 PST 2007
Jarrett Billingsley wrote:
> "Walter Bright" <newshound1 at digitalmars.com> wrote in message
> news:fjb8c6$2nqs$1 at digitalmars.com...
>> The version statement is limited in that you cannot do !foo or
>> foo&&bar||baz. Rather than a bug, that is deliberate. I've seen a lot of
>> code that, over the years, accumulated detritus like:
>>
>> #if FOO || BAR>0x1234 && BAZ && !HACK
>>
>> These tend to snarl themselves into such a rat's nest of conditionals the
>> only way to figure out which lines actually got compiled was to examine
>> the preprocessor output. (Another consequence of these is that,
>> inevitably, the various conditionals were WRONG as they were layered on by
>> people who didn't really understand the code.)
>>
>> So, by limiting the version statement, the idea is to encourage the
>> programmer to think in terms of distinct versions being generated, and
>> then code in terms of those distinct versions - each of those versions
>> having a name.
>
> 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;
>
> 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.
I've dealt with production code -- a mere 5k line project -- that was
ported manually to four operating systems (Linux, HPUX, Darwin, and I
think FreeBSD). My task was to convert it to use autotools.
Ugly. Horrible. Terrible. I wanted to find the coders and shoot them.
You're recommending an autoconf-like system, basically. Which I commend.
But then you just code for version(has_feature). And your config file
might be relatively large, with several entries for each OS. So you'd have:
// dll stuff
version(linux || darwin || bsd)
version = UseDlfcn;
else
version = UseDll;
// socket stuff
...
I would prefer:
version(linux)
version = UseDlfcn;
// ...
version(darwin)...
It works with the current syntax, and it is equally organized. It's
easier to see, given a platform, what versions you have defined. On the
other hand, it's a bit harder to see whether a particular version is
defined.
More information about the Digitalmars-d
mailing list