I'm sorry if this is a ABSOLUTELY sophomoric question, but I'm curious what the best practices are out there, and I can't seem to find a good answer on Google.
In Python, I usually use an empty class as a super-catchall data structure container (sort of like a JSON file), and add attributes along the way:
class DataObj:
"Catch-all data object"
def __init__(self):
pass
def processData(inputs):
data = DataObj()
data.a = 1
data.b = "sym"
data.c = [2,5,2,1]
This gives me a tremendous amount of flexibility, because the container object can essentially store anything. So if new requirements crop up, I'll just add it as another attribute to the DataObj object (which I pass around in my code).
However, recently it has been impressed upon me (by FP programmers) that this is an awful practice, because it makes it very hard to read the code. One has to go through all the code to figure out what attributes DataObj actually has.
Question: How can I rewrite this for greater maintainability without sacrificing flexibility?
Are there any ideas from functional programming that I can adopt?
I'm looking for best-practices out there.
Note: one idea is to pre-initialize the class with all the attributes that one expects to encounter, e.g.
class DataObj:
"Catch-all data object"
def __init__(self):
data.a = 0
data.b = ""
data.c = []
def processData(inputs):
data = DataObj()
data.a = 1
data.b = "sym"
data.c = [2,5,2,1]
Is this actually a good idea? What if I don't know what my attributes are a priori?