I have been learning about @property decorators that replace getters and setters. A lot of people seems to prefer using @property over getters and setters.
Regardless of which is desirable, are they even needed most of the times? I feel that it is unnecessary or overkill to have @property for all internal variables especially when the variables are as simple as below. Shouldn't simple things be left simple if they work?
class Ex():
    def __init__(self, value):
        self.__x = value
    @property
    def x(self):
        return self.__x
    @x.setter
    def x(self, value):
        self.__x = value
I also don't think @property provides extra security (if at all needed) as people with intention can still access the variable. (._Ex__x)
Why should I use @property (when validation and future changes are not expected) and when should I not use them?
PEP 8, Style Guide for Python Code says:
For simple public data attributes, it is best to expose just the attribute name, without complicated accessor/mutator methods.
A property with no additional logic, as you've shown, provides no advantages over using a simple attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With