Private enum members + Descent

Yigal Chripun yigal100 at gmail.com
Mon Oct 26 13:49:38 PDT 2009


On 26/10/2009 12:07, Lars T. Kyllingstad wrote:
> Yigal Chripun wrote:
>> personally I'd like to see D enums replaced by Java style enums which
>> make more sense to me. D enums are even worse than C enums since you
>> can write:
>> enum foo = "text";
>>
>> which to me looks very similar to:
>> auto cat = new Dog;
>
>
> I agree that enum is a horrible keyword to use for declaring manifest
> constants. In my opinion the D developers are sometimes a bit too afraid
> of introducing new keywords, and this is one of the consequences.
>
> Personally, I think this would be a better scheme:
>
> const: manifest constants, no storage (like const in D1, enum in D2)
> readonly: used for a read-only view of mutable data (like const in D2)
> immutable: truly immutable data (like now)
>
> -Lars

i don't think we need to add more options, I think we need to remove 
options.
there should be only two types, const and mutable.
manifest constants should be a linker optimization and immutable is only 
relevant as part of a concurrency model and even then there's no need 
for a separate keyword.

immutable objects are shared objects where only the owner is allowed to 
modify it and only if it's done in a thread-safe way (synchronized with 
locks, lock-free algorithms).
void foo() {
// can be optimized away (transformed into a manifest constant)
// taking address of var is illegal
const var = 42;
// allocated on the heap and you can pass it's address around
auto bar = new const int(42);
}









More information about the Digitalmars-d mailing list