Stop using the enum as a manifest constant.
Mathias LANG
geod24 at gmail.com
Sun Jun 6 10:47:54 UTC 2021
On Sunday, 6 June 2021 at 10:40:13 UTC, Jack Applegame wrote:
>
> That's not enough. Let's deprecate any use of enum as a
> manifest constant.
I wouldn't go that far. `enum` are like `#define`, and there
*are* cases where you want them. E.g. when using them as define
arguments:
```D
void foo (char[] fmt = DEFAULT_VALUE) { /* ... */ }
```
If `DEFAULT_VALUE` is `immutable`, this will never compile, but
with `enum`, it might. You'd think that's an odd use case, but we
actually had a few instances at Sociomantic which triggered when
we tried to change some internal tools to use `static immutable`
instead of `enum`.
I agree with the wider point though. People expect manifest
constant to have an address and to be eagerly evaluated. That's a
[`static`] `immutable`. `enum` is just a copy-pasted literal.
More information about the Digitalmars-d
mailing list