Twiddling my thumbs while I wait for the compiler to finish
I seem to be in some sort of state where if I ever touch this one file I trigger a complete rebuild of all our source.
I'm in the middle of taking some of our core types and doing the dual job of making them
- Immutable objects
- Good const citizens
I'm trying ot architect this work for maximum clarity and simplicity. I'm also trying to get it in a form that would be easy to port to C# and would end up with code that I wouldn't want to change once ported over.
It's easy to create immutable objects in C#. The readonly modifier does a great job of that for me. However, the lack of an ability to declare something const is extremely frustrating. About the only thing I can do to ensure the same behavior is to provide a deep clone on every single one of my types and then send a clone over to any callers. This is extremely frustrating and error prone.
I understand that in C++ it's purely an affectation and anyone can get around the constness of an object trivially. However, I would love it if our runtime added support to runtime checking of 'const.' The only reasons I can think of for us not to do this are:
- Perf overhead of checking that it's ok to call a specific method on a const instance of a type
- Needing to go through the BCL to update all methods with teh correct const information.
Both would cost a lot in terms of time necessary to do it. However, I see the benefit as being so high. Unfortunately, the longer we go without adding this, the more unlikely it will ever be that we'll ever be able to add it.
Comments
Anonymous
May 31, 2004
Cyrus,
there has been a discussion with raymond chen just some time ago regarding this... ( http://blogs.msdn.com/oldnewthing/archive/2004/04/27/121049.aspx )
eric ( http://blogs.msdn.com/ericgu/archive/2004/04/22/118238.aspx ) and stan ( http://blogs.msdn.com/slippman/archive/2004/01/22/61712.aspx ) also posted stuff regarding this.
but.... i still liked to see 'const' in the runtime... :)
WM_MY0.02$
thomas woelferAnonymous
May 31, 2004
const is also more familiar. readonly is... weird to me. const is familiar, I know it, I know what it does, what the semantics of it are, how to use it, when, why. readonly? Then you start the inevitable stream of questions beginning with "what's the difference?"Anonymous
May 31, 2004
YES!!! I've never gotten an acceptable answer as to why there is no const... but I'm glad there are other people around who feel the same way I do.
I talked about this a while ago on my blog here...
http://schweitn.blogspot.com/2004/02/guarantee-this-wont-change-im-sorry-i.html
It is the one major complaint I have left about C# & .NETAnonymous
June 02, 2004
One problem is that the CLR has to support multiple languages. If you add a CLR const feature, and go mark the BCL classes and methods with the modifier, you'll be left in a situation where only languages that support the concept of const will work with the CLS. So in addition to modifying C#, you'd have to modify VB.Net, and all the other languages that compile to the CLS specificationAnonymous
May 31, 2009
PingBack from http://outdoorceilingfansite.info/story.php?id=2297Anonymous
May 31, 2009
PingBack from http://outdoorceilingfansite.info/story.php?id=19933