Fully transitive const is not necessary

Janice Caron caron800 at googlemail.com
Thu Apr 3 10:55:49 PDT 2008


On 03/04/2008, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
>  For example, if I have a function that looks like this:
>
>  int[] calculateSomeValues(const(Calculator) c);
>
>  written by some other developer who says "I won't be changing c, and c
>  defines that f is const, so I'll declare that c is const".

The difference between Calculator and CachingCalculator is a bit like
the difference between File and BufferedFile. We all /know/ that file
access is slow, and so buffering speeds things up. Ditto here. That
other developer should have written

    int[] calculateSomeValues(CachingCalculator c);

and if they were dumb enough to use an underpowered class, then don't
call their function.



>  and inevitably, they [other people] will have
>  incorrectly implemented it

One doesn't introduce new language features on the assumption that
other people will incorrectly implement other language features.

It's just education, that's all. When using D, you program "the D
way". And that means, you don't declare something const, if you know
that bits of it are going to change. That's how it works in D. Look at
it like this - D mandates good habits.



More information about the Digitalmars-d mailing list