Why version() ?

Nick Sabalausky a at a.a
Tue Feb 10 14:33:37 PST 2009


"Walter Bright" <newshound1 at digitalmars.com> wrote in message 
news:gmsqnh$6qi$1 at digitalmars.com...
>
> The version statement is designed to be inflexible. It's designed to 
> encourage abstracting and modularizing version differences, rather than 
> encouraging line-by-line differences.
>
> I've used #if/#endif for decades. Over time, it *always* degenerates into 
> an utter rat's nest of nested, incomprehensible complexity (and this 
> includes my own code). For a lovely example of how bad it can get, take a 
> look at the source code to Hans Boehm's garbage collector. I defy anyone 
> to figure it out without running the code through the preprocessor first 
> to see which statements are actually getting compiled.
>
> A far better way to do versioning is to find the abstraction lines 
> separating versions, and put version specific code in separate modules 
> that are then imported. It makes for nice, clean, understandable code.
>

This strikes me as throwing away the baby with the bathwater. If your code 
starts degenerating towards a versioning rat's nest, then the solution is to 
take a moment and refactor it into a larger granularity, not to throw away 
features that are useful in moderation.

>
> 1. Why not version(!feature) ?
>
> Because cognitive studies show that people just don't see the negation.

Isn't that moreso a case against the ! operator in general? I don't see how 
"if(!blah)" is any less susceptible to overlooking the ! than 
"version(!blah)".

> Secondly, when you see things like:
>
>     version (!linux) { ... }
>
> they're almost always wrong. Versions should be positive things, because a 
> version is something that is being build - one doesn't craft a makefile to 
> build a notLinux.
>

True, we don't build to a NotLinux, but we do however build to "everything 
except platform X". And I don't see how a "LinuxOrMac" (or worse yet, a 
"LinuxOr_MacAndSomeOtherCharacteristic_") is any more or less of a realistic 
platform than a "NotLinux".

Also, you didn't respond to the concerns about typos in a version 
identifier. Can we assume you agree that's a problem? 





More information about the Digitalmars-d mailing list