Aren’t you tired of flattening your code to avoid repeated computation:
I too once thought as you did.
It began with wanting to run a program every time a keyboard was plugged in. "That should be simple," I thought. "I'll just write a udev rule." And so it began.