# Creating one function for multiple purposes vs multiple functions for one purpose each [closed]

I have one function that is used to compute distances of an object in 3 different ways.

Is one of the following two methods considered better practice:

1. Creating 3 different functions, one each for calculating a type of distance

2. Creating one single function with multiple if-else statements?

I am using python, and have observed a number of libraries using a 'mode' parameter in order to allow for similar kinds of functionality but with different calculations, for example the convolution function in scipy: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve2d.html. Here, the operation being done is always convolution, but the mode determines the type of convolution.

## closed as too broad by Doc Brown, gnat, David Arno, Robert Harvey♦Apr 30 at 15:31

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• How are you calculating the distances differently? What makes you choose one of the ways over another? – Greg Burghardt Apr 30 at 1:55
• I am sure variants of this question have been asked a hundred times on this site - just can't find a real duplicate immediately. However, I don't think this is a good question, because these kind of things should be discussed in terms of examples. So my recommendation: post the source code of the function in stake on codereview.stackexchange, then you will get way better answers. – Doc Brown Apr 30 at 5:36
• @DocBrown Thank you! – rahs Apr 30 at 13:51
• @GregBurghardt In one type of distance, the coordinates of the destination do not need to be passed, while in both the other types, they do need to be. As a result, the function signature is different for both kinds. – rahs Apr 30 at 13:56