Normalizing Const Syntax.
Janice Caron
caron800 at googlemail.com
Thu Apr 10 06:03:30 PDT 2008
On 09/04/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
> so my personal conclusion is - why
> have two pairs of parens? lets unite them to the following:
> int a(const this, const int a);
> which is very clear on its intent, IMO.
>
> Questions? Suggestions?
I don't have any particular problem with that syntax, however, it's no
better or worse than any other possiblity. The following all seem to
be equally acceptable:
(1) ReturnType f(Params...) const
(2) ReturnType f(const this, Params...)
(3) ReturnType const f(Params...)
Of these, (1) is *already legal syntax*, so it's not like we need
something to replace it. (Yours is option 2) Indeed, the simplest
answer of all would be just to get rid of const-at-the-front, leaving
const-at-the-back as the way to do things.
However, there is a reason why Walter has not made const-at-the-front
illegal, which is that /he likes it/. And so far as I can gather, the
reason that he likes it is because it means he is able to write
const
{
/* lots of functions */
}
So you see, part of the purpose of the const(this) proposal is to keep
Walter happy. It means that he will still be able to do
const(this)
{
/* lots of functions */
}
Only something-at-the-front can do this. So, const(this) is an attempt
to simultaneously (a) remove the current unintuitive syntax, and (b)
keep Walter happy. It's also consistent with D-style in that D already
has attributes like extern(C) and version(Windows), so const(this)
would be right at home.
And of course - the bonus is that
const R f(...)
can have its intuitive meaning of "f returns a const(R)".
(Of course, if const(this)-at-the-front ever replaces
const-at-the-front, then the question of whether to allow
const-at-the-back returns to haunt us! :-))
More information about the Digitalmars-d
mailing list