D2.0 const this methods
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Wed Jun 20 14:19:21 PDT 2007
Georg Wrede wrote:
> Walter Bright wrote:
>> Bill Baxter wrote:
>>
>>> From the const page docs
>>> class Foo {
>>> invariant int foo() {
>>> ...
>>> }
>>> }
>>>
>>> makes 'this' and the return value invariant.
>>
>> No. invariant as a storage class on a member function only makes the
>> member function invariant, it does not affect the return type.
>
> Am I the only one who thinks it is hard to remember that a word (here
> 'invariant') somewhere applies on this and otherwise on that?
>
> Should we have the keywords applying to the function be written after
> the function signature, and those applying to the return type before it?
>
> (I'd really hate D to become another language where one has to remember
> a truckload of stuff by heart.)
As much as I hate to admit this... I would personally prefer the
const|invariant occuring after the signature as well. It shames me,
truly it does! But it /is/ less ambiguous than this, where it becomes
difficult to quickly discern with the eyes whether the method is
const|invariant, or whether the return type is. (Yes, technically,
there would be parentheses to disambiguate if it were the type... but
then again, I'd bet forgetting those paren's would lead to interesting
new bugs, and that's precisely the sort of thing these are supposed to
help prevent!)
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list