On Thu, Jun 25, 2020 at 6:44 PM Alex Hall <alex.moj...@gmail.com> wrote:
> Previous discussions on this: > > > https://mail.python.org/archives/list/python-ideas@python.org/thread/ASHOHN32BQPBVPIGBZQRS24XHXFMB6XZ/ > > https://mail.python.org/archives/list/python-ideas@python.org/thread/K5SS62AB5DFFZIJ7ASKPLB2P3XGSYFPC/ > (seems > like part of the above discussion that got separated) > > https://mail.python.org/archives/list/python-ideas@python.org/thread/CKF2GFI3HKQAAYRCMMRPTFMONG3UGO4T/#CKF2GFI3HKQAAYRCMMRPTFMONG3UGO4T > The latest of these discussions is over 8 years old, and I think it deserves bringing up again. The convention that "methods that modify self return None" is useful, but I would say that dict's equivalent method: dict.setdefault is a modifying method that also returns a pertinent (and often useful value), even though it could too be split into two methods (__getitem__ and __setitem__ if the key is missing), as does dict.pop (BTW, I think that set.discard should also return a boolean, but that discussion can wait). Indeed, adding a return value to set.add would not improve runtime performance, but I believe it would both improve readability and make code more fluent to write. As for teaching, I don't think this additional bit of complexity would be too difficult to learn. "set.add ensures that an item is in the set and returns whether it was already included" seems pretty straightforward to me. Not to mention that anyone coming from C#, Java, C++, and many other languages would already be familiar with this concept. Overall, I think my gripe is that, currently, set() does not have the capabilities of a dict that maps to NoneType, that the simplest implementation of set in python is more powerful than the standard library's version.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/UHCVO5PAS7DJXSGLMYEW72BRCE3RZUYT/ Code of Conduct: http://python.org/psf/codeofconduct/