Const sucks
Russell Lewis
webmaster at villagersonline.com
Mon Sep 10 13:08:53 PDT 2007
Walter Bright wrote:
> (snip)
> o static const/invariant means the initializer is evaluated at compile
> time. non-static const/invariant means it is evaluated at run time.
I'd like to suggest that we use some keyword other than "static." Yeah,
I know that "static" can imply "static analysis" (compile time), but the
static modifier on a variable has a well-known meaning from C: it's not
exported. I think that that was a poor design choice in C, but now
we're stuck with millions of programmers who expect it.
I think that this would just cause confusion, and perhaps we need a new
keyword to express this new concept. While I understand that we don't
want to multiply keywords, multiplying concepts, and then overloading
them all into a single keyword, is, IMHO, even worse.
> o no initializer means it is assigned in the corresponding constructor.
>
> o const/invariant declarations will always allocate memory (so their
> addresses can be taken)
>
> o So, we still need a method to declare a constant that will not
> consume memory. We'll co-opt the future macro syntax for that:
>
> macro x = 3;
> macro s = "hello";
How about "inline"? That seems to clearly express what we want to
express (there is a clear parallel between inline functions and inline
constants).
I don't recall: is inline a keyword in D or not?
More information about the Digitalmars-d
mailing list