DEV Community

Discussion on: You don't need null

Collapse
 
martinpham profile image
Martin Pham

That’s the thing.
Eg from a json response, a “post” which has “deleted_at” is null means it’s not deleted. But if the “deleted_at” is missing, it should be considered as invalid api response

 
loucyx profile image
Lou Cyx

That depends on the API implementation. This is like saying:

You need to use null because I wrote if (value === null)

Which is kinda like a Straw Man. If the API has a poor implementation that requires null, that doesn't mean you need to use null in your entire codebase, that just means you need to use it in your surface of contact with said API.

 
martinpham profile image
Martin Pham

Sorry but I wouldn’t consider an api which has consistent response for nullable object, as a poor implemented api..

 
loucyx profile image
Lou Cyx

Me neither, that doesn't have anything to do with null. You can just omit something when is "nullish" which translates to .... you guest it, undefined, and it has the added value that payloads are smaller 🎉

 
patroza profile image
Patrick Roza

Absence and null are different things, as said.
What constraints are you under that these minor payload sizes matter? you’ll probably get more out of gzip than omitting nullish.

 
martinpham profile image
Martin Pham

Payloads are smaller by omitting some characters, good.
But if it causes confusion between null (value is set as no value) and undefined (value is not set), I wouldn’t take it as a good thing.

 
loucyx profile image
Lou Cyx

"Absence and null are different things" ... how? The size of the payload doesn't only affect the request, also the parsing. You're literally loading something trough the wire and in memory that you could omit, just to use null X_X

Some comments have been hidden by the post's author - find out more