I was recently trying to explain a particular anti-pattern to some novice programmers and found that it was hard to express without an overly-detailed example. I'm sure it has a name and that someone has spent the effort to write a succinct/clear explanation of it, but I have struggled to find it.
The anti-pattern usually starts with a function:
def make_model(input_size, output_size):
"Builds a neural network model from the parameters and returns it."
# ... <initial setup> ...
# Build a 4-layer neural network
model.add_layer(some_conv_layer(input_size))
model.add_layer(some_conv_layer(input_size * 2))
model.add_layer(some_relu_layer(output_size * 2))
model.add_layer(some_sigmoid_layer(output_size))
# ... <etc> ...
return model
Then, at some point while developing the software, we realize that, in fact, the number of layers and the kinds of layers are a parameter of the model, and we should handle that because sometimes we want a different set of layers. So we update hte function:
def make_model(input_size, output_size, model_arch):
"Builds a neural network model from the parameters and returns it."
# ... <initial setup> ...
if model_arch == 'basic':
# Build a 4-layer neural network
model.add_layer(some_conv_layer(input_size))
model.add_layer(some_conv_layer(input_size * 2))
model.add_layer(some_relu_layer(output_size * 2))
model.add_layer(some_sigmoid_layer(output_size))
elif model_arch == '5layer':
# ...
else:
raise Exception("invalid model architecture parameter")
# ... <etc> ...
return model
However, as the code development progresses, this becomes untenable--every possible architecture of the model must reside in this one function, and parameters of the every model architecture need to be made to somehow route through this make_model
function.
Depending on the programming language you're using and the paradigms to which your codebase is adhering, the solutions to this problem vary (in Python it likely involves classes), but I'm interested in the name of the anti-pattern and in documents describing it broadly for novices: how to identify it, strategies for fixing it, consequences of not fixing it.
Thanks in advance.