↳
In-reply-to
»
I trip over this in our code at work all the time.
⤋ Read More
@movq@www.uninformativ.de The nice thing about properties is that you can compute and cache things on the fly at first attempt and also ensure validation for writing. But like you said, since it’s not obvious that reading or writing might do some more things, it’s strongly advised to avoid doing expensive stuff disguised as properties.
I reckon the vast majority of property use cases is to provide read-only access. At least that was my impression when I was doing a lot more in Python.
Personally, I think that this just reads a lot nicer:
oink.my_property
oink.my_property = 42
Than:
oink.get_my_property()
oink.set_my_property(42)
Btw, any field access is implemented using method calls. I might be wrong, but I believe there’s always __getattr__ and __setattr__ involved. 8-)