Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I suspect there are some practical reasons, and some theoretical reasons:</p> <ul> <li>Should the constness apply to the <em>object</em> or the <em>reference</em>? If it's in the reference, should this be compile-time only, or as a bit within the reference itself? Can something else which has a non-const reference to the same object fiddle with it under the hood?</li> <li>Would you want to be able to cast it away as you can in C++? That doesn't sound very much like something you'd want on a managed platform... but what about all those times where it makes sense in C++?</li> <li>Syntax gets tricky (IMO) when you have more than one type involved in a declaration - think arrays, generics etc. It can become hard to work out exactly which bit is const.</li> <li>If you can't cast it away, <em>everyone has to get it right</em>. In other words, both the .NET framework types and any other 3rd party libraries you use all have to do the right thing, or you're left with nasty situations where your code can't do the right thing because of a subtle problem with constness.</li> </ul> <p>There's a big one in terms of why it can't be supported <em>now</em> though:</p> <ul> <li>Backwards compatibility: there's no way all libraries would be correctly migrated to it, making it pretty much useless :(</li> </ul> <p>I agree it would be useful to have some sort of constness indicator, but I can't see it happening, I'm afraid.</p> <p>EDIT: There's been an argument about this raging in the Java community for ages. There's rather a lot of commentary on the <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4211070" rel="noreferrer">relevant bug</a> which you may find interesting.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload