Struct with default ctor (Was: [dmd-beta] dmd 2.064 beta take 2)
deadalnix
deadalnix at gmail.com
Sun May 19 11:30:09 PDT 2013
On Sunday, 19 May 2013 at 18:23:22 UTC, Walter Bright wrote:
> On 5/19/2013 5:02 AM, Simen Kjaeraas wrote:
>>> By definition? Pointer semantics are what we choose it to
>>> mean.
>> Of course. But which definition is saner:
>
> For many types, it is extremely useful to have some sort of
> "invalid" value for it. null fills that role nicely for
> pointers, just as nan does for floating point types, and 0xFF
> does for UTF-8.
>
I don't wanted to bring that up because I thought it would
confuse people, but yes, 0xFF for char is the exact same problem
and I argue in the same direction : require explicit
initialization.
> There's not anything insane about it. The Nullable type
> constructor even exists in order to provide such an invalid
> state for types (like int) which normally do not have one.
>
If something can be null, you MUST do something to handle
specifically the null case. D completely fail to ensure that.
void buzz(Foo f) {
f.foo(); // Rely in faith. It is invalid and way easier to
write than the valid code, which is THE recipe for it to spread.
}
More information about the Digitalmars-d
mailing list