www.digitalmars.com         C & C++   DMDScript  

D - What happened to const?

reply Lio <Lio_member pathlink.com> writes:
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.
Oct 07 2003
next sibling parent "Philippe Mori" <philippe_mori hotmail.com> writes:
 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
Oct 07 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
"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.
Oct 07 2003