Let's say I want to have a function to load a project's data from both a json and a file path, the first idea which comes to my mind would be having a couple of functions such as:
def load_project_from_json(json_data):
...
def load_project_from_path(path):
with open(path) as f:
load_project_from_json(f.read())
but then I was asking myself if maybe would be more convenient to achieve both tasks with just a single function, for instance:
def load_project(path_or_json)
Many interrogants come to my mind, for instance:
how do you know when it's convenient to explode a function into multiple ones or not?
how can i judge whether a function is a "good" function or not?
is it the function following SRP?
Question: Which systematic method (set of steps or rules) could help me out to extract all responsabilities from any function? The main reason is learning how to judge the quality of any function (no matter if we're talking about free functions or class methods). That way I'll be able to say whether it's necessary or not to refactor it.
NS: When I say systematic method think in terms of simplifying equations, if you follow a set of rules you'll be able to reach a point where the equation can't be simplified further, similarly I'd like to know which rules I could apply to know when a function can't be refactored any further. I hope the analogy makes sense