Kacarott@aussie.zone to Programmer Humor@lemmy.ml · 8 hours agoWhat the F#whatthefsharp.comexternal-linkmessage-square22fedilinkarrow-up169arrow-down11file-text
arrow-up168arrow-down1external-linkWhat the F#whatthefsharp.comKacarott@aussie.zone to Programmer Humor@lemmy.ml · 8 hours agomessage-square22fedilinkfile-text
minus-squareexpr@programming.devlinkfedilinkarrow-up5·4 hours agoMutating function arguments is pretty wtf to begin with.
minus-squareFourPacketsOfPeanuts@lemmy.worldlinkfedilinkarrow-up2·edit-239 minutes agotrue, and i can’t think of a legitimate case where it would have tripped me up. but if someone, a novice perhaps, wrote def some_func(foo, bar=[1, 2, 3]): bar.reverse() # for whatever reason print(bar) some_func('hello') # output [3,2,1] some_func('hello') # output [1,2,3] i think they would be within their rights to be surprised that calling this function twice has different results. that’s what i was surprised by; it feels like bar would be re initialised each time with a scope of the function but apparenty not
Mutating function arguments is pretty wtf to begin with.
true, and i can’t think of a legitimate case where it would have tripped me up. but if someone, a novice perhaps, wrote
def some_func(foo, bar=[1, 2, 3]): bar.reverse() # for whatever reason print(bar) some_func('hello') # output [3,2,1] some_func('hello') # output [1,2,3]
i think they would be within their rights to be surprised that calling this function twice has different results. that’s what i was surprised by; it feels like bar would be re initialised each time with a scope of the function but apparenty not