dotnet / dotnet/vblang

Proposal: Non Nullable Objects

Open
#386 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

I started this discussing in issue #355, where @KathleenDollard is stating that she is still undecided on the C# 8 implementation of (Non) Nullable References, as it only gives a "a bazillion warnings".

And I agree with this.
The Nullable References as implemented by C# is only an _attempt_ to prevent an object to become null.
It gives no guarantees at all and almost all assignments will create a warning.

That is why i came up with the Non Nullable Objects - an object with a default value.
This default value is the returnvalue of a specific function (that is not allowed to return a null value - if it does, the runtime error ).
Direct after each and every assignment to an Non Nullable Object, the compiler adds a check to see if the object became null, and if so, the DefaultValue function is called.

This function can be directly implemented in the class or (of runtime and third party libraries) be implemented as an Extension function.

Because every assignment is checked, the Object will _never_ contain a null reference.
It's like assigning nothing to a value type; it will just assign the default value to it - the only difference is that, with Non Nullable Objects, you define the default value yourself, and a Null Reference will be seen as Nothing, meaning the Default Value of the Object.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.