Q1: Coming from an OO background (Java, Ruby, Smalltalk), what would be the preferred way of naming accessor and mutator methods when writing classes in Python? For example if I have:
class Account :
def __init__(self, owner) :
self.__owner = owner
self.__amount = 0
def owner(self) :
return self.__owner
Should I call my accessor methods after the name of the attribute like owner()
to access the private attribute __owner
as is custom in languages like Smalltalk and Ruby, or rather call it get_owner
which would be the snake-case equivalent of how you would call an accessor in Java. I assume the Java way would be prefered?
Q2: Similar question for mutator methods: should I call them set_owner
à la Java or rather something else?
Q3: Final question: if my attributes are public, as in:
class Account :
def __init__(self, owner) :
self.owner = owner
self.amount = 0
Should I even bother to write accessor and mutator methods for them then, since I can access and assign these attributes from outside the class anyway?