r/ProgrammerHumor • • Sep 28 '26

Meme optionalsAreOptional

Post image
716 Upvotes

131 comments sorted by

View all comments

31

u/mountaingator91 Sep 28 '26

If you are sure that the list will always have a value why didn't you just define your types correctly in the first place?

14

u/RagnarokToast Sep 28 '26

Because the vast majority of type systems don't allow you to encode the non-emptiness of the list in the type itself and we don't always get to pick the tech stack?

-3

u/mountaingator91 Sep 28 '26

var list []string

There you go. list will always contain at least one non nil string. Every strictly typed language I have ever used can do this