D - more or less power than C++?

Brad Roberts braddr at puremagic.com
Sun Mar 5 01:14:06 PST 2006


On Sat, 4 Mar 2006, Walter Bright wrote:

> "Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message 
> news:dudept$19qp$1 at digitaldaemon.com...
> > And in D, f(x) can be visually ambiguous as well - is the parameter in, 
> > out, or inout?
> 
> At least you know it's a function call, rather than a declaration of x of 
> type f! 

I've been trying to figure out when to say something on this topic since I 
fully understand just how difficult a topic const/immutability is and I 
know it's been thrashed around for years now.  That said, I think it's a 
seriously important feature for the safety and maintainability of code.

I view constness as one major aspect of contracts.  A function specifying 
that 'I will not alter the data you send me, and by implication neither 
will anything below me' give a major boost to the maintainability of a 
system.  A human writing that in a comment is totally insufficient.  The 
author could be wrong about a called function or a future change could 
invalidate the claim.  The language (and by implication the compiler) must 
support this guarantee.  As an asside, having such guarantees also gives 
the optimizer a boost in that it now has much more freedom to restructure 
code by knowing more.

I fully realize that C++'s const are incomplete.  I also don't personally 
have a full understanding of how to actually implement such protections.  
For now, let's not get caught up with the implementation specifics but 
rather defined semantics.

I want to be clear though, I'm not talking about const-ness of an 
instance, but of the barrier between callee and caller.

Make sense?

Later,
Brad



More information about the Digitalmars-d mailing list