const

Yigal Chripun yigal100 at gmail.com
Mon Mar 31 08:25:31 PDT 2008


Janice Caron wrote:
> On 31/03/2008, Jason House <jason.james.house at gmail.com> wrote:
>   
>> Maybe rov or read.
>>     
>
> Again, "readable" doesn't imply "not writeable". (It is perfectly
> possible for a thing to be both readable and writeable at the same
> time).
>
> Let's just stick with "in". It's /already implemented/ in one of the
> places where it's needed, and let's face it, keywords don't get much
> shorter!
>   

just to throw my 2 cents to the mix:
i don't like "in" as it doesn't mean "read only view" and for a line like :
in(int) temp = 1;
that's just looks strange to me.
the stated benefits of using it as stated by others are the fact that
it's already in the language, and it's short.

instead of looking at current "const" meaning as read only view, you
could say it's means "protected". a protected variable is such a
variable that is protected from writing. the word "protected" itself is
too long for my personal taste, so here's a list of other possibilities:
 - shielded (I've seen this on someone else's post)
 - sealed  (used in c#)
 - protected (too long IMO)
 - final (already reserved in D) <- i like this one as it's the same
length as const, already in D, etc..
 - perm[anent]
- fixed
etc...

Personally, I think "in" should be deprecated. no need to have two
reserved words that do the same thing (if it currently means const, why
should I bother using const which is longer? )
const should replace invariant (I agree with everyone else that
invariant breaks the meaning of const in D1, and it's long)
also, in my ideal world, functions would be rewritten with the return
type at the end:
someFunc(...param list...) returnType;
but I'd settle for:
final(this) returnType someFunc(...param list...);

one last thing: since D const != C/C++ const (transitivity and such)
than the D syntax for it shouldn't try to be backward compatible to
C/C++. that's just confusing. a good example of that is :
const const int func(params..);
that's bad. i'd prefer that the syntax const(T) would be mandatory.

-- Yigal



More information about the Digitalmars-d mailing list