Added: C# Design Notes for nullable reference types #1208
Replies: 11 comments
-
Have you thought about adding support for something similar to But files similar to Roslyn's PublicAPI.txt could be sideloaded into existing projects to mark the nullability of existing libraries. They could even be crowdsourced for libraries that are no longer supported by the creators or where the source code of a specific version is lost. |
Beta Was this translation helpful? Give feedback.
-
@orthoxerox |
Beta Was this translation helpful? Give feedback.
-
FWIW, Code Contracts uses reference assemblies for this purpose - given Additionally, it also provides Contract reference assemblies for the BCL. Even if C#8 goes a different route and doesn't use reference assemblies to annotate nullability, it might be worth piggybacking off of Code Contracts and converting the nullability portions of the BCL contracts into whatever form C#8 uses to annotate pre-existing assemblies. |
Beta Was this translation helpful? Give feedback.
-
Because this might be too confusing, it's not scoped and people will have to play the analyzer and figure whether it's nullable or non-nullable based on the flow of the code so being explicit about makes the code easier to follow. To make it stick all people have to do is wrap the section of code with an
|
Beta Was this translation helpful? Give feedback.
-
Would it make sense to consider For example, consider: class Phone {}
class Person
{
string Name { get; }
Phone? Phone { get; }
}
void Call(string name, Phone phone) { ... }
void CallEveryone(IEnumerable<Person> people)
{
var peopleWithPhones = people.Where(p => p.Phone != null);
foreach (var person in peopleWithPhone)
Call(person.Name, person.Phone);
}
|
Beta Was this translation helpful? Give feedback.
-
Why? Array covariance is a bad feature and consistency with a bad feature does not seem like something to strive for to me. If I really want to make the conversion, I can do it by using |
Beta Was this translation helpful? Give feedback.
-
How can I install Nullable preview, if I don't have preview version of Visual Studio and "Installing on a machine with multiple versions of Visual Studio is not supported."? I have to completly unistall VS 2017, then install VS 2017 Preview? It's will be too long, with all C++, Python, SDK's and other stuff. |
Beta Was this translation helpful? Give feedback.
-
This is off-topic for design discussions, however, you only need 15.5, which is no longer in preview. I wouldn't recommend installing an experimental compiler in your production instance of Visual Studio. Personally, I'd recommend using a virtual machine. |
Beta Was this translation helpful? Give feedback.
-
Have we some idea if we will be able to create extensions for nullable reference types? today |
Beta Was this translation helpful? Give feedback.
-
I would like to see nullability annotations to be supported and released first, so that annotated APIs will be widespread, before flow analysis reach mature state. The most useful part is the function signiture annotation, which can be used by documentation and intellisense, while even local variable annotation could be out of MVP. Tools like Resharper can already do some simple nullability analysis today. The analysis does not have to be perfect and stable as carved in stone; it has a lot of room to improve in the long run. A progressive approach across several releases fits better IMO. |
Beta Was this translation helpful? Give feedback.
-
There is no difference between a reference type and its "nullable" version at runtime, this feature is only compile-time annotations. Read my comment over here which notes the relevant parts. |
Beta Was this translation helpful? Give feedback.
-
I completed the outstanding design notes related to nullable reference types. Opening just one discussion issue, since some of the decisions in individual notes are outdated.
C# Language Design Notes for Aug 16, 2017
C# Language Design Notes for Aug 23, 2017
We discussed various aspects of nullable reference types
C# Language Design Review, Oct 4, 2017
Added earlier. Included here for completeness.
We looked at nullable reference types with the reviewers, Anders Hejlsberg and Kevin Pilch.
C# Language Design Notes for Oct 11, 2017
We looked at the Oct 4 design review feedback for nullable reference types, and considered how to react to it.
C# Language Design Notes for Nov 8, 2017
We went over the status of the prototype for nullable reference types, to address outstanding questions and make any last minute calls before release.
C# Language Design Notes for Nov 27, 2017
We went over the feedback on the nullable reference types prototype, and discussed how to address the top issues that people had found using the feature on their own source code.
Beta Was this translation helpful? Give feedback.
All reactions