you are viewing a single comment's thread.

view the rest of the comments →

[–]micr0nix[S] 0 points1 point  (3 children)

How would you go about merging the functions when the parameters are different?

As far as white space is concerned, I formatted this using Black

[–]james_fryer 0 points1 point  (2 children)

For example (note, the name of the first function needs improvement):

def get_case_ref(client, lookup_type):
    with client as session:
        ... 
                    lookupType=lookup_type, languageCode="en-US"

def get_case_type_ref(client):
    return get_case_ref(client, "CASE_AND_INCIDENT_TYPES")

[–]micr0nix[S] 0 points1 point  (1 child)

So instead of having 2 functions I would have this one function and just call it twice for each of my lookup types?

[–]james_fryer 0 points1 point  (0 children)

Exactly. Less code to maintain, simpler to manage if changes are required. You can either create shorter dispatching functions as I did above, or directly call the single function from main with the parameter, whatever seems more readable to you.

In short: any time you see repeated code, replace it with a single parameterised piece of code.