Thursday, April 26, 2018

How To Trap a Code Monkey

Have you ever been coding and have run up into a problem and gotten stuck. You keep looking for quick fixes to your problem but to no avail. You start getting frustrated. There must be a quick fix along the path that you are on. You keep  moving forward. You just want to finish this last bit of code but its just not working right. That little change ends up taking a lot longer than you had expected and you end up not getting further. Its starting to get late so you are forced to take a break. You go home and have dinner. Then you take a shower. In the shower you have time to ponder it and retrace your steps methodically. You hit an aha moment and go back to your code, this time taking a different path. It works.

That's an example of a "South Indian monkey trap" described in one of my favorite books: Zen and the Art of Motorcycle Maintenance. There is quite a simple trap to catch a monkey. You put some seeds into a hole just big enough for the monkey to fit their hand into. The monkey will put their hand into the hold to grab the seeds. But when they do, their hand becomes too big to be able to pull out of the hole. It demonstrates the concept of "value rigidity" as the monkey is not able to consider giving up what he has already obtained. I forget if the monkey finally gives up the seeds or if it will die their (I would guess it would eventually calm down and let go).

This was the same as our coding trap. We had a solution in mind and when we got stuck. Maybe we tried to move sideways a bit. The correct thing to do is to take a step back and examine the problem but we are so far along the path. The effort to give up what we have and go back seems like too monumental of a task. So we look to go forward down the wrong path, looking for a quick win and we don't find it. In order to solve the problem we have to let go of the seeds. In my example the taking a break and shower lead me to let go and take that step back.

Taking a break is the remedy for when you are stuck. You need to distance yourself from the problem. Completely let go before you can approach it. Otherwise you might still be attached to your current path. You might still have the seeds in your hands.

Don't laugh at the short sightedness of the monkey. In different ways we may ourselves be stuck in  "South Indian monkey traps" and not know it. The monkey trap analogy doesn't just apply to coding. Often times in life we have this value rigidity where we are unable to evaluate our current circumstances due to your previous beliefs. Perhaps we are holding on to a bad career or bad relationship because of mental barriers we have set in place. We won't let ourselves get out of it because we don't want to be perceived in a certain way. Maybe we don't believe we will find something better or maybe we want to hold onto a perception that we haven't "failed" yet.

Pay attention to any stuckness you run into in life. Might you be stuck because you are still holding on to a fistful of seeds?