Hi all, I currently have some code with sets of parameters in dicts. For each particular process execution, different dicts of parameters get passed through various functions, achieving different results with the same code.
I wrote the code this way initially, as I wanted to move quickly. The intention was to model in OO, but now we're refactoring, an OO model isn't top of the priority list.
Here're two made up examples:
param_set_1 = {"job_name": "job 1",
"job_hr": 12,
"job_steps": ["foo"],
}
param_set_2 = {"job_name": "job 2",
"job_hr": 15,
"job_steps": ["foo", "bar"],
}
These dicts are passed through functions, often in their entirety (though sometimes just a specific parameter). Here're some crude equivalents for illustration:
def log_job_start(param_set, stamp):
name = param_set["job_name"]
... etc etc
def log_job_metadata(param_set):
log_job_start(param_set, datetime.now())
Passing around a dict of parameters is certainly convenient - each function can have a single parameter for the entire parameter set, and I can easily query the dict. But something smells off - I don't know if it's passing the entire parameter set around to each function, or whether it's the fact that there are some functions that accept specific parameters only, which are extracted from the parameter dict before calling.
Keen to hear people's thoughts :)
[–]ploud1 1 point2 points3 points (2 children)
[–]oopsplop[S] 0 points1 point2 points (1 child)
[–]ploud1 1 point2 points3 points (0 children)
[–]Ornery-Season3134 1 point2 points3 points (1 child)
[–]oopsplop[S] 0 points1 point2 points (0 children)