Paavo Helde <
myfir...@osa.pri.ee> wrote:
> On 14.04.2016 23:25, Alf P. Steinbach wrote:
> > On 14.04.2016 18:46, Daniel wrote:
> >>
> >> <snip> My perspective is that const is a
> >> poorly thought out feature, ever by the standards of way back when.
> >> What I want to know when I call a method is whether it has side
> >> effects, and const is silent on that.
> >
> > As I recall Andrei was keen on providing a kind of transitive constness
> > in D. Not sure how that panned out. But it's worth noting that C++ does
> > not generally provide conceptual level features, but merely the low
> > level building blocks to create such features.
> That's right and how it should be. Const propagation is done for example
> by higher level classes like std::vector.
> Another issue is what exactly are those low level building blocks. Maybe
> 'const' as defined is not the most useful. It provides some
> half-enforced documentation though, so it is not entirely useless either.
I guess that a lot of this is a question of perception, dependent
on where one's coming from. For me as someone that has taken the
route assembler => C => C++ the way const is used in C++ is rather
easy to grasp and pretty impressive as well when it comes to help
avoiding common mistakes. For someone coming from the other direc-
tion, i.e. from a higher-level language point of view, it might
look much poorer.
On the other hand there's always the question of what one whishes
for. Would it be really always a good thing if one couldn't modify
what a pointer member variable of a const instance of a class points
to? If you e.g. have a pointer to a C-type file pointer in your
class, would it "feel right" to be unable to read from that file
or write to it (since it will, in some way, modify the internal
state of the pointed to FILE object)?
The way of good intentions would be to start distinguishing be-
tween pointers that also should "protect" what's pointed to and
those that don't: we'd need two types of pointers, one for poin-
ting to objects, that can not be changed when the pointer is a
member of a const qualified class instance, and one for pointers
as we have them now. Same, of course, for references. I'll need
some convincing that this would be a desirable feature to have...
Regards, Jens
--
\ Jens Thoms Toerring ___
j...@toerring.de
\__________________________
http://toerring.de