Why version() ?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Feb 10 16:22:37 PST 2009


Steven Schveighoffer wrote:
> "Walter Bright" wrote
> Think of code that is versioned around architecture that would look 
> horrendous if you have to do version statements that have all different 
> combinations of stuff.  If I have 5 different architectures to support, I 
> don't want to have to define a module that has 2^5 different version 
> combinations.  On top of that, the way versioning works, you need 2^4 * 5 
> different statements:
> 
> version(A)
> {
>    version = AorB;
>    version = AorC;
>    version = AorD;
>    version = AorE;
>    version = AorBorC;
>    version = AorBorD;
>    // ad nauseum.
> }
> version(B)
> {
>    // oh fun! let's do it again!!!!
>    version = AorB;
>    version = BorC;
>    version = BorD;
>    ...
> }
> 
> When I add another architecture, *gasp* I have to double the statements (to 
> do them now with and without version(F) ), and now I have to do another 2^5 
> statements for the version(F) block.  Wheee!

But this is clearly the wrong way of cutting the pie. What you need is 
define features that are supported by some of the versions. You don't 
need to judge in terms of logical operators between versions.

version (A) version = canBeUsedToPickupChicks;
version (C) version = canBeUsedToPickupChicks;
// version (B) no good


Andrei



More information about the Digitalmars-d mailing list