Version block "conditions" with logical operators

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Wed May 11 10:02:36 PDT 2016


On Tuesday, 10 May 2016 at 11:12:58 UTC, Tomer Filiba wrote:
> Hey guys,
>
> Looking at our code base (weka), I realized it would be really 
> useful if we had logical operators (negation, conjunction, 
> disjunction) in the version's "condition" clause. Here's what I 
> have in mind:
>
> version(!extra_checks) {
>     ...
> }
>
> version(dlang_ver_2069 || dlang_ver_2070) {
>     ...
> }
>
> Today we have lots of ugly code like
>
> version(unittest) {} else { ... }
>
> and bad-old copy-paste for the logical-or case I mentioned.
>
> Is there any reason for that versions can't take compound 
> logical conditions? Alternatively, an isVersion(x) predicate 
> that I could use in a static if could do the trick -- although 
> I think ``version(x || y)`` is more readable than ``static if 
> (isVersion(x) || isVersion(y))``
>
> I think it could be a useful feature. Any thoughts?
>
> -tomer

Still holding out hope Walter will change his mind here..

His rationale is based on keeping code clean and organized, but 
given that D has no preprocessor macros, it will never look as 
bad as C++ code, or even close.

Compounding versions in C++ accounts for a very small portion of 
the mess. When you have an #if VERS every 5 lines, however, 
you've got a problem...but then, you can do that with D's version 
just the same. The real solution is to properly encapsulate 
system-dependant code so that whatever version statement you 
need, is all in one place. Also when you have to hack 10 
different macros together to invent a feature your language 
doesn't have, you've got a problem, but this is much less of a 
concern in D than C++.

When even D gurus writing D compilers have to hack solutions 
together with static if to get by, its time to re-evaluate the 
situation.

    Bit


More information about the Digitalmars-d mailing list