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.