The problems with hidden nulls
Steve recalled a recent bug in his tower defense game.
Steve: I think I’ve run into this problem. My game crashed when trying to upgrade a tower that didn’t exist.
Julia: That’s a classic example, let’s look at how we can prevent that using what we’re learning today.
Have you ever felt confused trying to figure out why your program stopped working? Most times, the problem comes from a well-known NullReferenceException
. This section looks at the tricky connection between C# and null, pointing out the problems many developers face.
A quick look back – C# and null
To understand our current problem, let’s look back a bit. Tony Hoare, an important computer expert, called the null reference a “huge mistake.” The idea was to provide developers with a tool to show when a value was missing. At first, it seemed like a good plan, but it ended up causing many problems and mistakes in languages...