More Intuitive Syntax for Manifest (enum) Constants

Kapendev alexandroskapretsos at gmail.com
Sun Nov 23 22:16:41 UTC 2025


On Sunday, 23 November 2025 at 21:19:05 UTC, monkyyy wrote:
> On Saturday, 22 November 2025 at 09:39:03 UTC, Kapendev wrote:
>> I think this isn't very clear and can confuse people. For 
>> better readability,
>> you should actually use something more in line with modern 
>> language design, like:
>>
>> ```c#
>> public static class FOO
>> {
>>     public const int Value = 42;
>> }
>> ```
>>
>> This gives the constant a proper semantic boundary and lets 
>> you extend it later
> thats still bad style
> ```d#
> public static class FOO
> {
>     private const int Value = 42;
>     ///gets the value
>     public const ref int getValue() @property
>     {
>         assert(&Value is not null);
>         return Value;
>     }
> }
> ```

Overall, better, but you forgot to put `@trusted` there. Return 
`ref` is unsafe, but your code looks correct, so it's okay. It 
would be nicer if you wrapped that getter in a safer abstraction.


More information about the Digitalmars-d mailing list