I'm trying to sort out how to organize a lot of code that iterates on data stored in python class instances. In most cases, the code reads the instance data and produces some result (a number, a list, etc).
Essentially, I'm just trying to keep everything maintainable and easier to read by creating top-level instance methods that delegate the grunt work to otherwise "dumb" methods that need the instance data, but don't need to modify the instance itself.
Given the read-only nature of these other methods, am I better off declaring them as static methods and passing the needed data as separate parameters, or leaving them all as instance methods?
I prefer the static method approach as a "self" parameter signals that the method modifies instance data, but I don't know if I'm over-using static methods to adopt that approach...
I realize this makes for a broad question that invites opinion-based responses, but I can't find anything information which suggests over-using static methods creates any real hardships / performance issues (or vice-versa). That is, I see suggestions that static methods should be used sparingly, but I don't see any justification for that.
For example, in the code snippet below, assuming the static methods represent significant, but separate, operations on the instance data, is it better to tag them as static methods (which tells me right away they only return a result, not modify the instance or class), or make them all instance-level methods and access the data directly? Is there any real problem this approach creates?
class Test(object):
def __init__(self):
self.var1 = 10
self.var2 = ["my", "list", "of", "strings"]
self.var3 = [1,2,3,4,5]
@staticmethod
def processFloat(inst_float):
pass
@staticmethod
def processList(inst_list):
pass
@staticmethod
def processArray(inst_array):
pass
def doStuff(self):
processFloat(self.var1)
processList(self.var2)
processArray(self.var3)