Good examples of version() algebra in real code

Hipreme msnmancini at hotmail.com
Mon May 22 02:01:10 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.

Keep in mind that I have found plenty of codes when defining a 
`version` based on `static if`. This bug probably occurs for them 
being parsed at different stages of the compiler, I would be 
using that if weren't for the bugs.

Right now I've come to understand that using feature based 
versions instead of real versions really makes a lot of 
difference. But as Guillaume pointed out, there is still this 
other problem of defining a feature based on multiple platforms 
and this solution doesn't really make one write a lot less, so I 
still find this solution lacking for our problem which makes me 
wonder if there really exists a good solution for that.


More information about the Digitalmars-d mailing list