Why there are no 'physical' object variables (only references)?

Kristian kjkilpi at gmail.com
Tue Sep 12 07:49:44 PDT 2006


On Sun, 10 Sep 2006 23:48:22 +0300, Reiner Pope  
<reiner.pope at REMOVE.THIS.gmail.com> wrote:

> Kristian wrote:
>> On Sun, 10 Sep 2006 18:59:34 +0300, Sean Kelly <sean at f4.ca> wrote:
>>> Kristian wrote:
>>>> And, I hope that D will have a 'const' type specifier in the future.
[snip]
>>>
>>> Don't we all.  But wanting it and coming up with a solid proposal for  
>>> how it should work are entirely different issues, unfortunately.
>>  Well, what's wrong with the way C++ does it?
[snip]
> Do some searching for 'const' and 'readonly' on this NG, and you should  
> get the idea:
>   - C++ const is ugly, so people don't use it enough;
>   - const_cast removes the safety guarantees of const, making  
> const-directed optimizations by the compiler impossible.
>   - overloading by const requires duplication of code.
>   - a trivial const system like C++ is too strict and may require  
> unnecessary clones to avoid a static const violation, thus necessitating  
> the need for const_cast
>   - reference immutability (C++'s 'readonly view') is only one form of  
> const, and can't guarantee other (important) immutability contracts
>   - after such a problems, the merits are not so clear, since the  
> usefulness can only really be attributed to two things:
>      1. Standardising documentation of variable usage.
>      2. Getting the compiler to help catch programmer errors.
>    and some people claim that they have never found any bugs by using  
> const.

There are a lot of talk about const/readonly/immutability in the archives.  
I have to admit that I don't have the strenght to read them, so I didn't  
(yet anyway).

C++ const is better than nothing. Hopefully there will be a solution that  
will suit everybody, more or less.

C++ const has flaws, of course. Sometimes it's necessary to do  
non-const-casting inside a const member function. But 'const' tells that a  
function is logically const even if it's not physically (statically?) one.  
So for a programmer it's only documentation tool that a compiler can use  
to check for (some) programming errors. And as such it has been working  
fine, for me at least.

(I don't know what this C++ const ugliness means. 'const' is a wrong word,  
so I don't use it? ;) )



More information about the Digitalmars-d mailing list