Vision for the D language - stabilizing complexity?

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 15 16:00:45 PDT 2016


On 7/15/2016 1:48 PM, Shachar Shemesh wrote:
> On 15/07/16 22:50, Walter Bright wrote:
>
>> You can do logical const in D just like in C++, and get those
>> performance gains. You just can't call it "const". But you can call it
>> /*logical_const*/ and get the same result.
>
> No, you can't. The fact that the compiler enforces the no const to mutable
> transition (unless you use a cast)

The compiler does next to nothing - the maintainer can stick in 'mutable' 
members, and there's no reliable way to detect that. The maintainer can stick in 
const removing casts, and there's no reliable way to detect that, either.

If it's not mechanically checkable, it is not reliable, and is what I call 
"faith-based programming."


> is one of the main appeals of using const in
> any language. If you call something "logical const", but the compiler does not
> help you to catch bugs, then I don't see the point.

I agree, and the C++ compiler is unable to verify "logical const". It's entirely 
based on faith.


> In effect, if logical const is what you want, C++ gives you a tool while D
> leaves you to your own devices. As a result, a lot of places you'd define as
> const in C++ are defined mutable in D, losing language expressiveness.

You and I certainly have polar opposite opinions on that. C++ does not have a 
notion of "logical const" (it is not in the C++ Standard). It's an uncheckable 
convention, might as well just use /*logical const*/.

D, on the other hand, has verifiable const and verifiable purity.



More information about the Digitalmars-d mailing list