Coding Shorts: Nullable Reference Types: Or, Why Do I Need to Use the ? So Much!

  Рет қаралды 10,242

Shawn Wildermuth

Shawn Wildermuth

Күн бұрын

Пікірлер: 59
@Switchs89
@Switchs89 25 күн бұрын
Solid material. When you go over reference types nullability with such ease, you know straight away that you are listening to a an expert. Thanks.
@swildermuth
@swildermuth 25 күн бұрын
That's very kind of you. Glad you liked it.
@arttrenton4467
@arttrenton4467 Жыл бұрын
Shawn, you did an outstanding job of clarifying this new feature. I was struggling to understand why this was done. It now make sense to me. Thanks 😊
@swildermuth
@swildermuth Жыл бұрын
Happy to help!
@lasermouth
@lasermouth Жыл бұрын
Amazing video! The only video that cleared up for me why there's such a thing as nullable ref types. In short, it was to eliminate ambiguity by forcing an explicit declaration of intent. I also enjoyed the latter half where you went into the operators and the generic example.
@swildermuth
@swildermuth Жыл бұрын
Glad it helped!
@hozmannew896
@hozmannew896 Жыл бұрын
you have unusual way to simplify anything in a minute, great explanation as usual, thank you so much
@imaginative-monkey
@imaginative-monkey Жыл бұрын
Thanks for the video! 👍 Sometime for new projects, I add Nullable to the csproj, so the code won't compile unless I fix nullability issues. This makes me understand the concept better.
@trestenpool9045
@trestenpool9045 Ай бұрын
great vid. You cleared up a lot of confusion I previously had!
@swildermuth
@swildermuth 27 күн бұрын
Glad it helped. Took me a while to get my head around it too.
@swordblaster2596
@swordblaster2596 Жыл бұрын
most important change in the last 5 years. Paying attention to this as the tools are trying to make you do, massively improves your design.
@jonb8869
@jonb8869 7 ай бұрын
How? Can you elaborate on this?
@russellf
@russellf 3 ай бұрын
Came back for a refresher. A great summary, thanks! One thing I still ponder about is nullability on classes and records that are loading, e.g. config from disk etc., where you want to almost tell the compiler, “these fields are always set”. I guess this is adding ! to members but maybe there is a better way?
@swildermuth
@swildermuth 3 ай бұрын
You can say "required" and use non-nullable - they just need to be initialized in the constructor or object syntax.
@russellf
@russellf 3 ай бұрын
I completely missed the required keyword - thanks!
@TheDrewCrawford
@TheDrewCrawford Жыл бұрын
This information was exactly what I was looking for. Greate stuff Shawn. Thanks for sharing your knowledge.
@swildermuth
@swildermuth Жыл бұрын
Glad it helped
@sschulze2891
@sschulze2891 Жыл бұрын
Thanks for the clear explanation on this. One thing that might be missing is that you can also get ris of the "may be null" warning by performing a null check somewhere before in the code. To me the addition of nullabel reference types possibly had the biggest impact of all newer features and i would never deactivate it on a new project now. Migrating old code can be a pain though ...
@arjanvandenberg5313
@arjanvandenberg5313 Жыл бұрын
Brilliantly explained in such a short way! Thanks a lot for your educational lessons 😊
@nalcora7389
@nalcora7389 Жыл бұрын
Extemely well done video, full and concise; have watched many video tutorials over the years both on YT, Pluralsight, etc; format is excellent.
@robby-de-laet
@robby-de-laet Жыл бұрын
Well, that was a clear explanation. Thanks Shawn.
@swildermuth
@swildermuth Жыл бұрын
Glad it was helpful!
@enigma_dev
@enigma_dev Жыл бұрын
Amazing video, thanks for putting it together!
@coderider3022
@coderider3022 8 ай бұрын
I switched to using result / option / elevated types from the functional world in my c# and never looked back. Nullable and handling of them was a terrible idea for c#. I get its backward compatibility but time to evolve.
@swildermuth
@swildermuth 8 ай бұрын
Immutability and nullability are not the same issue. But I'm glad it is working for you.
@sadhappy8860
@sadhappy8860 9 ай бұрын
Great video, really helped me thank you. Although the word null kept going funny in my head. Haha
@GBUKMilo
@GBUKMilo 27 күн бұрын
Love this video, thanks Shawn
@swildermuth
@swildermuth 27 күн бұрын
I appreciate it!
@jasonazevedo1983
@jasonazevedo1983 Жыл бұрын
Your content is amazing.. well done! don't stop!!
@swildermuth
@swildermuth Жыл бұрын
Ok!
@redcrafterlppa303
@redcrafterlppa303 Жыл бұрын
It's funny how c# is now doing the same thing java did with generics decades ago. Provide an optional "upgrade" to the new system and all old stuff is now a warning. And seeing that this "slow migration system" never completed in java we can assume that c# will have projects with nullabity and without for pretty much forever.
@a-s733
@a-s733 Жыл бұрын
short and clear
@swildermuth
@swildermuth Жыл бұрын
Glad you liked it.
@jedjohan
@jedjohan Жыл бұрын
Thanks, very good stuff. What would you say are the benefits, for developers and the applications we build. I know you did mention it in the end, but I somehow got the impression of "just do it" rather than "do it so that your code will ..."
@swildermuth
@swildermuth Жыл бұрын
I think the benefit is more transparency to what you expected. By specifying nullability, you're telling the developer after you what you expect. Whereas before Nullable Reference Types, I didn't have a way of saying "This will never be null".
@jedjohan
@jedjohan Жыл бұрын
@@swildermuth I also like that the code, when in runtime, will not (hopefully) get "null ref"-issues. Or am I misunderstanding ?
@swildermuth
@swildermuth Жыл бұрын
@@jedjohan That's true (harder to get null ref issues, but not impossible)
@montana3426
@montana3426 Жыл бұрын
Thanks for great video!
@swildermuth
@swildermuth Жыл бұрын
My pleasure!
@onedev7316
@onedev7316 Жыл бұрын
Nice one. Thank you
@swildermuth
@swildermuth Жыл бұрын
Always welcome
@prateektomar4874
@prateektomar4874 7 ай бұрын
Nice explaination.
@swildermuth
@swildermuth 7 ай бұрын
Glad you liked it
@kraadhithya9841
@kraadhithya9841 Жыл бұрын
good explanation
@swildermuth
@swildermuth Жыл бұрын
Thanks and welcome
@semuhphor
@semuhphor Жыл бұрын
Cool channel. Thanks. I have been uneducated about how this feature works. Now I ain't. :D
@georgepagotelis
@georgepagotelis Жыл бұрын
At 3:00 - "int? x = default" - the value is not 0 but null! (I was testing code as you were displaying it) Which brings me to my next question, why isn't it clear by the compiler what "default" value is!
@swildermuth
@swildermuth Жыл бұрын
Null isn't the default for anything. Default for value types are typically 0 for numeric types.
@MohammadKomaei
@MohammadKomaei Жыл бұрын
How to create project by n new instead of dotnet new? when I use it I get error: n : The term 'n' is not recognized as the name of a cmdlet
@swildermuth
@swildermuth Жыл бұрын
Sorry, it is "dotnet new" - I just have a batch file that redirects to dotnet so I only have to type "n"
@redcrafterlppa303
@redcrafterlppa303 Жыл бұрын
9:25 In fact the code: var len = user.Name?.Length; len is of type int? var len = user.Name!.Length; len is of type int
@王宏亮-x8h
@王宏亮-x8h Жыл бұрын
This feature adds unnecessary complexity to the c# language.
@allanhouston22
@allanhouston22 6 ай бұрын
C# is a Frankenstein language for a long time. Now this nullable stupity is made so that the code is easily read and used by the AI... I hate it
@swildermuth
@swildermuth 6 ай бұрын
Not sure how AI plays into it. But you're able to not use nullable reference types. There seems to be a separation into two dialects of the language over the years. C# 13 is the maturation of including more functional ideas, but it's all opt-in. You don't have to use it if it's not serving your needs.
@WillEhrendreich
@WillEhrendreich Ай бұрын
Coming from an Fsharp perspective, nrt is helpful, but.. Like.. Not enough safety still. Lol. Types should never be null, null is terrible. Option is nicer, result is even better. Null was never a good idea.
@swildermuth
@swildermuth Ай бұрын
I understand this perspective coming from F#, but C# is still an OOP language and the concept of NULL is still valid, especially when you're working with data stores that keep that concept.
@SasanSalem
@SasanSalem Жыл бұрын
Great explanation
@swildermuth
@swildermuth Жыл бұрын
Glad you liked it.
Coding Shorts: Using the Vite PWA Plug-in
14:05
Shawn Wildermuth
Рет қаралды 27 М.
Coding Shorts: For The Record - Why You Should Use (Records in C#)
10:46
Shawn Wildermuth
Рет қаралды 13 М.
Мама у нас строгая
00:20
VAVAN
Рет қаралды 11 МЛН
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 25 МЛН
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
Manage Nulls Like a Boss and Never Fail!
21:43
Zoran Horvat
Рет қаралды 14 М.
Андрей Дятлов - Nullable reference types - advanced guide
56:54
DotNext — конференция для .NET‑разработчиков
Рет қаралды 4,3 М.
C# Nullable reference types - No more null reference exceptions!
18:06
Coding Shorts: ASP.NET Core Middleware Explained
17:36
Shawn Wildermuth
Рет қаралды 31 М.
Coding Shorts: Ahead-of-Time Compilation in C# (AOT)
12:03
Shawn Wildermuth
Рет қаралды 2,3 М.
How to Avoid Null Reference Exceptions: Optional Objects in C#
18:13
Coding Shorts: C# Dialects and Idioms
19:13
Shawn Wildermuth
Рет қаралды 3,5 М.
Nullable Reference Types and Null Operators in C#
12:56
Jeremy Clark
Рет қаралды 1,3 М.
Namespace and Assembly in C# - Where is the difference?
8:46
tutorialsEU
Рет қаралды 8 М.