Four Techniques to Wrap Your Head Around Complicated Code

[article]
Summary:

Software people love challenges and want to exercise their brains by tackling difficult problems. Our nature is to understand complicated problems, become familiar with various business domains, and generate a solution that helps the world become a better place. Nirav Assar explains four techniques to wrap your head around complicated code.

Software people love challenges and want to exercise their brains by tackling difficult problems. Our nature is to understand complicated problems, become familiar with various business domains, and generate a solution that helps the world become a better place.

During our journey, we may have to look at complicated code (or “ spaghetti code ”). If we don't understand the dilemma or code, we risk solving the wrong problem and wasting time and money. This article offers some techniques I have used in the past to muddle through complicated problems and wrap my head around complicated code.

We Are Intelligent
Most of us in software are intelligent. When trying to understand a complicated problem, intuition kicks in and we work our way to a solution in a free-flowing fashion. An example of this is just browsing through code and clicking around an application until we understand what is occurring. By doing this, we are forming a picture in our heads of how a system is working. After a while, we  “get” it. This is our natural ability at work, and we may find it hard to explain how we arrived at our destination.

However, this technique is not scalable as the problem complexity increases. Relying on intuition has limits. Sometimes, you can look at code all day in bits and pieces and still never get a clear picture. This can be not only unsuccessful but also wasteful. We need a more disciplined, efficient, and effective approach.

Below are four useful techniques. They start with lightweight and intuitive and gradually trend towards more heavy and formal. Each approach has its own context, and you should use it where it is most effective.

1. Use Your Intuition
The best approach is to trust your intuition. This technique simply requires looking at the code and browsing until you figure it out. Don't jot down any notes. Just wrap your head around the issue. It is basically the “dig around and find out what’s going on” approach.

In my experience, this is the most common way that developers try to solve problems. It is beneficial for straightforward, simple issues. The domain of the problem should be understandable, the code should be readable, and the time taken with this approach should be minimal. The “intuition” approach is good because it is hands free, requires no discipline, and is the quickest in some situations. The drawback is that sometimes it doesn’t scale or just doesn’t work.

It is important to time box how long you work in this manner. Since using “intuition only” is the fastest and simplest method, it often is the correct first choice. However, if progress stops, you should use alternate methods. A common mistake for programmers is to spend too much time using this method before transitioning to a more formal method.

2. Document the Known, the Unknown, and Formulated Questions
When looking at a lot of complex code, your brain tends to jumble knowledge. Research has shown that brain comprehension decreases when processing more than three things at a time. Most people can only retain seven things in working memory at a time. How do we get past this limitation? Document your knowledge.

Taking notes is effective when trying to understand a complex domain, which could be code or even a sophisticated business process. While you are perusing code, jot down your ideas in a free-flowing manner. If you are listening to a business person explain a process, jot down the process in a free-flowing manner.

Now, here is where the novel idea comes in. After you have logged notes, take

About the author

AgileConnection is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, TechWell.com is the place to go for what is happening in software development and delivery.  Join the conversation now!