Struct with default ctor (Was: [dmd-beta] dmd 2.064 beta take 2)

Walter Bright newshound2 at digitalmars.com
Sat May 18 18:20:31 PDT 2013


On 5/18/2013 5:23 PM, deadalnix wrote:
> On Sunday, 19 May 2013 at 00:14:26 UTC, Walter Bright wrote:
>>
>>     this() { assert(0); }
>>
>> makes for a runtime check, not a compile time one. Compile time checks are
>> more efficient in both programmer time and run time.
>>
>> Note that C++11 8.4.3 has @disable as well, in the form:
>>
>>    S() = delete;
>>
>
> D has @disable. If default constructor are allowed, default constructor can be
> disabled, as any other declared symbol.

I understand that. But the rationale you gave for having a default constructor 
was to be able to disable default construction.


>> With NotNull, the runtime check only happens upon assignment and
>> initialization from a pointer type. Dereferencing, copying, etc., of NotNull
>> entails zero runtime overhead and no checks.
>
> People go for the shortest path. You end up having nullable everywhere.
> Experience have been a countless amount of time in bazillion programming
> languages. But it is probably too late to fix this in D anyway.

I know that some languages have a special syntax for non-null pointers. I 
disliked this solution for D because non-nullable pointers are just one instance 
of creating a type with a limited set of values. Why not go for a general 
solution? Why not create a mechanism where a type can be defined that can only 
consist of prime numbers, for example? Why not ranged integer types?


More information about the Digitalmars-d mailing list