What The F#
whatthefsharp.com
external-link
A Collection of Surprising Behavior by Programming Language

A small collection of WTF code snippets sorted by language.

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

Create a post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
  • 1 user online
  • 168 users / day
  • 347 users / week
  • 615 users / month
  • 2.35K users / 6 months
  • 1 subscriber
  • 1.64K Posts
  • 36.4K Comments
  • Modlog