News for hackers. Stuff that matters.
Re:Ask HN: What are your favorite examples of elegant software? by thrtythreeforty on Monday May 02, 2022 @10:04PM (#31243575)
Yep and that's also the source of the footgun:

def foobar(my_list=[]): my_list.append(42)

A cursory glance suggests this function appends a number to an empty list every time it's run. But actually, the default argument is evaluated once when the function is defined, so calling this function repeatedly will continue to append to that same list.

There are no comments on this comment yet.