Re: Variables in for loop (style issue)
Sean Kelly wrote:
Andrei Alexandrescu (See Website For Email) wrote:
Now here's my confusion. As this discussion makes progress, I assume
we're in scenario 2. After all, you created a language that overtly
competes with C++, and as such any and all of your comments about C++
invite the "let's see how D did" investigation. But you comment as if
you were comfortably laying on the couch in scenario 1. But there's no
couch - you're sweating in the court together with all of us. As such, I
find D's author's comments about C++'s const being imperfect... pot
*cough* kettle *cough* black! :o)
Forgive me for interrupting, but I have a different impression of the
situation. To extend the basketball analogy, I feel this is more like
this is a team reviewing a tape of an important game. Someone might
notice that a particular play or strategy didn't work so well against
the opposing team, but have no immediate ideas on how to improve
things. Instead he points the problem out to his teammates, hoping
that an ensuing dialogue will produce some useful ideas on how to
improve things. In this case, the criticism is made for a contructive
purpose rather than simply to give a friend a hard time as per your
Scenario 2 above.
But we've repeatedly agreed what the problems of const in C++ are, and
as soon as we try to let the discussion take its natural progression,
there's yet another example on how const_cast messes things! It's been
in like half a dozen posts already - the equivalent of taking over the
remote and backing the tape over and over again to the same ten seconds
of the game!
Defining a useful form of const behavior seems a tremendously difficult
problem--if it weren't, these issues would have long since been
settled.
There's been good work done on that, see
http://www.cs.umd.edu/~jfoster/papers/pldi99.pdf and the CQUAL program
that allows programmers to define their own type qualifiers. The paper
discusses exactly the const issue.
The solution they describe lies on defining polymorphism on qualified
types. They define a qualifier q to be a "positive qualifier" if q T
describes a superset of T, that is T is a subclass of q T, and a
"negative qualifier" if q T describes a subset of T, that is q T is a
subclass of T.
So const (as a qualifier, not a storage class) would be a _positive_
qualifier because any T is also a const T. The converse is not true, so
the set of const T includes the set of T. A qualifier such as nonzero
(for a pointer or integer) is negative because the set of nonzero
objects is included in the set of all objects. Because of the way
polymorphism interacts with value types in C++, however, it's not
obvious to me how this work could be applied to solve the
iterator/const_iterator dilemma.
Andrei
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]