Thread overview
What happened to const?
Oct 07, 2003
Lio
Oct 07, 2003
Philippe Mori
Oct 07, 2003
Walter
October 07, 2003
I'm actually very fond of 'const' in C++. You can give (a pointer to) an object to anybody for reading only. I've looked through the docs but can't seem to find anything about 'const' in D. Did I miss it? Or was it removed, if so, why?

L.


October 07, 2003
> I'm actually very fond of 'const' in C++. You can give (a pointer to) an
object
> to anybody for reading only. I've looked through the docs but can't seem
to find
> anything about 'const' in D. Did I miss it? Or was it removed, if so, why?
>
> L.
>
>

Currently, const is used only as a stirage modifier and not a type modifier.

IMHO, D give with one hand and take away with the other one. We have better
"design by contract" but we miss full constness support... which also help
to
prevent errors.

I think we should support constness at least on final objects (say a Point`
a Rect or String class for example). In fact, I would say that we should
support
it on any object (except possibly for interface --- since they might
interact
with COM --- and in that case, QueryInterface would not be const so
having interface won't break the constness of an object)

Philippe


October 07, 2003
"Lio" <Lio_member@pathlink.com> wrote in message news:blu0np$2m7n$1@digitaldaemon.com...
> I'm actually very fond of 'const' in C++. You can give (a pointer to) an
object
> to anybody for reading only. I've looked through the docs but can't seem
to find
> anything about 'const' in D. Did I miss it? Or was it removed, if so, why?

'const' exists in D as a storage class, not a type modifier (as in C++). There have been numerous long threads here discussing the pros and cons of it.