any news on const/invariant?

Steven Schveighoffer schveiguy at yahoo.com
Wed Nov 28 21:17:51 PST 2007


"Derek Parnell" wrote
> On Wed, 28 Nov 2007 23:02:06 -0500, Steven Schveighoffer wrote:
>
>> If that method returns a const type, then the method is declared as:
>>
>> const const(Type) f();
>
>> To someone who never used const before in another language, this isn't 
>> any
>> less or more intuitive than the way C++ does it.  It's like saying using
>> semicolons at the end of statements is intuitive.  It's just a different 
>> way
>> of expressing what you want to the compiler.
>
> Got it. When I see two adjacent "const" keywords I need to realize that 
> the
> first const refers to the second 'thing' and the second const refers to 
> the
> first 'thing'. Very intuitive.

It is if you think in stacks :)

>
> However ... what if we tried to make things unintuitive ... like having 
> the
> first const refer to the first thing and the second const refer to the
> second const ... Nah ... on second thoughts that would only confuse 
> people.
> Who'd ever work out that ...
>
> const(Type) const f();
>
> means that the 'Type' is const and the f() is also const?
>

Hey, I'm not saying it's the best way :)  I'm just saying it's no less or 
more intuitive than the C++ way:

const Type f() const

It's just different.  I'm all for the const(this) format suggested in 
another branch of this thread, as I think that's the most intuitive.

-Steve 





More information about the Digitalmars-d mailing list