On 3/13/14, 17:43, Walter Bright wrote:
On 3/13/2014 3:21 PM, Timon Gehr wrote:
On 03/13/2014 02:32 PM, Steven Schveighoffer wrote:
The one I would really like to see is logical OR. There is no easy way
around this, one must come up with convoluted mechanisms that are much
harder to design, write, and understand than just version(x || y)
version(A) version=AorB;
version(B) version=AorB;
version(AorB){ }
If you're writing things like that, it's still missing the point. The
point is not to find workarounds, but to rethink just what feature is
being version'd on.
For example, suppose it's wrapping a call to SomeWackyFunction:
version (Linux)
SomeWackyFunction();
else version (OSX)
SomeWackyFunction();
else
... workaround ...
Execrable answer:
version (Linux) version=LinuxOrOSX;
version (OSX) version=LinuxOrOSX;
...
version (LinuxOrOSX)
SomeWackyFunction();
else
... workaround ...
This is execrable because LinuxOrOSX:
1. has no particular relationship to SomeWackyFunction()
2. makes for confusion if LinuxOrOSX is used also to version in other
things
3. makes for what do I do if I add in FreeBSD? Rename to
LinuxOrOSXOrFreeBSD ? yeech
Better answer:
version (Linux) version=hasSomeWackyFunction;
version (OSX) version=hasSomeWackyFunction;
...
version (hasSomeWackyFunction)
SomeWackyFunction();
else
... workaround ...
At least this is maintainable, though it's clumsy if that code sequence
appears more than once or, worse, must be replicated in multiple modules.
Even better:
--------
import wackyfunctionality;
...
WackyFunction();
--------
module wackyfunctionality;
void WackyFunction() {
version (Linux)
SomeWackyFunction();
else version (OSX)
SomeWackyFunction();
else
... workaround ...
}
--------
Simple, maintainable, easy on the eye.
...And code duplication everywhere!