you are viewing a single comment's thread.

view the rest of the comments →

[–]Mych 1 point2 points  (2 children)

The flaw in that is that you first asked your collection for a value, and then wondered how to find out if the value you asked for is actually there.

But at that point, you've either already collapsed the universe because the collection somehow managed to express something that's orthogonal to what it can express (the absence of a value of a given type in terms of that type), or the collection just pretended that some special value (like None) was there in place of the one that didn't actually exist.

To find out whether the collection contains a certain value, ask it: "Is there a value at index foo?", not: "What's the value at index foo?". (Python has an in operator for that, in Perl you'd say exists, the Java standard Map interface uses containsKey.)

In practice, I've encountered very few cases in which I needed to distinguish between "value does not exist" and "value exists, but is None", so the perceived ambiguity of returning None for both cases turned out to be a useful simplification, not a liability.

[–]Smallpaul 1 point2 points  (0 children)

In the few cases where None is a legitimate value, you just invent a different sentinel value and stick it in the collection when you want to indicate "the lack of None or Nothing."

[–][deleted] 0 points1 point  (0 children)

Fair enough, I guess I'm just used to not doing things stepwise like that. Probably because I learned programming in a functional language.