No need for version expression is a lie

Hipreme msnmancini at hotmail.com
Mon Aug 21 21:21:03 UTC 2023


On Monday, 21 August 2023 at 19:27:57 UTC, Walter Bright wrote:
> On 8/21/2023 11:46 AM, Basile B. wrote:
>> However that approach was used. It really looks like an 
>> alternative to a version OrOr. There are plenty of other 
>> examples in drutime sources.
>
> Druntime was written by many people, and does not exhibit 
> consistent best practices.
>
>> Sure at some point there is also the problem of the unix 
>> standards...Every distribution can choose its own value for 
>> the flag of this func or that one...which creates complexity 
>> in C `define`s, but should not in D. There is a problem that 
>> is not solved.
>
> I've dealt with enough professional C .h files to conclude that 
> #ifdef algebra is the worst solution. This includes the ones I 
> have written.
>
> The objectives of minimizing keystrokes and maximizing clarity 
> are only rarely aligned.
>
> I understand that many of D's design decisions are out of step 
> with conventional wisdom. They aren't the result of reading 
> about best practices, but instead decades of living with those 
> practices.

I had the same opinion as the OP before, but one thing Walter is 
correct is that it is better for you to define version presets.

One thing I can't agree is the `static assert` approach, if you 
have a really big library, partially porting it makes it quite 
unfeasible, having ways to just test is a really nice feature.

Also, for not being that verbose, like `if(a) b = true; if(c) b = 
true`, I would rather just put the defaults and only change the 
cases which are different.

One thing that also works even better IMO is using:

```d
version(MICROBLAZE) version = UseDefault;
else version (SH) version = UseDefault;
else version (ARM_Any) version = UseDefault;
else version (IBMZ_Any) version = UseDefault;
else version (IA64) version = UseDefault;

     version(UseDefault)
       private enum DEFAULTS = true;
```

This pattern has been work really well for me and it makes easier 
read than only thinking about the "table approach"(unless we 
really had a table). This also makes your code a lot more 
consistent. You can even save your version combination as a 
`static if` thing (and try to use it as if it were a version).



More information about the Digitalmars-d mailing list