4 ms·
I'd note that `Vector.sort()` is an awkward choice of name for a function that returns a result, rather than mutating the object in-place, given the standard li
by Latty 12y ago
I'd note that `Vector.sort()` is an awkward choice of name for a function that returns a result, rather than mutating the object in-place, given the standard library tends to use infinitive verbs to mean in place functions, while past tense verbs return a new value with the modification applied.
e.g: `list.sort()` is in-place, `sorted(list)` returns a new list.
- shoyer 12y agoTrue, but who really wants the mutating version? Worse, do we really want to make it more obvious/natural to modify in place? I think this is a standard library convention that is best forgotten. In pandas, for example, you need to write inplace=True to use the mutating versions of methods, which hopefully makes mutation awkward enough to discourage it.
- andreasvc 12y agoMore often than not, I want the in-place version. When dealing with a significant amount of data, it's better not to make unnecessary copies. What is your argument for wanting to discourage mutation? Either way, the argument of the parent comment is clear, it's best to follow established naming conventions.
- shoyer 12y agoThis stack overflow discussion summarizes pros of immutability reasonably well: http://stackoverflow.com/questions/1863515/pros-cons-of-immutability-vs-mutability http://stackoverflow.com/questions/1863515/pros-cons-of-immu... The main reason is that mutable objects are more complex and thus harder to reason about (which leads to more bugs).
- ricsca 12y agoAgree. Naming is difficult and here maybe I did a wrong choice. Anyway, pykov.Vector class inherit from dict, which is not ordered, so mutating in place cannot be done. The sort() method returns a list, which makes the name "sort" even more problematic. What do you suggest? (OrderedDict?)
- deleted 12y ago[deleted]