Skip to main content
Post Reopened by Bart van Ingen Schenau, Greg Burghardt, Glorfindel
deleted 562 characters in body; edited title
Added to review
Source Link

pattern for reducing dependencies and decoupling Designing functions with separation of concern in mind

Full disclosure: I'm happy to ask for vocabulary around well known patterns to the extent that the vocabulary has fidelity to the code below; otherwise, I'm more asking about the logic behind why or why not the application structure shown below would be effective (say, relative to an application with tighter coupling).

For the sake of this question, assume it is a given that the application is not object oriented (for whatever reason). It seems to me that the code that follows is a rigid way to eliminate "extra" dependencies from functions.

My question: isIs there a name related to the "pattern"pattern shown in the code that follows, or? Or is there writing/thinking on this "pattern"the [design of] code shown that showssuggests it is indeed not worthy of pattern status (say, is an anti-pattern)? Said a different wayIn general, I'm curious if this is there writing or vocabulary that goes with thesomehow a well known design shown in the code belowstrategy for non object oriented applications (and, more importantly, why or why not).

I suppose I'll use Python but this isn't a Python question, it's ais just an application design question.

pattern for reducing dependencies and decoupling

Full disclosure: I'm happy to ask for vocabulary around well known patterns to the extent that the vocabulary has fidelity to the code below; otherwise, I'm more asking about the logic behind why or why not the application structure shown below would be effective (say, relative to an application with tighter coupling).

For the sake of this question, assume it is a given that the application is not object oriented (for whatever reason). It seems to me that the code that follows is a rigid way to eliminate "extra" dependencies from functions.

My question: is there a name related to the "pattern" shown in the code that follows, or is there writing/thinking on this "pattern" that shows it is indeed not worthy of pattern status (say, is an anti-pattern)? Said a different way, is there writing or vocabulary that goes with the design shown in the code below.

I suppose I'll use Python but this isn't a Python question, it's a design question.

Designing functions with separation of concern in mind

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.

Post Closed as "Needs details or clarity" by Martin Maat, BobDalgleish, gnat
syntax highlighting
Source Link
Greg Burghardt
  • 46.1k
  • 8
  • 87
  • 150
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)
# ...
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)
# ...
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)
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)
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)
# ...
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)
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)
# ...
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)
added 324 characters in body
Source Link

Full disclosure: I'm happy to ask for vocabulary around well known patterns to the extent that the vocabulary has fidelity to the code below; otherwise, I'm more asking about the logic behind why or why not the application structure shown below would be effective (say, relative to an application with tighter coupling).

For the sake of this question, assume it is a given that the application is not object oriented (for whatever reason). It seems to me that the code that follows is a rigid way to eliminate "extra" dependencies from functions.

My question: is there a name related to the "pattern" shown in the code that follows, or is there writing/thinking on this "pattern" that shows it is indeed not worthy of pattern status (say, is an anti-pattern)? Said a different way, is there writing or vocabulary that goes with the design shown in the code below.

I suppose I'll use Python but this isn't a Python question, it's a 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:

  1. Calculate on those inputs
  2. Communicate with services/libraries that came from outside of the application
  3. 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.

For the sake of this question, assume it is a given that the application is not object oriented (for whatever reason). It seems to me that the code that follows is a rigid way to eliminate "extra" dependencies from functions.

My question: is there a name related to the "pattern" shown in the code that follows, or is there writing/thinking on this "pattern" that shows it is indeed not worthy of pattern status (say, is an anti-pattern)? Said a different way, is there writing or vocabulary that goes with the design shown in the code below.

I suppose I'll use Python but this isn't a Python question, it's a 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:

  1. Calculate on those inputs
  2. Communicate with services/libraries that came from outside of the application
  3. 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.

Full disclosure: I'm happy to ask for vocabulary around well known patterns to the extent that the vocabulary has fidelity to the code below; otherwise, I'm more asking about the logic behind why or why not the application structure shown below would be effective (say, relative to an application with tighter coupling).

For the sake of this question, assume it is a given that the application is not object oriented (for whatever reason). It seems to me that the code that follows is a rigid way to eliminate "extra" dependencies from functions.

My question: is there a name related to the "pattern" shown in the code that follows, or is there writing/thinking on this "pattern" that shows it is indeed not worthy of pattern status (say, is an anti-pattern)? Said a different way, is there writing or vocabulary that goes with the design shown in the code below.

I suppose I'll use Python but this isn't a Python question, it's a 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:

  1. Calculate on those inputs
  2. Communicate with services/libraries that came from outside of the application
  3. 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.

Source Link
Loading