I have different equations to compute the same quantity. For example, `val = my_func(a, b, c)`

but also `val = my_func(x, y)`

, where `my_func`

represents the quantity I would like to compute: it could be Velocity or Momentum or something completely different. I have dozens of quantities to code, each with multiple equations.

It is also essential that I provide a decent documentation for the different input arguments.

EDIT: I believe the end users of the code will be smart enough to use some kind of advanced editor with autocompletion and capable of displaying docstrings.

So far, I have thought about three basic approaches.

**Approach #1: I can write one function for each equation.**

**Pros:** easy to write.

**Cons:** From a developer standpoint it may be difficult to maintain the code as it grows. From a user standpoint it becomes “cumbersome”, in the sense that the user is forced to look at the correct function that accepts its arguments.

`def my_func_1(a, b, c): """ Compute my_func. Parameters ---------- a : float blablabla b : float blablabla c : float blablabla """ return a + b + c def my_func_2(x, y): """ Compute my_func. Parameters ---------- x : float blablabla y : float blablabla """ return x * y `

**Approach #2: I can write one function accepting keywords arguments and manage all the different cases!**

**Pros:** Easy to use from a user standpoint (the user only need to read the documentation of one function and insert the correct parameters).

**Cons:** From a developer standpoint (in my opinion) it requires a little bit more attention to what you are coding. From a user standpoint, it becomes a little bit harder to use as he/she is forced to use the keyword approach, for example: `my_func(x=my_x_val, y=my_y_val)`

.

`def my_func(**args): """ Compute my_func. Formulas: (1) val = my_func(a, b, c) (2) val = my_func(x, y) Please, provide input parameters accordingly to the equation you desire to solve. Parameters ---------- a : float blablabla b : float blablabla c : float blablabla x : float blablabla y : float blablabla """ if all(k in args for k in ["a", "b", "c"]): a, b, c = args["a"], args["b"], args["c"] return a + b + c if all(k in args for k in ["x", "y"]): x, y = args["x"], args["y"] return x * y raise ValueError("The given arguments can't be used to compute the " + "my_func. Please, read the function docs.") `

**Approach #3: I can write one function accepting a index argument associated to the equation the user would like to solve. This function return the correct equation (function) and the user insert the different arguments.**

**Pros:** Easy to use from a user standpoint as there is no need for keywords arguments! For example, `my_val = my_func(2)(my_x_val, my_y_val)`

.

**Cons:** From a user standpoint it would be a good idea to also have a copy of the arguments description in the parent function docstring, but this would insert a lot of repetition in the comments, hence increase difficulty in maintaining the code.

`def my_func(idx): """ Compute my_func. Formulas: (1) val = my_func(1)(a, b, c) (2) val = my_func(2)(x, y) Please, insert the index of the formulas you would like to solve. """ if idx == 1: def func(a, b, c): """ Parameters ---------- a : float blablabla b : float blablabla c : float blablabla """ return a + b + c return func if idx == 2: def func(x, y): """ Parameters ---------- x : float blablabla y : float blablabla """ return x * y return func raise ValueError("The given index can't be used to compute the " + "my_func. Please, read the function docs.") `

As of now, I would be inclined to use approach #2.

Is there any better paradigm for this problem? Do you happen to know some code that faced this problem?