4 ms·
Imagine two different call sites want to do two different things with the message. One wants to log() it, another wants to print() it. In my example this has
by gorgoiler 4y ago
Imagine two different call sites want to do two different things with the message. One wants to log() it, another wants to print() it. In my example this has been implemented by passing a flag to greet() to tell it what to do.
If greet() gave up responsibility for outputting the message and instead just constructed it, then your code would look like this:
def site1():
print(greet(“x”))
def site2():
log(greet(“y”))
And greet would be half as long.
- Xelynega 4y agoExcept wouldn't the ideal in this case be to use default parameters? def site(message, port=print): port(greet(message))