const(FAQ)

Jason House jason.james.house at gmail.com
Tue Apr 1 07:27:03 PDT 2008


Kevin Bealer Wrote: 
> Regarding the D approach then:
> 
> I think it is a question of cooperation and goals.  If you have a method in D that only
> operates on in-class data then it is pure.  (It can also operates on other classes but
> only if it only calls methods following the same "pure" rules, and they do the same,
> recursively.)  Many methods like .size() can easily be pure since they operate entirely
> within the object, so in practice this is quite feasible.
> 
> The D const system does not prove purity, but it helps a lot when writing code and
> making it pure.  The C++ const gives every class the tools and therefore implicitly 
> the permission to use mutable fields in const objects, which means that if people
> do things in a non-pure way its not even wrong.  In fact my (limited) understanding
> is that the C++ standard actually supports the idea of casting away const just to
> side step the const regime.

This is actually a good way to think about this stuff.  My current problem with the const regime is that global variables can be used to break the transitive const nature.  For me to truly feel comfortable with the idea, I need to see equal handling of member variables and global variables.  I really hate to see designs that encourage use of global variables!

Personally, I like the idea of specifying some kind of exception to the transitive const such as an output-only object.



More information about the Digitalmars-d mailing list