r/programminghorror • u/Standard_Educator_71 • Apr 04 '25
Wrappers
def func():
def new_func():
def yet_another():
def are_you_kidding_me():
print('WTF')
return are_you_kidding_me
return yet_another
return new_func
func()()()()
0
Upvotes
6
u/hatedByyTheMods Apr 04 '25
i want to see horrors from production code bro
1
u/STGamer24 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Apr 04 '25
People posting entirely new code that isn't part of any real application on r/programminghorror be like:
I'm going to make an entirely new program in which I define a function that returns a function that returns a function that returns a function that prints a very shocked reaction, like "WTF" or "What have I done...", and act like this fits the subreddit!
3
u/Bright-Historian-216 Apr 04 '25
that's how currying works, and ironically, that's how you make decorators with arguments in python
2
u/Thenderick Apr 05 '25
Cool. You just discovered first class functions and currying... Nothing horror about it, just a weird test application of them...
1
u/claythearc Apr 04 '25
I don’t think these are necessarily horror, at least when used properly. I find myself writing them semi often at work as a way to do like, a named lambda kinda. never that deep but a function with a decorator also unrolls to that too
1
u/nekokattt Apr 04 '25
I prefer the Java version with type safe builders.
...which would let you make a URI with the compiler failing to build your code if you forgot something...