Suggestion: object const'ness

Derek Parnell derek at psych.ward
Sun May 21 04:22:01 PDT 2006


On Sun, 21 May 2006 13:36:33 +1000, Hasan Aljudy <hasan.aljudy at gmail.com>  
wrote:


> huh? if you pass an object reference as in you shouldn't be able to  
> manipulate the object?!!

Why not? What is the axiom that makes this so?

> In what sense is that a "true" in?

There *is* no "true" 'in'. Each language has its own definition of 'in'.  
In D the 'in' just means you can't modify what ever has been passed to the  
function. And in the case of objects and arrays, it's the reference that  
is passed - thus you can't change the reference. There is nowhere that  
talks about protecting that which is referenced - only the reference  
itself.

If we learn to live with this, we can design our code around such a  
concept.

Personally, I'd like the compiler to be a bit more helpful so I could tell  
it when I'm not intending something to be changed and it could tell me  
when it happens to detect that I'm accidently trying to change it.

-- 
Derek Parnell
Melbourne, Australia



More information about the Digitalmars-d mailing list