remove keywords

Sean Kelly sean at f4.ca
Fri Dec 7 05:45:05 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. 

There's always static if.


Sean



More information about the Digitalmars-d mailing list