Eric Peng exploring

Cognitive Behavioral Therapy For Hackers

What is Cognitive Behavioral Therapy?

Cognitive behavioral therapy’s (CBT) basic premise is that dysfunctional thinking is the root of all psychological issues. Just like buggy or suboptimal code may produce poor output or performance, our brains’ code may produce poor behavior or unhelpful feelings. CBT offers techniques to refactor our brain’s code to create better output and performance.

Technical Debt

Our brain’s code can become suboptimal because of technical debt. Technical debt arises when we use code that’s easy to implement in the short run but isn’t an optimal or scalable solution. Every minute that suboptimal code runs, interest is accrued.

Our brain’s suboptimal code takes two forms. First, there’s the reptilian (brain stem and cerebellum) and monkey (limbic system) parts of our brain that served us well in our evolutionary past but are no longer optimized for our modern day-to-day lives. Second, our brains developed neural circuitry during our childhood that may not be serving us effectively in our adult lives. These suboptimal code are our brain’s form of technical debt.

We often delay paying off technical debt because the perceived payoff price is high. What we may not realize is that every day that passes increases the payoff price because of the debt’s rising compound interest. It often takes a catastrophic event to occur (e.g. servers go down) before we begin to take refactoring seriously. And we end up paying a significantly higher price to pay off the debt than if we had done it earlier.

The best response to technical debt is to pay it off–by refactoring suboptimal code–before it halts your system. Fortunately, CBT provides a framework for refactoring our brain’s suboptimal code so that we can pay off our brain’s technical debt.

Cognitive Model

Before we can discuss refactoring our brain’s code, we need to understand how the brain works. Here’s CBT’s cognitive model:

Situation => Beliefs => Thoughts => Emotions => Behavior

Our beliefs–our brain’s precompiled code–produce thoughts based on the situation. This process occurs so quickly that we tend not to consciously realize the automatic thoughts that are going through our minds. That’s useful because conscious processing consumes working memory, which is resource intensive and limited in capacity. We usually want to save those resources for novel high priority problems–aka new features.

But when our beliefs produce undesired emotions and behavior, we’re paying interest on our brain’s technical debt. These beliefs may no longer be useful or valid–and may need to be refactored.

The Refactoring Cycle

A unique challenge for humans is that we tend to hold tightly to our beliefs. We feel that they form a part of our identity and the idea of refactoring them can feel like we’re losing a part of ourselves. More importantly, it can be risky to refactor our beliefs: what if refactoring produces even worse results?

We can set up an iterative refactoring cycle to manage this risk.

1. Collect data
2. Refactor code
3. Run unit tests
4. Analyze results

Let’s walk through each step of the refactoring cycle.

Collect Data

Just like we log data and metrics in a production environment to capture what’s happening behind the scenes, we want to collect data from our minds. Without data, it can be challenging to know what code to refactor and whether refactoring is effective.

A common CBT data collection technique is called the Thought Record. I’ve created a CBT Thought Record template on Google Spreadsheets that you can copy for your own use. The data collection step focuses on filling out the first five Thought Record columns. Simply put, we’re answering the question, “what was just going on through my mind?”

If we’re serious about paying off our brain’s technical debt, we’ll want to set up a routine for filling out the Thought Record. I do this by setting up a daily Gmail reminder and bookmark my Thought Record spreadsheet so that whenever I notice a thought or feeling that seems strange or unhelpful, I immediately jot it down before I forget it.

Refactor Code

Once we have our data, we can start refactoring. We can do this by filling out the last four columns of the Thought Record.

The goal is to objectively examine the facts of the situation to come up with a new more realistic and balanced viewpoint. We then measure the new intensity level of the emotion to see how it compares to the initial intensity level.

The Thought Record is just one refactoring technique that focuses on modifying thoughts and emotions–the tip of the code iceberg. Once we’ve mastered the Thought Record, we can move under the surface to identifying and modifying beliefs.

The Cognitive Conceptualization Diagram can be used to translate the Thought Record data into underlying beliefs. Then, the Core Belief Worksheet can be used to modify negative beliefs into new realistic and balanced beliefs.

This process of refactoring our brain is known in psychology as cognitive restructuring. Just as there are common software design patterns, there are standard cognitive restructuring patterns for the most common cognitive distortions.

Run Unit Tests

Once we’ve refactored our beliefs, thoughts, and emotions, we’ll want to test whether the changes were effective and look out for undesired bugs.

A simple unit test is to continue to leverage the Thought Record. Examine similar situations after the refactoring to see if the frequency and intensity level of emotions and negative thoughts have decreased.

Another unit test is to pay attention to feedback from close friends and family. Since they can’t see into your beliefs and thoughts, do they notice differences in your emotions and behavior? If so, do those changes appear positive or negative to them?

Analyze Results

We then ask ourselves what worked and what didn’t? Based on the unit tests, how effective was our refactoring? What can we do to optimize the refactoring cycle for our unique preferences?

We can then restart the refactoring cycle by going back to collecting data.

Continuous Improvement

“By continuously improving the design of code, we make it easier and easier to work with. This is in sharp contrast to what typically happens: little refactoring and a great deal of attention paid to expediently adding new features. If you get into the hygienic habit of refactoring continuously, you’ll find that it is easier to extend and maintain code.”
– Joshua Kerievsky, Refactoring to Patterns

We can adopt Kerievsky’s idea for our brains:

By continuously improving the design of our beliefs, thoughts, and emotions, we make them easier and easier to work with. This is in sharp contrast to what typically happens: little self-examination and self-awareness. If you get into the hygienic habit of refactoring continuously, you’ll find it easier to respond to challenging situations with optimal behavior.

Eric Peng exploring

Eric Peng

husband & father
executive coach
4x founder

Follow Me