Confusion is part of programming. When you learn a new programming language, concept, or framework, the new ideas might scare you. When reading unfamiliar code or code that you wrote a long time ago, you might not understand what the code does or why it was written the way it was. When you start to work in a new business domain, new terms and jargon can all bump into each other in your brain.

It's not a problem to be confused for a while, but you don't want to be confused for longer than needed. In this note, we discuss how to recognize and decode your confusion. It is possible that you've never thought about this, but there are different ways to be confused. Not knowing the meaning of a domain concept is a different source of confusion than trying to read a complicated algorithm step by step.

Different types of confusion relate to the different cognitive processes. Using various code examples, this note will detail three types of confusion and explain what happens in your mind.

By the end of this note, you will be able to recognize the different ways that code might cause confusion and understand the cognitive process happening in your brain in each case. Once you know about the three different types of confusion, and the three related cognitive processes, you can consider how you can improve these cognitive processes.

The Types of Confusion in Code

All unfamiliar code is confusing to a certain extent, but not all code is confusing in the same way. Let's illustrate that with three different code examples. All three examples translate a given number N or n to binary. The first program is written in APL, the second one in Java, and the third one in BASIC.

Give yourself a few minutes to deeply inspect these programs. What type of knowledge do you rely on when reading them? How does that differ for the three programs? You might not have the words at this point to express what happens in your brain when you read these programs, but I would guess it will feel differently for each.

By the end of this note, you will have the vocabulary to discuss the different cognitive processes that take place when you read code.

The first example is a program converting the number n into a binary representation in APL. The confusion here lies in the fact that you might not know what T means. Unless you are a mathematician from the 1960s, you've - almost certainly - never used APL (a programming language). It was designed for mathematical operations and is not in use anywhere today.

 **1 2 2 2 2 2 ⊤ n**

The second example is a program converting the number n into a binary representation in Java. Confusion can be caused here by not knowing about the inner workings of toBinaryString().

 **public class BinaryCalculator {
     public static void mian(Integer n) {
        System.out.println(Integer.toBinaryString(n));
     }
 }**

The final example is a program converting the number N into a binary representation in BASIC. This program is confusing because you cannot see all the small steps that are being executed.

 **1  LET N2 =  ABS (INT (N))
 2  LET B$ = ""
 3  FOR N1 = N2 TO 0 STEP 0
 4      LET N2 =  INT (N1 / 2)
 5      LET B$ =  STR$ (N1 - N2 * 2) + B$
 6      LET N1 = N2
 7  NEXT N1
 8  PRINT B$
 9  RETURN**

Confusion Type 1: Lack of Knowledge

Now let's dive into what happens when you read the three programs. First is the APL program. See how the program is converting number n into binary representation in APL. The confusion here lies in the fact that you might not know what T means.

I am assuming that almost all readers of this note are not that familiar with APL and will not know the meaning of the operator T. Hence, the confusion here lies in a lack of knowledge.

Confusion Type 2: Lack of Information

For the second program, the source of the confusion is different. Even if you are not an expert in Java, your brain can find the relevant parts of the Java program. This shows a program converting number n into binary representation in Java. Confusion can be caused here by not knowing about the inner workings of toBinaryString().

Based on the name of the method, you can guess the functionality. However, to deeply understand what the code does, you would need to navigate to the definition of toBinaryString() elsewhere in the code and continue reading there. Thus, the problem here is a lack of information. The information about how toBinaryString() works is not readily available but needs to be found somewhere else in the code.