Programming languages: "We are just a way to operate computers in a way that makes sense to humans."
Programming languages [takes a big joint hit]: "What if there were 5 kinds of nothingness?"
Programming languages: "We are just a way to operate computers in a way that makes sense to humans."
Programming languages [takes a big joint hit]: "What if there were 5 kinds of nothingness?"
I'm throwing in another tiny, obscure, dark corner case .... undefined behavior ....
Since people are liking this (for some reason), I felt like explaining the joke (for some reason).
In #JavaScript there are three distinct ways for a plain object to "not have x". There's certainly more if you add prototypes, getters, or worse, but that's on you then.
const a = { x: null };
const b = { x: undefined };
const c = {};
In most cases b and c are treated as the same case:
b.x === c.x; // undefined
JSON.stringify(b) === JSON.stringify(c); // {}
In some cases they're not:
Object.entries(a); // [['x', null]]
Object.entries(b); // [['x', undefined]]
Object.entries(c); // []
In some cases, the distinction matters. For example, if you have a function that takes a partial update to an object, it would be reasonable to take a to mean "set x to null" and to take c to mean "do nothing".
There is no reasonable way to interpret b, but I strongly believe it should be normalized to c, not a. Or throw a compile/runtime error. But certainly not turn undefined into null. That's two distinct kinds of nothingness in their own right, after all!
@olafurw I'm reminded of this story
> Said the master: “We have learned only that we have learned nothing, yet this is the root of wisdom.”
@olafurw That's just capturing reality with more accuracy than normal people tend to capture, because most of those cases don't often happen they are still actually relevantly different.
1. There's toilet paper
2. There's no toilet paper, the roll is empty
3. The roll is gone, but the roll holder is empty
4. There is no place to even put a roll if you had one, but there is a toilet
5. The toilet is being rebuilt and the place to mount the roll holder does not currently exist
Most people only care about 1 or not 1 when they ask "is the toilet paper out"... but we kinda need the other details, so we don't try to screw a roll holder into nothingness and crash the system.
@lbheuschkel @dascandy @olafurw
7. There's toilet paper, but the dog just put it in the toilet.
(Sorry, I know nothing about programming, but a surprising amount about toilet paper.)
@dascandy @olafurw I also wouldn't say it's that people don't capture that info; it's that (generally) a huge amount of information is captured nonverbally.
Customer: "Can I get some toilet paper?"
Answer 1: uh yeah, in the toilet *points*
Answer 2: One sec, I'll bring some more over
Answer 3: someone just used the last roll, sorry
Answer 4: can't you read? *angrily points at "closed for maintenance" sign*
Answer 5: *in hi-viz and hard hat* what the hell are you doing on my construction site? Get out!
We infer the type of zero from context
Answer 6: sir, please put the teapot back on the display, I'm going to have to ask you to leave the store
@dascandy @olafurw there's toilet paper but no roll.
That's before "2 people put a roll on at the same moment" and "someone knocked down the toilet whilst in use" and all the other stuff that does the real damage for correctness because most programmers are still taught in a serial way so just don't see the problem.
Yes, precise and interesting ways. I don't personally trust the humans who want things to be understandable to humans but haven't thought the concept through. This is how you get "AI prompt engineers".
@olafurw so:
X=null
X=0
X=0.0
X=""
X={ }
X=[ ]
exists(X)=false
So much fun 😁