On Sunday, 19 May 2013 at 21:36:17 UTC, Andrei Alexandrescu wrote:
On 5/19/13 4:30 PM, Peter Alexander wrot
OK, this is sensible. One question - would you be willing to
type symbols as NullType!T instead of T to avoid these issues?
Thanks,
Andrei
Trying to come up with some once-and-for-all safe way to deal
with null in languages which allow null references by default is
something I wonder about now and then. This is due to my desire
to adopt nice patterns for making my time spent working with a
language safer and easier.
Option/Maybe I think only really works when the language has
references as non-null by default. Otherwise, you're writing
verbose code for Option/Maybe and lies the rest of the time. (I'm
looking at Scala.) For D, I decided that my way to do it, to be
applied almost all of the time, is to write contracts.
void func(Klass value) in {
assert(value !is null);
} body {
}
This stops null from being passed through too many functions, so
that alleviates a lot of problems. I think contract programming
is a good solution for this, and it applies more generally to
other kinds of invalid values. This can include values other than
the default values.