r/programminghorror • • Dec 08 '25

Does this qualify?

# Licensed under https://unlicense.org/
_flipFlopStateRegistry:dict[str,bool]=dict()
import inspect, time
def flipFlop(flip=True,flop=False):
 try:returnVal=_flipFlopStateRegistry[flipFlopStateRegistry_key]=flip if flop==_flipFlopStateRegistry[flipFlopStateRegistry_key:=(stack:=inspect.stack()[1]).filename+str(stack.lineno)] else flop;return returnVal
 except KeyError:_flipFlopStateRegistry[flipFlopStateRegistry_key]=flip;return flip


import random
def flipFlopRecursive():
 print(flipFlop())
 if random.random()>0.5:print(flipFlop("flip","flop"))
 time.sleep(1)
 flipFlopRecursive()
flipFlopRecursive()
22 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/nickthewildetype Dec 10 '25

oh well I use it all the time and love it!

Not that I think a lot of people enjoy trying to read my code (myself excluded of course)

2

u/Twirrim Dec 10 '25

I would be more than happy to read it in code. I like it as an approach. I use the syntax in other languages that support it, it's just not got into my muscle memory for python :)