logical const is a subset of transitive const

Janice Caron caron800 at googlemail.com
Fri Sep 14 12:20:07 PDT 2007


On 9/14/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> I disagree.  Declaring it const means that calling that function will not
> change any members of the date object.
>
> Declaring it pure means that it will always return the same value, which
> means it would be safe for multiple threads to access without locking (I am
> very new to this concept, but I got all my knowledge from wikipedia:
> http://en.wikipedia.org/wiki/Functional_programming)

I stand corrected. Yes, you are right. A function can be declared
const and still read and write global variables, and hence not be
threadsafe.

In that case, I don't understand why Walter wants to outlaw intransitive const!


> I think this is incorrect.  It would not randomly crash, it would not
> compile.  They would not be able to call the now lconst method through a
> const reference.

I stand corrected again. Well argued.


> I think your argument stems from the incorrect assumption that const ==
> thread safe, which I think I've argued against above.

It did. Because that was the only only argument that Walter managed to
get through into my brain when he was justifying that there would be
no way to specify e.g. pointer to const pointer to int.


> I think invariant, const, and lconst all have clear meanings, are clearly
> separated.  Since lconst/invariant would be new to D, a new programmer would
> need to know about them to use them, so they would need to read
> documentation and descriptions of the keywords to understand them.  I agree
> that in learning a new language, it would be a slightly larger learning
> curve, but with simple examples (please note, examples are key, I love
> examples) and a concise explanation would make learning const take at most 1
> hour.  At least for me :)

Of course, there would be /four/ keywords, if you count "pure". And
five if you count "mutable".
:-)



More information about the Digitalmars-d mailing list