by lencastre · 2y ago · 0 comments
_If a function is called from multiple places, see if it is possible to arrange for the work to be done in a single place, perhaps with flags, and inline that._
Thanks,
def processOrder():
# Some common processing logic
print("Processing the order...")
def placeOnlineOrder():
processOrder()
print("Sending confirmation email...")
def placeInStoreOrder():
processOrder()
print("Printing receipt...")
# Calls from different locations
placeOnlineOrder()
placeInStoreOrder()
Could become: def processOrder(order_type):
# Common processing logic
print("Processing the order...")
if order_type == "online":
print("Sending confirmation email...")
elif order_type == "in_store":
print("Printing receipt...")
# Unified calls with different flags
processOrder("online")
processOrder("in_store")