Why there is no constant object references/values in .NET?

"readonly" modifier is almost useless, because it all the same allows to modify content of the object, and it may be applied to object members only, not to function arguments nor local variables.
I've already asked this question many people on discussion boards, but I got nothing except piles of buzzwords and pseudo-philosophical figments (usually something like "don't think in your dumb C++, think in our cool C#").
May very wise All explain me, is this lack intention of .NET architects, or they just missed this?
[536 byte] By [AndreiF] at [2007-11-18 17:38:11]
# 1 Re: Why there is no constant object references/values in .NET?
The decision was quite deliberate (although I do not personnaly agree). The basis is that the CLR (which is the layer at which the issue lices, not C# or VB) is designed to do all checking at runtime.

Since we are talking about the reference to an object (rather than an object itself) would need to be flagged as either a constant or writtable reference, this information would need to be carried with each and every reference throughout the program. The effect would be an increase in the size of a reference. The performance and management issues involved with checking EVERY operation on EVERY reference passed EVERYWHERE in the program would be quite expensive (in terms of memory and time).

Since "doing it perfectly" was not practical, it was decided to leave it out all together.

This is based on a number of conversions I have had (both on-line and in person) with a number of the developers of the CLR.

One "solution" to this issue (which we use) is to design out objects using two levels of interitance. The base level is an "immutable" object. It does not have any methods which can modify the object (i.e. in C++ they would all be "const" methods). From this class we derive a "mutable" version which adds all of the operations (and properties) that can modify the object.

While this is a little awkward at first, it does work, nd the use of code generators nearly elimintates the pain...
TheCPUWizard at 2007-11-10 3:47:06 >
# 2 Re: Why there is no constant object references/values in .NET?
Thank you very much!

It makes some sense, although I don't agree this argument too. It's rather far-fetched, I believe.
There isn't need to do constant checks at runtime, compile-time check would be good enough. And even if do checks at runtime, there isn't need to store const sign along with every object reference. There is a lot of ways for optimization.
But... we can't change anything :)

Your way seems to be good, but it won't prevent somebody from using type casts. For example, it's not a problem to get IDispose (if your "mutable" object implements it)
:(
AndreiF at 2007-11-10 3:48:15 >
# 3 Re: Why there is no constant object references/values in .NET?
"They"want everything to be runtime checked. It DOES improve reliability.

Regarding the cast. It is really no different than doing a const_cast in c++......
TheCPUWizard at 2007-11-10 3:49:13 >
# 4 Re: Why there is no constant object references/values in .NET?
Yes, of course :)

Indeed, it looks like const_cast in C++.
But C++ isn't safe, and CLR pretends to be so. I think, "not very reliable check" is much better, than "no check" :)
And concerning performance - "const" modifier is not a part of object data or object reference, it's rather the part of particular execution context.
AndreiF at 2007-11-10 3:50:09 >