As I started reading this, I immediately thought of the toilet paper dispenser graphic, and then you included it! :-)
I refer to that diagram when I need a refresher about the differences between null and undefined or 0. Essentially, I view null as describing a state of a variable when the variable is fully understood but hasn't yet been given a value.
I just took a quick look at some Typescript-based React/Redux code I've been working on, and I found quite a few references to null in two general situations. The first is in Redux store selectors to address the reality that the data hasn't been populated yet. Admittedly, these are explicitly Typescript types (i.e., the type null) to address the reality of no values being present.
function useRef<T>(initialValue: T|null): RefObject<T>;
If I am understanding your argument, the basic opposition to the use of null is that it lacks definitiveness and could remain hidden and misunderstood. In that sense, I do understand why it should be avoided.
But, I'm also not clear how I would remove them in the examples I've shown.
As I started reading this, I immediately thought of the toilet paper dispenser graphic, and then you included it! :-)
I refer to that diagram when I need a refresher about the differences between
null
andundefined
or 0. Essentially, I viewnull
as describing a state of a variable when the variable is fully understood but hasn't yet been given a value.I just took a quick look at some Typescript-based React/Redux code I've been working on, and I found quite a few references to
null
in two general situations. The first is in Redux store selectors to address the reality that the data hasn't been populated yet. Admittedly, these are explicitly Typescripttypes
(i.e., the typenull
) to address the reality of no values being present.The second situation is also on the front end:
const inputRef = React.useRef<HTMLInputElement>(null);
This is done to satisfy the typings:
function useRef<T>(initialValue: T|null): RefObject<T>;
If I am understanding your argument, the basic opposition to the use of
null
is that it lacks definitiveness and could remain hidden and misunderstood. In that sense, I do understand why it should be avoided.But, I'm also not clear how I would remove them in the examples I've shown.
Or, did I misunderstand your article?
Null does not exist. So it violates the MAPPER principle
IF you have control on the frontend you should avoid it. If you don't you should do damage control and not propagate it
Might be a dumb question, but what would you put in the
inputRef
initial value for React?Do you control React?
Anything but a null, For example a NullInputRef (it is not null)
You are not in control of React?
A null. and handle it ASAP in your model