On Mon, 29 Nov 2010 18:04:31 -0500, Walter Bright <newshou...@digitalmars.com> wrote:

Steven Schveighoffer wrote:
On Mon, 29 Nov 2010 15:58:10 -0500, Walter Bright <newshou...@digitalmars.com> wrote:

Steven Schveighoffer wrote:
Having a logical const feature in D would not be a convention, it would be enforced, as much as const is enforced. I don't understand why issues with C++ const or C++'s mutable feature makes any correlations on how a D logical const system would fare. C++ const is not D const, not even close.


Because people coming from C++ ask "why not do it like C++'s?"
I don't get it. A way to make a field mutable in a transitively-const system is syntactically similar to C++, but it's not the same. Having a logical-const feature in D does not devolve D's const into C++'s const. If anything it's just a political problem.

Having mutable members destroys any guarantees that const provides. That's not political.

What guarantees?  Const provides no guarantees.

class C
{
   static C theCommonOne;
   int x;
   void foo() const {
      theCommonOne.x = 5; // theCommonOne could be this
   }
}

Only immutable provides guarantees. As I said earlier, the place where logical const would cause issues is immutable. Immutable data is currently implicitly shareable, and the compiler may take steps to optimize strongly-pure function calls, which require immutable parameters. Any logical const system would have to either work with those requirements or force them to be reevaluated.

And, I repeat, having a mutable type qualifier DOES NOT make logical const a language feature. This is why discussion and understanding of C++'s const system is so important - people impute characteristics into it that it simply does not have.

I've proven in the past that logical const is equivalent to full const. That is, I can emulate logical const without any casts in the current const regime. Making it more efficient and simpler is all we would be doing.

-Steve

Reply via email to