News for hackers. Stuff that matters.
Re:Google Python Style Guide by rightbyte on Saturday February 11, 2023 @05:55AM (#34751207)
You don't suggest any solution. Do you want more function overloading or maybe config objects?

Adding default parameters works well with existing code. It is not bad and lazy because it is easy.

Re:Google Python Style Guide by gorgoiler on Saturday February 11, 2023 @07:02AM (#34751602)
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.
Re:Google Python Style Guide by Xelynega on Saturday February 11, 2023 @10:20AM (#34753083)
Except wouldn't the ideal in this case be to use default parameters?

def site(message, port=print): port(greet(message))