At the moment I am developing three scientific software projects (computer vision) in parallel in Python and scratching my head about organization, clean code and easy extensible/to maintain code.
One question which I have is whether to keep all three project separate or not? They share similar functions, which I thought to collect in a shared API (with many arguments). Or should keep the projects entirely separated, which means I end up with redundant code which is usually not recommended.
I have a function to stack images. This function is used in all three projects.
def stack_images(img_lst):
# do some stacking of the img_lst with algorithm_max
return stacked_image
Now in one of the projects I need another algorithm for the stacking, let's call it algorithm_min but the rest of the code inside the function will not change. Should I add the algorithm as an argument or should I write three stack_images functions, one for each project, which can be easily adapted to the needs of each project?
My fears for the first option, it is very likely that I have to make small changes now and then which means in one year I might end up with many arguments.
My fears for the second option, if I change something fundamental in my function which concern all three projects, I have to change the code on three places (which I am sure soon or later I will forget to do it for the other projects.)
Second example, I have to switch the color spaces of my images all the time. This is one line of code in opencv:
# RGB to HSV
hsv_image = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
# RGB to LAB
lab_image = cv2.cvtColor(img, cv2.COLOR_RGB2LAB)
Now, should I write one function with the color space as an argument or for each color space a separate function? Should I unit test such basic functions (isn't it exaggerated?)