More Intuitive Syntax for Manifest (enum) Constants

Peter C peterc at gmail.com
Sat Nov 22 09:32:29 UTC 2025


On Saturday, 22 November 2025 at 08:59:59 UTC, Walter Bright 
wrote:
>
> ...
> As for `final`, it seems the perfect keyword for it. What 
> semantic integrity is it losing? Currently, applying `final` to 
> a variable declaration gives an error.
>

Actually, outside of OO like programming, 'final' does seem like 
the perfect fit - because you typically won't ever see that word 
used (expect for 'final switch')

It's when it appears in the context of other finals, that it 
creates mental dissonance:

final class Base
{
     final void printInfo() {}
     final Base finalFieldRef;
}

Of course, putting final on the methods here is a bit redundant, 
since the class is final anyway, but this pattern is still used.

So, yes, final is an 'intuitive' syntax choice for SAA - but only 
when used outside of code above.

Most likely, for immediate clarity (for myself and others), I'd 
have to include a comment:

final class Base
{
     final void printInfo() {}
     final Base finalFieldRef; // enforcing a single assignment 
here
}

This is a bit off topic of course, but I can easily twist this 
same argument around for why there should have been a more 
intuitive syntax for mainfest constants, instead of overloading 
enum to also mean a non-type definition - i.e. the tool for 
defining a type should not be the tool for defining a value.



More information about the Digitalmars-d mailing list