Good examples of version() algebra in real code

max haughton maxhaton at gmail.com
Sun May 21 19:23:49 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')
It's not bad to try and make good look good. Most programming 
language design decisions boil down to some kind of aesthetically 
driven heuristic.


Current state of affairs is oppressive because it makes common 
cases expensive. That being said a lot of `version` usage 
shouldn't exist. Let the compiler constant fold the details for 
you so your code ports to new architecture/cross target more 
easily




More information about the Digitalmars-d mailing list