a more consistent const syntax
Rioshin an'Harthen
rharth75 at hotmail.com
Sun Aug 5 11:36:29 PDT 2007
"Chris Nicholson-Sauls" <ibisbasenji at gmail.com> kirjoitti viestissä
news:f951kq$2fss$1 at digitalmars.com...
> Daniel919 wrote:
>> 3. const P func(P p) { ... }
>> reads like: func returns a const(P)
>
> Which is, indeed, a problem -- in that I agree.
I agree, as well. It reads like returning a const P.
>> const / invariant alone (without brackets) is an attribute and has no
>> other meaning
>> further proposal: returned types in a bracket at the end:
>> 3. const func (P p) (P) { ... }
>> //templated syntax: const func!(T) (T p) (T) { ... }
>
> Uhm. Ew. No, seriously, I just could not possibly handle that; I would
> keep thinking I saw templates where there aren't any. Worse yet, for a
> long time I'll see the '!(' and keep wondering how I could be
> instantiating a template in that position, when its really a template
> declaration. T'is a naughty naughty thing to mix the two -- would give
> both the compiler and the user headaches. IMHO, its the
> 'const'/'invariant' keyword on methods that needs to move -- not sure
> where it should go, though. What looks best down here? ;) (First
> listing is the current state, for reference.)
>
> const P vunc (P p) { ... }
> P const func (P p) { ... }
> P const:func (P p) { ... }
> P const(func) (P p) { ... }
> P func const (P p) { ... }
> P func:const (P p) { ... }
> P func (P p) const { ... }
Definitely the last one. It's immediately familiar to anyone with a C++
background, which I guess most of those coming to D has, and which I think
are the people Walter is especially targetting. It also has the added bonus
of not complicating method declaration grammar too much.
Same list, this time a const func returning a const return value:
const const(P) func (P p)
const(P) const func (P p)
const(P) const(func) (P p)
const(P) func const (P p)
const(P) func:const (P p)
const(P) func (P p) const
I definitely prefer the last one as the cleanest of these.
More information about the Digitalmars-d
mailing list