More Intuitive Syntax for Manifest (enum) Constants

user1234 user1234 at 12.de
Tue Nov 25 16:29:31 UTC 2025


On Tuesday, 25 November 2025 at 15:26:06 UTC, Zealot wrote:
> On Tuesday, 25 November 2025 at 12:20:13 UTC, Dejan Lekic wrote:
>> On Tuesday, 25 November 2025 at 10:54:06 UTC, Jonathan M Davis 
>> wrote:
>>> [...]
>>
>> I thought I would skip this discussion, but I could not resist 
>> to write my suggestion here. We discussed `final int E = 42`, 
>> `manifest E = 42`, and few other options on but I do not 
>> remember that we discussed this:
>>
>> ```d
>> named E = 42;
>> named APP_VERSION = "1.0.0";
>> ```
>>
>> This comes from the fact that manifest constants are "named", 
>> "literal", "symbolic" constants. A good alternative in my 
>> opinion would be `symbol E = 42;`
>
> alias? :D

Styx uses `alias` for the equivalent of D manifest constants. 
That works because the language also has [expression 
aliases](https://styx-lang.gitlab.io/styx/expression_alias.html)

```
// polymorphic version
alias e0 => 0;
// monomorphic version (evaluated once in situe)
const alias e0 => 0;
```

anyway, I dont think this is a good idea for D.


More information about the Digitalmars-d mailing list