enums and version/static if/"inheritance"
IchorDev
zxinsworld at gmail.com
Wed Jul 31 09:23:37 UTC 2024
On Wednesday, 31 July 2024 at 06:11:15 UTC, Walter Bright wrote:
> 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);
> ```
>
> Ah, doesn't that look nicer? It's nicer because the code forms
> a regular pattern. A regular pattern is easier to understand.
Could you please rewrite the D version of [this
enum](https://github.com/BindBC/bindbc-glib/blob/b5b8131226f176bcd1ab68af0402c2ce984c2f64/source/glib/unicode.d#L130) to use this pattern for me? When you’re done, post it as a reply so we can see how much nicer it looks. ;)
There’s only 14 different possible versions, and each one is at
least 67 lines long (unless you inline the enum, in which case
you can kiss readability goodbye), so it should only be a bit
over 1000 lines of code when you’re finished there. Compared with
the 238 lines of my original version—which could be further
shortened if it was using conditional compilation instead of
meta-programming—and it might become apparent that your
suggestion forsakes the DRY principle.
More information about the Digitalmars-d
mailing list