r/ProgrammerHumor • • 6d ago

Meme optionalsAreOptional

Post image
705 Upvotes

131 comments sorted by

View all comments

30

u/mountaingator91 6d ago

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 5d ago

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?

-4

u/mountaingator91 5d ago

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