Which D features to emphasize for academic review article

Era Scarecrow rtcvb32 at yahoo.com
Tue Aug 14 13:02:22 PDT 2012


On Tuesday, 14 August 2012 at 15:24:30 UTC, F i L wrote:
>> Really? We can catch (or, should be able to) missing 
>> initialization of stuff with @disable this(), but not floats?
>>
>> Classes have constructors, which lend themselves perfectly to 
>> doing exactly this (just pretend the member is a local 
>> variable).
>>
>> Perhaps there are problems with structs without disabled 
>> default constructors, but even those are trivially solvable by 
>> requiring a default value at declaration time.
>
> You know, I never actually thought about it much, but I think 
> you're right. I guess the same rules could apply to type fields.

Mmmm... What if you added a command that has a file/local scope? 
perhaps following the @disable this(), it could be @disable init; 
or @disable .init. This would only work for built-in types, and 
possibly structs with variables that aren't explicitly set with 
default values. It sorta already fits with what's there.

@disable init; //global scope in file, like @safe.

struct someCipher {
   @disable init; //local scope, in this case the whole struct.

   int[][] tables; //now gives compile-time error unless @disable 
this() used.
   ubyte[] key = [1,2,3,4]; //explicitly defined as a default
   this(ubyte[] k, int[][] t){key=k;tables=t;}
}

void myfun() {
   someCipher x; //compile time error since struct fails (But not 
at this line unless @disable this() used)
   someCipher y = someCipher([[1,2],[1,2]]); //should work as 
expected.
}


More information about the Digitalmars-d mailing list