[Numpy-discussion] Shouldn't all in-place operations simply return self?

Nathaniel Smith njs@pobox....
Thu Jan 17 12:29:08 CST 2013

On Thu, Jan 17, 2013 at 6:08 PM, Dag Sverre Seljebotn <
d.s.seljebotn@astro.uio.no> wrote:
> In addition to the verb tense, I think it's important that mutators are
> methods whereas functions do not mutate their arguments:
> lst.sort()
> sorted(lst)

Unfortunately this isn't really viable in a language like Python where you
can't add methods to a class. (list.sort() versus sorted() has as much or
more to do with the fact that sort's implementation only works on lists,
while sorted takes an arbitrary iterable.) Even core python provides a
function for in-place list randomization, not a method. Following the
proposed rule would just mean that we couldn't provide in-place shuffles at
all, which is clearly not going to be acceptable.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130117/c2b71a60/attachment.html 

More information about the NumPy-Discussion mailing list