Structs are Not Plain: A call for empty struct constructors
couteaubleu at gmail.com
Mon Sep 23 09:03:25 UTC 2019
On Friday, 20 September 2019 at 07:48:25 UTC, Dukc wrote:
> I know this all has the downside that you cannot implement more
> complex "never null" types in a practical way. But in fact,
> most of D stuff has "null" anyway: floats, chars, arrays,
> pointers, classes regardless of the definition. Only bools,
> integrals and enums (if you don't define one) do not, none of
> which are complex types. The philosophy AFAIK is that a type
> should always provide a null value, if it can be assigned
> normally "wrong" values without enlarging it.
I just want to point out that this isn't an inherently unsolvable
problem. You can have a type system where leaving your variable
uninitialized is statically forbidden, while using sum types
(Optional!T, Result!(T,E), etc) to handle functions taking or
returning "wrong" values.
It doesn't even have to be as complex as Rust. Just disable
default construction for types without a .init value, and
encourage the user to use Optional!T for corner cases.
More information about the Digitalmars-d