#20743: Parent.list() should return an immutable tuple -------------------------------------+------------------------ Reporter: jsrn | Owner: Type: defect | Status: new Priority: major | Milestone: sage-7.3 Component: categories | Resolution: Keywords: parent, immutable | Merged in: Authors: | Reviewers: Report Upstream: N/A | Work issues: Branch: | Commit: Dependencies: | Stopgaps: -------------------------------------+------------------------
Comment (by nbruin): Replying to [comment:10 kedlaya]: > But it might be unavoidable: tuples must consist of immutable objects, so it may not always be possible to return one. That is not true: {{{ sage: A=([1],[2]) sage: A[0].append(3) sage: A ([1, 3], [2]) }}} That said, I don't think `foo.tuple()` would be discoverable at all, so think that's a very bad name for implementing this functionality. I think it is essential that `foo.list()` continues to provide a way to indexably access constituents of an object (although it would be interesting to have data on how much code depends on that). If returning a list for that is too dangerous, I'd be fine with a tuple instead. If it has to be a list then that would be fine with me. If it's too difficult to let people use `copy` when they need to, we may just have to add an option. Something like: {{{ sage: foo.list() <returns a copied list> sage: foo.list(tuple=true) <returns the cached/stored tuple> sage: foo.list(copy=false) <returns the cached/stored list> }}} Concerning verbs/nouns: English is a pretty flexible language. You can verb any noun in it, so without grammatical context you can't really tell what it is anyway. If we want to remove the ambiguity, we should probably rename the method to `foo.listify()`. In fact, I always thought that desctructive method would be verbs (and return None) and methods without side effects would be nouns, as in `L.sort()` versus `L.sorted()` (except that python, having a decided preference for routines with side effects, doesn't have the latter) Note that a common design paradigm in python is "we are all consenting adults here" (an argument I haven't seen brought up against using python for pre-university schooling yet). From that perspective, returning a mutable list (perhaps because it must be mutable internally) that shouldn't be mutated isn't an absolute no-go. -- Ticket URL: <http://trac.sagemath.org/ticket/20743#comment:12> Sage <http://www.sagemath.org> Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, and MATLAB -- You received this message because you are subscribed to the Google Groups "sage-trac" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-trac+unsubscr...@googlegroups.com. To post to this group, send email to sage-trac@googlegroups.com. Visit this group at https://groups.google.com/group/sage-trac. For more options, visit https://groups.google.com/d/optout.