It would be great to have nullable reference types enabled by default in new projects.
Because of the breaking changes it's understandable that this is not the default with existing projects, but creating new projects this should be the default, or easily turned on to be the default.
Just turning nullable reference types on with directory properties does not help. Using this, if a project with nullable reference types is copied results in compiler warnings.
At least there should be an option that can be easily configured that new projects should be created with nullable reference types turned on.
Enabling by default is even better: https://github.com/dotnet/roslyn/issues/52302.
Depending on the status in the Roslyn repo, it probably can be closed here.
Thank you for great idea, will see where Roslyn discussion leads and act accordingly.
Let's see where the Roslyn discussion goes. I am a tad concerned about turning it on in simple templates by default because of new to programming new users. Maybe @jongalloway or @jamesmontemagno could weigh in on that.
I think it should be turned on for the "new to programming" users - it helps them a lot to get rid of the null errors in their programs they do otherwise. @jongalloway @jamesmontemagno what's your opinion?
Honestly I am torn here, because yes I think it would get rid of null errors in code, but could lead to more confusion when things don't compile and you have to learn a big concept just getting started.
Some additional views: I'm working a lot with students. The main issues I'm seeing in their code is issues with null. If creating new projects don't have this setting, they don't turn it on. When they then first learn about this feature, they have a lot to change in their projects, and than this feature stays turned off.
Learning materials for beginners should show this feature early. This will not happen if nullable is not turned on by default.
I'm just in the finishing steps where all the projects have nullable turned on. Many complains from a reviewer because the code I'm showing does not compile with default project settings - although of course it was explained in the beginning. I added a note in every chapter that nullable is turned on.
Having a directory default setting does not help in this case. Copying a project to a different directory, it's not compiling anymore.
The more I'm thinking about it and helping new programmers - and also supporting long-time developers giving information on this feature - I think the default should be to have nullable turned on with new projects, and should be explicitly turned on with existing projects.
I hope this helps for the discussion.
I changed title, I hope you don't mind, I'm also a bit confused what is Roslyn planning to change on their side to change this...
We have enabled nullable for classlib.
For console template - we decided to freeze it at this point and not do anymore changes to it as it might be breaking change for many users that use it in their educational manuals. We are going to create new version of console template - "Console App" template - which will have nullable enabled.
Thanks for the status @vlada-shubina, what about the other templates (ASP.NET Core, WPF, .NET MAUI,...)?
@christiannagel other templates are being updated in scope of https://github.com/dotnet/templates/issues/485. This repo only have classlib, console and common item templates.
Most helpful comment
Some additional views: I'm working a lot with students. The main issues I'm seeing in their code is issues with null. If creating new projects don't have this setting, they don't turn it on. When they then first learn about this feature, they have a lot to change in their projects, and than this feature stays turned off.
Learning materials for beginners should show this feature early. This will not happen if nullable is not turned on by default.
I'm just in the finishing steps where all the projects have nullable turned on. Many complains from a reviewer because the code I'm showing does not compile with default project settings - although of course it was explained in the beginning. I added a note in every chapter that nullable is turned on.
Having a directory default setting does not help in this case. Copying a project to a different directory, it's not compiling anymore.
The more I'm thinking about it and helping new programmers - and also supporting long-time developers giving information on this feature - I think the default should be to have nullable turned on with new projects, and should be explicitly turned on with existing projects.
I hope this helps for the discussion.