On 2017-05-14 00:34, Chris Angelico wrote:
On Sun, May 14, 2017 at 2:53 PM, Brendan Barnwell email@example.com wrote:
Attributes aren't just for passing things to other methods. They're
for storing state. In your proposed system, how would an object mutate one of its own attributes? It looks like "x" here is just stored in a function closure, which wouldn't allow easy mutation. Also, how would another object access the attribute from outside (as we currently do with self.x)? You can say we'd only use this new attribute-free approach when we want to pass a constructor argument that's used but never mutated or accessed from outside, but that severely restricts the potential use cases, and all it saves you is typing "self".
My expectation is that you'd be using "nonlocal x" to do that.
That would allow mutation from within methods, but (as far as I can tell) not access (or mutation) from outside the class.