const?? When and why? This is ugly!

Derek Parnell derek at psych.ward
Sun Mar 8 05:28:33 PDT 2009


On Sun, 08 Mar 2009 01:19:15 -0800, Walter Bright wrote:

> Derek Parnell wrote:
>> Walter, you have side-stepped the problem in question by talking about a
>> totally different problem.
> 
> It's the same issue. When you use a cast, you are subverting the type 
> system. That means you have to be sure you are doing it right. The 
> compiler cannot help you.

I disagree. There are two issues being discussed. One by Burton and another
by yourself. Burton is showing how that data declared as immutable can be
modified. You are talking about the dangers of using casts. NOT THE SAME
ISSUE. 
 
>> Burtons code says "b is invariant", but the program allows it to be
>> changed. Your code does NOT say that any of those variables is invariant.
>> The problem is NOT with the cast (although that is a totally different
>> issue). The problem is that the code says "invariant" but the data gets
>> changed anyhow. The method of changing the data is not the issue. The issue
>> is adxthat is gets changed at all.
> 
> When you cast something to immutable, you can no longer change it. It's 
> a one-way ticket.

Walter, did you actually see and run that code? I did cast something to
immutable but it got changed anyway. Is this a compiler bug or what? You
say that if one casts something to immutable that therefore one can no
longer change it - but it DID get changed.

I know that a better way to code this example would have been to use the
.idup functionality, but that is not the point. I relied on the compiler
ensuring that everything declared as immutable would not be modified. The
compiler failed.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list