From: Daniel T. on
mattb <matthew.bond(a)l-3com.com> wrote:

> 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.

'const' serves many uses. Yes it's a little extra typing, but it reduces
the maintenance burden, yes it helps stop amateur slip ups, but it also
helps stop professional slip ups. (Hopefully, nobody here is going to
claim that professionals don't ever slip up.)

'const' is a useful optimization, allowing classes to expose state
efficiently without breaking encapsulation.

'const' is a useful way to inform others about fundamental design
decisions in the code.

'const' is useful.

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

From: Daniel T. on
Tonni Tielens <tonnitielens(a)gmail.com> wrote:

> Interesting topic. I was thinking about this a while ago. Why does
> Java for instance not have a const mechanism. E.g. in Java you can say
> a reference itself cannot change, but you cannot prevent someone from
> modifying an objects state if he has a reference to it. Why is const
> correctness never introduced in a language like Java and more
> important: why do people not seem to miss it?
>
> We are working on two applications in my team. One is a const correct C
> ++ application and one is a Java application. Although I understand
> the idea behind const and I urge others to make const correct code, we
> have never had a situation in the Java application where we thought:
> "Oh, if we only had const now, this wouldn't have happened." Of course
> this also goes for the construction worker who has never had a brick
> falling on his head.

And if you are disciplined you have no need for access restrictions
(protected and private,) because you will naturally write your code
correctly.

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