Re: We should have an explicit concept of emptiness for collections
While this does comply with "explicit is better than implicit", there's another line of the Zen of Python that this idea definitely violates: "There should be one-- and preferably only one-- obvious way to do it." (Followed by the line "Although that way may not be obvious at first...", which I'd say also applies; after all, the boolean value of a sequence may not be obvious to a new Python programmer.) The way I see it, the issue is a conflict between these two ideas of what Python code should look like. My strong opinion is against adding isempty(); I see no point. Once you learn Python, it makes sense that an empty sequence is False. I think most Python coders learn that early on. We get it. The "if (not) seq" idiom makes sense, especially since everyone has been doing that for the last twenty years. It's readable. If this is about the fundamentally unknowable type of seq, use type hints. And if you really want to be that explicit, use "if len(seq) == 0" (which could be just "if len(seq)" but that's ruins the whole point). I think isempty() doesn't solve problems. It's completely unnecessary. And if it's somehow actually implemented, implement it as a method of sequence types! A built-in function should either be totally necessary (see: print(), input(), all the basic ones you know and love), or at least make a job much easier and more readable (see: zip(), enumerate(), all(), any(), and more). Python may be a language designed to be readable, but even it isn't English and doesn't need to be. -- Finn
participants (1)
-
Finn Mason