opMul

Janice Caron caron800 at googlemail.com
Thu Mar 6 02:43:34 PST 2008


On 06/03/2008, Koroskin Denis <2korden+dmd at gmail.com> wrote:
> This syntax looks less confusing to me. Why keep both?

The syntax /is/ confusing. This is one of those "remaining const
niggles" that is going to keep resurfacing until we come up with
something acceptable to all.

For now, I can tell you that const-at-the-end is allowed (a) for the
benefit of those used to C++ syntax, and (b) for the benefit of those
who just don't like const-at-the-start. Const-at-the-start is allowed
so that you can write stuff like:

    class A
    {
        const
        {
            A opAdd(A a) {...}
            A opSub(A a) {...}
            A opMul(A a) {...}
            A opDiv(A a) {...}
        }
    }

etc. Basically, it saves a lot of typing.

I know I'm repeating myself here, but I still think my previous
suggestion of replacing "const" with "const(this)" and allowing it
only at the front is still a good one. After all, how much extra
typing, proportionately, is

    class A
    {
        const(this)
        {
            A opAdd(A a) {...}
            A opSub(A a) {...}
            A opMul(A a) {...}
            A opDiv(A a) {...}
        }
    }

? And for single functions

    const(this) T f()

is a lot less confusing than

    const T f()

as the former tells me explicitly that "this" is the thing that is
const, wheras the latter makes it look like "T" is const (which it
isn't).

If this is not changed, then years, even decades from now, people will
still be complaining that it's confusing, and while it is true that
you can get used to it, I still think it's better not to confuse in
the first place.



More information about the Digitalmars-d mailing list