const question/suggestion
Sean Kelly
sean at f4.ca
Mon Jun 18 08:43:52 PDT 2007
Craig Black wrote:
> OK, I think I'm starting to grasp the subtle differences between const,
> final, and invariant. It seems to me that to have three keywords is
> unnecessary. Perhaps const and final could be merged into one?
Funny, I was going to say that about 'final' and 'invariant'. So far as
I can tell, the only difference between them from a user perspective is
that 'invariant' is transitive while 'final' is not. The ROMability of
'invariant' is a compiler issue and is meaningless to the user.
> From my understanding, the only difference between const and final is that
> local final fields can be initialized in a constructor, right? Couldn't
> that just be the default behavior of a local const field? Then we could get
> rid of final and have only two keywords. Or am I missing something? IMO,
> two keywords is way less confusing than three.
That was my thought as well.
> Another question. Since invariant data should always be invariant, does it
> make sense to be able to cast non-invariant data to invariant? The compiler
> will think that it is invariant when it isn't.
This is probably just a matter of not making special cases for the
compiler. Casts are always allowed, even those that don't make sense.
Sean
More information about the Digitalmars-d-announce
mailing list