lithander wrote: ↑Tue Jan 24, 2023 1:00 pm
Yeah, I gave that new "feature" 3 minutes before I googled how to get rid of it.
I'm the other way for the moment. I just check the nullability option at the project level that forces all reference variables to be not null. Then when you want a nullable reference, you have to declare it that way. At first it took some adjustment, but now I leave it on. I hated having to test for null when writing routines other developers might call. It is amazing just how many unit tests we had to write to guarantee that the appropriate exception was being thrown when a null parameter was passed. The "!" nullability override is ugly -- on that we can agree.
Of course, if you have had to write as much parameter checking code for all my methods to prevent calling with null as I did in my former career (before I retired) maybe you would feel the same.
You could always Board?.CanCaptureKing(Board.OpponentColor) ?? throw new ..... (Yeah, that's pretty ugly too.)
lithander wrote: ↑Tue Jan 24, 2023 1:00 pm
Yeah, I gave that new "feature" 3 minutes before I googled how to get rid of it.
I'm the other way for the moment. I just check the nullability option at the project level that forces all reference variables to be not null. Then when you want a nullable reference, you have to declare it that way. At first it took some adjustment, but now I leave it on. I hated having to test for null when writing routines other developers might call. It is amazing just how many unit tests we had to write to guarantee that the appropriate exception was being thrown when a null parameter was passed. The "!" nullability override is ugly -- on that we can agree.
Of course, if you have had to write as much parameter checking code for all my methods to prevent calling with null as I did in my former career (before I retired) maybe you would feel the same.
You could always Board?.CanCaptureKing(Board.OpponentColor) ?? throw new ..... (Yeah, that's pretty ugly too.)
I worked in the past on a project where you had to check everything with an ok boolean or something. Making your code much more difficult to read when you were only interested in the main line.
Fortunately this is my own project. No unnecessary checks. No checks on events that never happen. And if they happen I will repair it.
By the way it is easier to switch nullable off then switch nullable on and repair the warnings.
You need to remove ? as well as ! and that is relatively easy work.
Henk wrote: ↑Wed Jan 25, 2023 11:39 am
By the way would be nice to introduce the 'not' operator as well if you want to improve C#.
They actually did introduce the is not operation that is used for pattern matching. I sometimes use that to shut up the Resharpener nags about transforming my legacy comparisons.