this post was submitted on 30 Jun 2024
281 points (94.9% liked)

Programmer Humor

18961 readers
1074 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 

Meme transcription: Panel 1. Two images of JSON, one is the empty object, one is an object in which the key name maps to the value null. Caption: “Corporate needs you to find the difference between this picture and this picture”

Panel 2. The Java backend dev answers, “They’re the same picture.”

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 32 points 1 month ago* (last edited 1 month ago) (24 children)

If you’re branching logic due to the existence or non-existence of a field rather than the value of a field (or treating undefined different from null), I’m going to say you’re the one doing something wrong, not the Java dev.

These two things SHOULD be treated the same by anybody in most cases, with the possible exception of rejecting the later due to schema mismatch (i.e. when a “name” field should never be defined, regardless of the value).

[–] [email protected] 8 points 1 month ago (15 children)

Ya, having null semantics is one thing, but having different null and absent/undefined semantics just seems like a bad idea.

[–] [email protected] 39 points 1 month ago (14 children)

Not really, if absent means "no change", present means "update" and null means "delete" the three values are perfectly well defined.

For what it's worth, Amazon and Microsoft do it like this in their IoT offerings.

[–] [email protected] 3 points 1 month ago

it does feel ambiguous though as even what you outlined misses a 4th case. if null means delete, how do I update it to set the field to null?

load more comments (13 replies)
load more comments (13 replies)
load more comments (21 replies)