The Null Conundrum: A Guide to Optional Objects in C#



The Null Conundrum: A Guide to Optional Objects in C#

The Null Conundrum: A Guide to Optional Objects in C#

In this video, we are examining the impact of nullable references on the functionality of a program, including its structure and expressiveness. We will then delve into the topic of optional objects in C#, objects which are designed to either represent an existing object, or an object that is missing at run time – missing, but never null!

You will learn how you can design your own lightweight Option type in no more than a few lines of code. What comes at much higher cost than implementing the Option type is using it in an object-oriented design. You will learn how to handle situations where a value may or may not exist, but the caller never knows which of the two situations it is solving. So many puzzles!

But if you persist, if you accept the practice of using optional objects in place of null references, you will witness the birth of a rock-solid design with great flexibility attained with very little code. What else can one expect? There will be no null references in the final design, but also no null checks nor null guards. And with them, the danger of the dreaded NullReferenceException will also vanish.

If you wish to submit your code for a review, please use this form: https://codinghelmet.com/go/code-review-request

Video courses:
Beginning Object-oriented Programming with C# ► https://codinghelmet.com/go/beginning-oop-with-csharp
Collections and Generics in C# ► https://codinghelmet.com/go/collections-and-generics-in-cs
Making Your C# Code More Object-oriented ► https://codinghelmet.com/go/making-your-cs-code-more-oo

Other courses at Pluralsight ► https://codinghelmet.com/go/pluralsight
Other courses at Udemy ► https://codinghelmet.com/go/udemy

Additional videos:
The Fastest Way to Modify a List in C# ► https://youtu.be/0oSN65eM-tc
Coding with GitHub Copilot – Beginner to Master ► https://youtu.be/B9DKv09IfT4
Want to Start with DDD? Try Ubiquitous Language First! ► https://youtu.be/_zWMjMUHinc
Using C# Record Types ► https://youtu.be/VouNkrgkH78
Covariance and Contravariance in C# ► https://youtu.be/Wp5iYQqHspg
How do Virtual Functions Work? ► https://youtu.be/b0IDTWoaUJ0

Practical Design playlist at YouTube ► https://youtube.com/playlist?list=PLSDYwLgFqaX78eEg_YKs0wHmOMi7_ggZr

Comments are closed.