Should methods inside a class use property/setter accessors, a la "add_to_field" or should they access the private variables directly a la "subtract from field"?
class Example(object):
def __init__(self, field):
self._field = field
@property
def field(self):
return self._field
@field.setter
def field(self, field):
self._field = field
def add_to_field(self, something):
self.field += something
def subtract_from_field(self, something):
self._field += something
How about if the setter didn't purely set the variable, but performed something else, such as logging. Is this bad style?
@field.setter
def field(self, field):
log.logger.debug("Field set to %r", field)
self._field = field
Currently my code is a mixture of both. Not sure what direction to refactor in.