More Intuitive Syntax for Manifest (enum) Constants
Peter C
peterc at gmail.com
Sat Nov 22 02:30:12 UTC 2025
On Saturday, 22 November 2025 at 01:48:43 UTC, Walter Bright
wrote:
> ```d
> enum N = 42;
> ```
I've never ever liked this misuse of enum in D to basically
reflect a lightweight constant.
This is what happens when you repurpose a keyword to define a
named constant, instead of a strict collection of values, which
is what an enum is meant to be.
You seem intent on doing the same with 'final', it seems - i.e.
repurposing it to mean single assignment.
To me, it represents a lack of clarity in language design (i.e.
to benefit the compiler??, but at the cost of semantic integrity).
In C it's -> #define N = 42
In D, it should have been -> const int N = 42;
not -> enum N = 42; // to me, this misrepresents the purpose of
an enum
More information about the Digitalmars-d
mailing list