Identification
Billion-Dollar Mistake
Did you know that the inventor of the concept of null has called it his Billion-Dollar Mistake (https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare/)?
As simple as it seems, once you get into larger projects and code bases, you'll inevitably find some code that goes off the deep end in its use of nulls.
Sometimes, we want to simply make a property of an object optional:
class Product{ public id: number; public title: string; public description: string; }
In TypeScript, a string
property can be assigned a null
value.
But so can a number
property!
const chocolate: Product = new Product(); chocolate.id = null; chocolate.description = null;
Hmmm....
Example
That doesn't look so bad at first glance.
However, it can lead to the possibility of doing something like this:
const chocolate: Product = new Product(null, null, null);
What's wrong with this? Well...