Unofficial wish list status.(Jul 2008)

Brad Roberts braddr at puremagic.com
Tue Jul 22 17:35:29 PDT 2008


On Wed, 23 Jul 2008, Bill Baxter wrote:

> On Wed, Jul 23, 2008 at 8:27 AM, Brad Roberts <braddr at puremagic.com> wrote:
> > On Tue, 22 Jul 2008, Walter Bright wrote:
> >
> >> superdan wrote:
> >> > i couldn't design an const/invariant system to save my life
> >> > from the same cannibals who ate bjarne. the space looked like a zero
> >> > sum shit to me. so when i saw what walter came up with, i was rightly
> >> > surprised. same goes about some shit in phobos2. it's not just yet
> >> > another library. it's a fucking cool one because it's better in a new
> >> > and surprising way.
> >>
> >> I cannot claim credit for it. The const/invariant design was the result of
> >> literally hundreds of hours of work (and maybe a hundred gallons of coffee) by
> >> Andrei, Bartosz, Brad, David, Eric and myself, as well as feedback from the
> >> community on why our earlier efforts got it wrong.
> >>
> >> The transitivity requirement originated with Andrei, if I recall correctly.
> >
> > Quite possibly it was both of us, but I know I brought it up in
> > discussions with you prior to joining the group discussions.  It's my
> > primary angst with c++ const.
> 
> By that do you mean something that's caused you actual trouble in C++
> projects?  Or just something that keeps you awake at night worrying
> about the trouble it could cause?  My feeling is that C++ const does a
> decent job in practice of preventing programmers from doing stupid
> things.  On the other hand, if you're trying to go out of your way to
> be stupid... that's another matter.  But for the most part, while it
> may be easy to circumvent const, it's not so easy to circumvent it
> accidentally.  Useless for making compiler optimizations, yes, but
> fine for documenting the intent of code.
> 
> --bb

I mean has caused real trouble.  I don't tend to make a lot of arguments 
based on theory.  Primarily they're made from hard earned practice.  C++ 
does not make it possible (possibly too strong a statement, substitute 
easy if you can think of a loophole) to take an existing object that is 
poorly implemented for const-correctness and make that a contained object 
in another class that wants to behave const correctly.  It's way way too 
easy to make a mistake and have constness end without seeing it.  
Transitivity is what most more junior developers _expect_ from c++'s const 
system and it's not what they get.

Secondarily, I _strongly_ value the benefit of const at the interface 
layer.  That's even more important to me than the other half of constness.  
I love D's use of contracts and const (as well as in, out, and inout) 
playes a big role there.

Yes, it's a matter of mismatched exepctations, and it is possible to use 
const correctly in c++, but to do so requires (like so much of c++) 
considerable care.

To clarify, I've spent much of my 20 year career as both a maintenance 
programmer and as a new code developer (roughly 50/50).  I tend to 
volunteer for the cleanup projects because no one else is willing to do 
it.  A lot of that time has been in multi-million line code bases that 
have been evolved extremely rapidly and haphazardly.  Yes it's the fault 
of the code as much as the language, but a language that gave better 
guarantees would have prevented problems and made ongoing maintenance 
easier by having a trustable const system.

Make sense?

Later,
Brad




More information about the Digitalmars-d mailing list