Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.




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.


Except wouldn't the ideal in this case be to use default parameters?

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




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: