From: Dan W. (danw_at_[hidden])
Date: 2004-01-05 14:34:48
Thornsten, I agree with you 99.325%.
As a former fellow Eiffel-er, command <-> query separation is my religion.
If you were to look at my C++ code:
A) A function that has ANY side-effect whatsoever, inside or outside its
class, unfailingly returns void.
B) A function that returns anything but void, not only is it unfailingly
declared const, but you can bet your life-savings on it, it is as pure
as pure gets --i.e.: "deep_const".
And constness propagation is my default, by discipline:
C) You'd never see me calling a non-const function through a chain of
pointers that starts with, or contains, a const pointer anywhere, unless
I do it through ignorance of the library class I'm using.
D) You'd never see a class-const function of mine taking non-const
pointers or references.
E) Very rarely you'd see me mixing value and reference members, and
treating the reference members in a shallow way, unless I have a reason
for it, in which case you'd see big blocks of comments.
So, if C++ were to adopt the meaning of const correctness you propose,
it would probably have little effect on my code. (Not so for a lot of
other existing code).
Now, as I mentioned to you earlier, 4 years ago there was a heated
polemic in an Eiffel forum about this exact same subject: What IS an
object? What does ownership mean? Should constness propagate?
And this I find interesting:
In Eiffel, the lack of constness propagation INDEED violates command -
query separation! Unlike a C++ const member function, a query function,
in Eiffel, is *expected* to have no side-effects, yet it CAN have
side-effects through chained references. In this sense, C++ is the
language that has the more self-consistent definition; and Eiffel the
language that's broken. And remember that Eiffel has "deep_copy()".
So, you'd think that Eiffel has some *seriously* compelling reasons to
adopt constness propagation, right? Does it? Nope.
I think that, as arbitrary as some of the features of C++ may seem, it
just happens to be sitting on a sweet spot of sorts... something I've
grudgingly come to accept... I'd love to have the compiler enforce some
of my most beloved programming disciplines; but I wouldn't be prepared
to pay just any price for it; --and I do want to be able to touch the
metal underneath, if you know what I mean; that's why I left Eiffel behind.
Just my $0.02
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk