July 31
On Wednesday, 31 July 2024 at 06:11:15 UTC, Walter Bright wrote:

> version (x86_64)
> {
>     enum FOO
>     {
>        A = 5,
>        B = 6,
>        C = 7,
>     }
> }
> else version (AArch64)
> {
>    enum FOO
>    {
>        A = 5,
>        B = 6,
>        C = 17,
>    }
> }
> else
>     static assert(0);
> ```
>
> Ah, doesn't that look nicer?

It's been said maybe a billion times why this solution rarely works in the read world. And the arguments have been dismissed in the classic D way.
August 01
On 01/08/2024 4:04 AM, Max Samukha wrote:
> On Wednesday, 31 July 2024 at 06:11:15 UTC, Walter Bright wrote:
> 
>> version (x86_64)
>> {
>>     enum FOO
>>     {
>>        A = 5,
>>        B = 6,
>>        C = 7,
>>     }
>> }
>> else version (AArch64)
>> {
>>    enum FOO
>>    {
>>        A = 5,
>>        B = 6,
>>        C = 17,
>>    }
>> }
>> else
>>     static assert(0);
>> ```
>>
>> Ah, doesn't that look nicer?
> 
> It's been said maybe a billion times why this solution rarely works in the read world. And the arguments have been dismissed in the classic D way.

Yeah not supporting this, just doesn't fit D anymore.

Too many people try it, which shows that it is clearly good language design.

It helps to fulfill peoples ideas, so an easy win to me.
July 31
On 7/31/2024 2:23 AM, IchorDev wrote:
> your suggestion forsakes the DRY principle.

Indeed, it does. Consider the evolution of expertise:

1. novice - follows the rules because he's told to

2. master - follows the rules because he understands the point of the rules

3. guru - violates the rules because he understands when the rules don't apply

BTW, your example looks fine as it is!
July 31
On 7/31/2024 10:51 AM, Richard (Rikki) Andrew Cattermole wrote:
> Too many people try it, which shows that it is clearly good language design.

People try all kinds of things in programming, eventually they evolve towards Best Practices.
August 01
On 01/08/2024 7:08 AM, Walter Bright wrote:
> On 7/31/2024 10:51 AM, Richard (Rikki) Andrew Cattermole wrote:
>> Too many people try it, which shows that it is clearly good language design.
> 
> People try all kinds of things in programming, eventually they evolve towards Best Practices.

Luckily we have Dscanner, so if it turns out a pattern gets too complex and therefore is not best practice, we can throw a warning at it without breaking code!

Which severely diminishes any possible objections.
July 31
On 7/31/2024 9:04 AM, Max Samukha wrote:
> It's been said maybe a billion times why this solution rarely works in the read world.
I know, it comes up regularly.

A classic case is the antecedent where a list of operating system enum values changes with each platform.

I've had the dubious pleasure of having to fix the equivalent for struct fields that vary by operating system, and were wrong because it's hard to compare a mess of conditional compilation with the operating system spec which does not have conditionals in it.

Let's look at the original again:

```
enum FOO {
    A = 5,
    B = 6,
version (x86_64) {
    C = 7,
} else version (AArch64) {
    C = 17,
} else {
    static assert(0);
}
    E = 9, // fixed that!
}
```

The example does follow best practice by adding the static assert for an unanticipated operating system. Now, let's add a G for AArch64:

```
enum FOO {
    A = 5,
    B = 6,
version (x86_64) {
    C = 7,
} else version (AArch64) {
    C = 17,
} else {
    static assert(0);
}
    E = 9,
    G = 10,
}
```

Does x86_64 have a G, or not? Is the programmer going to check each supported system for G? No, they're not. Are they going to wrap it in its own version declaration? Nope. (Even if they do, it runs afoul of what to do about the else clause.) I see it again and again. I fix them again and again. Sometimes they are never caught at all.

One could put G in the AArch64 block, but then it is out of order, making it hard to check them against the operating system spec which will be in order.

But if the operating systems are in separate declarations, this is not an issue. The person adding G to x86_64 doesn't need to check operating systems he's not familiar with.

Getting the enum values wrong results in really hard to debug failures.

I know you don't find this convincing.
August 01

On Wednesday, 31 July 2024 at 16:04:43 UTC, Max Samukha wrote:

>

And the arguments have been dismissed in the classic D way.

Yes it feels a bit like a dogma, which is not really the D way IMO… we have a lot of choice about how we write code to best meet our needs. Especially with meta-programming—think of Pegged or similar.

August 01
On Wednesday, 31 July 2024 at 19:08:13 UTC, Walter Bright wrote:
> On 7/31/2024 10:51 AM, Richard (Rikki) Andrew Cattermole wrote:
>> Too many people try it, which shows that it is clearly good language design.
>
> People try all kinds of things in programming, eventually they evolve towards Best Practices.

?

Someone who starts at haskell will end up very different then someone who starts with c; to say nothing of different kinds of problems.

No. If you ask 5 80 year old programmers youll get 5 different answers for whats a "best practice" we all wont "evolve" to the same answers for the foreseeable future.
August 01

On Wednesday, 31 July 2024 at 19:03:32 UTC, Walter Bright wrote:

>

Indeed, it does. Consider the evolution of expertise:

  1. novice - follows the rules because he's told to
  2. master - follows the rules because he understands the point of the rules
  3. guru - violates the rules because he understands when the rules don't apply

He this, he that. Where is ‘they’ when you need it?
Nonetheless, when you say to do things one way, people will feel that they have to follow. I’ve seen a lot of horrendous enum repetition in D because of this mentality that ‘we have to do things the bad way because it’s correct’. Before I took over BindBC-SDL it had so much repetition because of this design pattern. I replaced all the enum types with typeless lists, but now people can’t just iterate over the members of an enum properly. Relegating something that’s easy to do anywhere else (structs, unions, classes) to mixins is just cruel and encourages people to make unreadable or inferior code because it’s the path of least resistance. Not everyone will spend a day making an enum generator like I did; and it didn’t even occur to me 2 years ago to use a mixin for enums in the case of BindBC-SDL because there was this dogma.

>

BTW, your example looks fine as it is!

You said that it hurts your head to read code like that. But even if it’s ‘fine’, it would compile faster & take fewer lines if we could put conditional compilation in comma-separated lists, particularly enums and (associative) array literals. I would only need to write one array literal instead of a CTFE lambda with a series of ifs. Notice also that I did not nest those ifs, which is slightly worse for performance, but I had to preserve readability. With a single array literal, I would not have to make these compromises.

August 01
On Wednesday, 31 July 2024 at 06:11:15 UTC, Walter Bright wrote:
> This comes up from time to time.
>
> ```
> enum FOO {
>    A = 5,
>    B = 6,
> version (x86_64) {
>    C = 7,
> } else version (AArch64) {
>    C = 17,
> } else {
>    static assert(0);
> }
>    version E = 9,
> }
> ```
>
> I've seen this forever in C. It just makes my brain bleed. Here's the D way:
>
> ```
> version (x86_64)
> {
>     enum FOO
>     {
>        A = 5,
>        B = 6,
>        C = 7,
>     }
> }
> else version (AArch64)
> {
>    enum FOO
>    {
>        A = 5,
>        B = 6,
>        C = 17,
>    }
> }
> else
>     static assert(0);
> ```
>

The clean way is using "mixin" & "import"

foo_windows.enum  file
enum FOO
{
  A = 5,
  B = 6,
  C = 7,
}

foo_aarch64.enum  file
enum FOO
{
  A = 5,
  B = 6,
  C = 17,
}

main.d  file
module m;

version(Windows)
    mixin(import("foo_windows.enum"));
else version(AArch64)
    mixin(import("foo_aarch64.enum"));
else
    static assert(0);

version(Windows)
    static assert(FOO.C == 7);
else version(AArch64)
    static assert(FOO.C == 17);

void main()
{
}

build with  dmd.exe -J="directory of those enum files..." main.d