Real nullable types will probably never make it to the language, but wel can still dream
Posted by jpluimers on 2016/10/06
Allen Bauer (ex Delphi R&D team) wrote the brilliant piece about a year and a half ago. We can still dream, right?
Allen Bauer, May 25, 2015Current working theory of
Nullable<T> = record
property Value: T read FValue; default;
defaultdirective to “hoist” the operators of “
T“. Currently the
defaultdirective only works for
arrayproperties by “hoisting” the ‘
‘ operator. Marking a non-array property with
defaultwill make the containing type behave as that type.
This, coupled with some intrinsic compiler knowledge of the
Nullable<T>type will make
Nullable<T>work without any addition of keywords or other standard functions or procedures.
Using the “
default” directive on a non-array property will work for any type, except for having the null-propagation semantics.
When considering language features, I try and not only make it work for the intended purpose, but also broaden reach of any supporting feature. In the above scenario, even user-defined operators on “
T” will be properly hoisted and used.
This was part of a very interesting G+discussion at Delphi’s New Feature Desired: Nullable Types and Null Propagation….
It covered topics like these:
- Rooted type systems
- IfThenElse implementations (and what’s needed in the language to have them)
- Null propagation
- The inline keyword
- Lazy parameters
- Nullable types in the Spring4D framework (see Spring.pas)