More Intuitive Syntax for Manifest (enum) Constants
Kapendev
alexandroskapretsos at gmail.com
Sat Nov 22 09:39:03 UTC 2025
On Saturday, 22 November 2025 at 08:10:44 UTC, Peter C wrote:
> In C#, we'd just do: [ public const int N = 42; ] - It provides
> immediate unambiguous clarity. I do not have to pause and make
> sense of this. It's a constant integer expression.
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
if needed. Raw enums like `enum FOO = 42;`, or even the more
primitive and worse looking
`public const int N = 42`, just don't scale in production code.
More information about the Digitalmars-d
mailing list