From: Dave Harris on
matthew.bond(a)l-3com.com (mattb) wrote (abridged):
> I have recently heard the above, along with a further statement
> along the lines of -
>
> 'const is there to stop amateur slip ups. Professionals should know
> what a function is expecting and should use that.'
>
> Could I please have some comments on these statements.

The title comment is a reasonable point of view. Although const has
benefits, it also adds a lot of complexity to the language. It's not just
the "const" keyword itself, you also have const_cast<> and mutable, and
issues like whether *p should be const if p is const (sometimes it should,
sometimes it shouldn't). The extra typing includes the need to write a
const_iterator as well as a non-const one, and in general the common need
to double-up interfaces in order to preserve or propagate const. It's a
lot of work.

In C++ you pretty much have to use it. There are things worth fighting
the language over, but this isn't one of them. However, it's not at all
clear that const would be worth adding to other languages, and indeed I
don't think any other languages have it (I'm excluding things like Java
which have only a half-baked version).

This is a specific example of the general debate about compile-time type
checking. C++ checks const at compile-time, other languages don't. Some
languages check exception declarations at compile-time, C++ doesn't. Some
languages (eg Smalltalk) do all their type-checking at run-time, and that
can work well.

If who-ever made the comment is a Smalltalk programmer, you are probably
better off not arguing with them. If they prefer languages with at least
some compile-time type-checking, then you could point out that the same
sort of comments apply to that equally well.

(Which, for me, means the question cannot be dealt with in such
generalities, but needs specific details and measurements.)

-- Dave Harris, Nottingham, UK.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]