Is there a name related to the pattern shown in the code that follows? Or is there writing/thinking on the [design of] code shown that suggests it is an anti-pattern? In general, I'm curious if this is somehow a well known design strategy for non object oriented applications (and, more importantly, why or why not).
I suppose I'll use Python but this is just an application design question.
main.py
from some_other_file import func_get_data_from_an_api, func_calculate_something, #...
from ...
data1 = None
data2 = None
data3 = None
data4 = None
data5 = None
# ...
data1, data2 = func_get_data_from_an_api()
data3 = func_calculate_something(data1)
func_write_to_database(data3)
data4 = func_calculate_again(data3)
data5 = func_d(data2, data4)
func_write_to_database(data5)
# ...
Then, every other file would just have the implementations of the functions from main.py. So here is the general case for one such implementation:
def general_case_func(param1_from_main, param2_from_main):
# Under this "pattern", a function in this application can never
# call another function from this application (but functions in this application
# can call things like functions from 3rd party software, functions from the
# library of the language being used, functions from external systems and so on).
# Note: This ☝️ is a central requirement for the "pattern" I'm asking about.
m = 3
if param1_from_main < 1500:
m = param1_from_main % param2_from_main
return max(m, 5)
Never mind the logic in this function (there isn't any intentional meaning in the calculation). The point is that the rules are that functions can only take inputs passed from main and do some combination of the following:
- Calculate on those inputs
- Communicate with services/libraries that came from outside of the application
- Return a value or values to main
So if the application happened to have 500 functions (each with about 4 or so lines of code in them, perhaps importantly for the sake of "clean" functions that only do one thing), then there would be exactly 500 function calls in main.py.
Unless of course considering such things is an essential part of the answer, never mind loops and if statements in main.py. By that I mean, never mind if main.py has if statements that possibly cause some of the functions to not run during some executions, or whether some of the functions in main.py are in a loop.