3 ms·
in-place operations give me the heebie-jeebies. I think this is something that is a slightly less obvious when dealing with classes. I see stuff like this in a
by jszymborski 7y ago
in-place operations give me the heebie-jeebies.
I think this is something that is a slightly less obvious when dealing with classes. I see stuff like this in academic code all the time:
class SomeDataObj:
def __init__(self, data):
self.data = data
def normalize(self):
self.data = normalize(self.data)
I'd much prefer for there to be variable `self.data_normalized` which is initialized to None or even better a getter `getNormalizedData()` that computes/caches a normalized variable.
- UncleEntity 7y agoThe pythonic way would be to have sort() and sorted() which either sort in place or return a sorted copy. Best of both worlds.
- ajuc 7y agoCommand Query Separation is a very good general idea in programming that should be followed more often. Sadly it went out of fashion in 90s when everybody got hyped about OOP.