any news on const/invariant?
Janice Caron
caron800 at googlemail.com
Wed Nov 28 02:46:36 PST 2007
On Nov 28, 2007 10:10 AM, Walter Bright <newshound1 at digitalmars.com> wrote:
> I think it would be pretty hard to give up:
>
> const x = 3;
Why? It would just turn into something else, like
const(int) x = 3;
static x = 3;
macro x = 3;
...or something. I mean, you get to invent the syntax.
> Also, C++ has const as both a storage class and a type constructor, and
> yes, they have subtly different meanings. This doesn't seem to cause any
> major problems.
That's because C++ behaves as expected. If I declare
const int * f();
then I get a function which returns a pointer to const int, /not/ a
const member function which returns a pointer to mutable int. I other
words, in C++, the const adheres to the return type, not the
function's "this" pointer. The D behaviour is drastically different
and vastly unintuitive.
I don't know whether this is syntactically considered to be a storage
class or a type constructor in C++, but really, it's irrelevant to me.
What matters is the principle of least surprise. It should do what we
expect it to do, and not something else.
More information about the Digitalmars-d
mailing list