Message 189990 - Python tracker (original) (raw)
Antoine Pitrou added the comment:
-1. Exposing a function allows to modify the underlying implementation without breaking any API.
This doesn't make any sense. Once you've exposed an API that gives out a value for this, you can't change the implementation in a way that doesn't involve handing out a value... in which case you can just as easily set it as an attribute.
So there is actually zero improvement in encapsulation: it's purely a ritualistic wrapping, like Java programmers insisting on having getFoo() methods in Python when an attribute would suffice. If there must be a way to change it later to be dynamic, it can always be exposed as an attribute of an object that could grow a property later, e.g.
from abc import object_graph
if object_graph.version != old_version:
...
Nick Coghlan added the comment:
Trading correctness for speed is almost never a good idea.
How is "correctness" relevant to the question of whether a readable value is exposed as an attribute or a method?