Manage several procedures

By | June 14, 2018

I have a software project which grows rapidly in an unexpected way, many customers request similar tasks but with slightly different needs and parameters. I start to dislike my current code structure and I have two ideas in mind how to improve my code:

I have a shared library with shared functions in it. This library is imported in each procedure file. One procedure file for each task, the tasks overlap a lot (90 %) but this could change in the future as people change their ideas and requests all the time (scientific project).

Idea A) I have a configuration file with all settings and parameters which can be changed depending on the procedure. In a single procedure file, I use the extracted parameters of the configuration file to set up the system. Example:

import shared_lib
# Get all the parameters and procedure from my configuration file

# This step is the same for each procedure
shared_lib.function1()

# This step depends which procedure we use
if procedure1:
    shared_lib.function2()
elif procedure2:
    shared_lib.function3()

# For this step we need to set a parameter depending on which procedure we use
if procedure1:
    shared_lib.function4(x = 10)
elif procedure2:
    shared_lib.function4(x = 20)

# This step is the same for each procedure
shared_lib.function5()

This works for two procedures but I fear the file will get messy with increasing number of procedure, which I expect in the future. In addition it is very annoying to change the settings in the configuration file every time I change the procedure.

Idea B) Create one file for each procedure and include all the setting and procedure code inside the file. Example:

### File procedure1

import shared_lib

# Set parameters
x = 10

# Start procedure
shared_lib.function1()
shared_lib.function2()
shared_lib.function4(x)
shared_lib.function5()

Example

### File procedure2
import shared_lib

# Set parameters
x = 20

# Start procedure
shared_lib.function1()
shared_lib.function3()
shared_lib.function4(x)
shared_lib.function5()

What I dislike with idea B, is that I will end up with many procedure file (plus many files of the shared code) with a large part of overlapping code.

Can I do better? I am not very convinced with both ideas...