> What's the problem being solved by isempty? Are there any situations
> that couldn't be solved by either running a type checker, or by using
> len instead of bool?

I agree that determining the type is possible most of the time, either by type 
hints or a static analyzer. Using len is possible, with the limitation that you 
need a full `len(x) == 0` for numpy arrays (see discussion above). The type 
aspect was emphasized in the video. I'm not too worried about that explicitly. 
The video was more of a starting point for me to reconsider the ideom `if not 
users`. My conclusion (and thus proposal) differs from the video.

On a technical level, everything can be solved with the current language 
capabilities. The main advantage is clearer semantics (explicit is better / 
readability counts):
- Re bool: As experienced python users we are used to translate `if not users` 
to "if users is empty" or "if we have no users", but it *is* less explicit than 
`if users.is_empty()`.
- Re len: `if not len(users)` or `if len(users) == 0` is more explicit, but its 
semantically on a lower level. Counting elements is a more detailed operation 
than only checking if we have any element. That detail is not needed and 
distracting if we are only interested in is_empty. This is vaguely similar to 
iterating over indices (`for i in range(len(users))`) vs. iterating over 
elements (`for user in users`). We don't iterate over indices because that's 
usually a detail we don't need.

I acknowledge that discussing readability can be vague and subjective, not 
least because we are used to the current ideoms. I'm also aware that we should 
be very conservative on adding new API, in particular if it's not technically 
necessary. However, Python makes a strong point on readability, which IMHO is 
one of the major reasons for its success. I belive that in that context adding 
is_empty syntactic sugar would be a clear improvement.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/JQTXNHGJZYQL3BWNCED5WAJG2KITCFTG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to