I have written some code that uses attributes of an object:
class Foo:
def __init__(self):
self.bar = "baz"
myFoo = Foo()
print (myFoo.bar)
Now I want to do some fancy calculation to return bar. I could use @property to make methods act as the attribute bar, or I could refactor my code to use myFoo.bar().
Should I go back and add parens to all my bar accesses or use @property? Assume my code base is small now but due to entropy it will increase.
If it’s logically a property/attribute of the object, I’d say keep it as a property. If it’s likely to become parametrised, by which I mean you may want to invoke
myFoo.bar(someArgs)then bite the bullet now and make it a method.Under most circumstances, performance is unlikely to be an issue.