Getting the const-correctness of Object sorted once and for all
Walter Bright
newshound2 at digitalmars.com
Tue May 15 00:33:05 PDT 2012
On 5/14/2012 1:03 AM, Mehrdad wrote:
> On Monday, 14 May 2012 at 06:27:15 UTC, Walter Bright wrote:
>> #3 Improves self-documentation of code - it's more understandable and less
>> susceptible to breakage during maintenance.
>
> #3 is also valid for C++, so I wasn't exactly considering that.
No, it isn't.
1. C++ legally allows changing const values.
2. const only applies to the top level (i.e. head const). So if you have
anything more than a simple value type, it literally means *nothing*.
>
>> #4 Improves encapsulation
>
> o.O How does it improve encapsulation?
By guaranteeing that the method call is a reader, not a mutator.
D is a very deliberate step away from correctness by convention and towards
correctness with mechanical verification.
More information about the Digitalmars-d
mailing list