Good examples of version() algebra in real code

Basile B. b2.temp at gmx.com
Tue May 23 10:01:37 UTC 2023


On Sunday, 21 May 2023 at 18:43:32 UTC, Dennis wrote:
> D's version() statement deliberately does not allow composing 
> version conditions with boolean operators `! || &&`, in order 
> to avoid C's `#ifdef` hell. This is a controversial design 
> decision though, because some people don't like the resulting 
> verbosity you sometimes get. Discussions about this come up now 
> and then, see for example [Issue 
> 7417](https://issues.dlang.org/show_bug.cgi?id=7417) and its 
> duplicates.
>
> The most recent incarnation of this comes from this Phobos PR 
> proposing a library solution:
> [std.compiler.Version](https://github.com/dlang/phobos/pull/8750)
>
> ```D
> import std.compiler;
>
> static if (Version.D_InlineAsm_X86 || 
> Version.D_InlineAsm_X86_64)
> {
>     version = UseX86Assembly;
> }
> ```
>
> I don't expect this to get approval though, I said in the PR 
> discussion:
>
>> I'll bring this up in the next DLF monthly meeting, but 
>> without new compelling arguments, I don't expect a different 
>> outcome. If you can demonstrate problems (other than it not 
>> looking nice) in existing projects that the current logic 
>> causes, you'll have a stronger case.
>
> So far I haven't received any real code examples, so I'm asking 
> here:
>
> Do you have any examples of existing projects (on github, dub, 
> etc.) that either:
>
> - demonstrate version algebra done well
> - use a `Version`-like template successfully
> - have real problems with existing `version()` statements 
> (besides 'it looks ugly')
>
> Please reply with links and don't rekindle the old arguments. I 
> can't stop you, but know that it will only be 
> counter-productive.

One thing that is not mentioned is the grammar of version 
algebra...what would be allowed ? Do we want things like

     version(mixin(someCtfeCall(())

How would be handled the fact that

     enum BigEndian = 0.123;

is ATM legal, i.e identifiers can be both expressions and sealed 
version identifiers ?

There are already bugs caused by the fact that `static if`s can 
introduce `version`s... it's probably not worth introducing 
version algebra until those get fixed.


More information about the Digitalmars-d mailing list