More Intuitive Syntax for Manifest (enum) Constants
Peter C
peterc at gmail.com
Tue Nov 25 23:55:08 UTC 2025
On Tuesday, 25 November 2025 at 10:54:06 UTC, Jonathan M Davis
wrote:
>
> ...
> And honestly, if I were to create a new version of D with all
> of the various changes that I think would ideally be changed if
> we didn't care about backwards compatibility, I'd probably just
> leave manifest constants the way that they are. It simply isn't
> worth adding a keyword for this concept, and it has the benefit
> that both enum values and manifest constants which are
> designated via enum behave the same way. So, arguably, using a
> different keyword would just fix one perceieved inconsistency
> by adding a new name for what is practically speaking the same
> thing but in a slightly different form.
>
> - Jonathan M Davis
After exploring D's enum further, I tend to agree.
I like (and just discovered) that D's enum can be initialized by
a CTFE-compatible function (pure).
C# lacks this initialization flexibility, and is too rigid,
forcing you to switch from const to static readonly for
initialization via a function.
So at least D's use of enum provides a consistent entry point for
manifest constants - even in Rust you would have to switch from
const to const fn.
Walter said (in previous post here): "The `enum E = 24;` syntax
looked a bit odd at first, but seems perfectly natural to me
now.".
So really, I just had the same reaction.
But I'm getting more comfortable with it, as begin to understand
its role in D a little better (particulary in combination with
CTFE).
But to clear [yet again] I was never advocating for a change to D
- I was just expressing an opinion.
More information about the Digitalmars-d
mailing list