Exploring Cognitive Functions for Software Engineering
How might we apply cognitive psychology to our work?
I have bad memories. Not the kind that relates to regret or sadness, but rather, I have difficulty recalling them. Whenever my wife reminisces, saying, “Remember that holiday when we …” I often draw a blank.
This forgetfulness piqued my curiosity, or more accurately, it instilled fear, prompting me to delve into books about memory. I remember over a decade ago, I read “Moonwalking with Einstein” by Joshua Foer, the 2006 U.S. Memory Championship winner. Ironically, just days after his victory, he drove his car to a celebratory dinner and took the subway back home, completely forgetting his car.
After devouring many books, I toyed with the idea of returning to university to delve deeper into the subject, but I couldn’t afford it. That’s when I realised that perhaps a textbook is a cheaper path to finding the truth1. I picked up “Cognitive Psychology” by E. Bruce Goldstein, a university textbook. Back in my university days, I’d despise reading a textbook cover to cover, but this time, I finished the textbook (still processing) and felt energised. All the things I wanted to know, they’re all here.
Nine cognitive functions
I don’t think there’s an official list of cognitive functions. The following is derived from the textbook as hinted by its chapters. As you read through this list, imagine that I’m seated in front of my computer, about to make a change to a codebase:
I engage my perception and notice multiple problems in the codebase.
I pay attention to one problem that worries me the most.
This particular problem turns into information and goes into my working memory, ready for manipulation.
As I manipulate the information, I rake through my long-term memory to determine if I have solved similar issues.
I’ve seen this before. I have the knowledge. This is a code smell. It’s called the long method. And I know multiple refactoring techniques to address this code smell.
I use visual imagery, to remind me of the architectural style we’ve adopted, ensuring the solution is aligned to it.
I reason and make the judgement to choose which solution is best.
Using all the above cognitive functions, I problem-solve, and the problem is resolved.
I commit the change, writing the commit message in a language that my future self and others will understand.
Each of the emphasised words represents a cognitive function, I won’t go deep in defining each one here. I have illustrated these cognitive functions linearly for simplicity, but they’re more intricate than that. Consider a recent task, maybe making an architectural decision, and reflect on it, every cognitive function is at play.
Cognitive psychology is the study of the mind. An interesting observation is that these cognitive functions can often be metaphorically replaced with the concept of ‘mind’:
“I’ve changed my mind” (judgement)
“If you put your mind to it, I’m sure you can find the solution” (problem-solving)
How might this be useful?
After reading the illustration above, you might ponder, what’s the point? You might think, I can do my job without understanding all that.
This is where my exploration has led me, and so far, some of my coachees have begun to see its usefulness:
1. Decompose a skill into multiple parts
Observe how a child learns to hold a pencil to write. You can break this down into fine motor skills (the strength to hold the pencil) and recognising the alphabet. Both are essential.
Similarly, in a refactoring exercise, you can dissect the skills into multiple cognitive functions, as illustrated before. This is what Quantum Steps is all about, I want to break things down into tiny parts.
2. Identifying gaps
You may notice that a child can recognise the alphabet but still can’t hold the pencil. The gap here is the fine motor skills.
In the context of refactoring, an engineer might know the steps to refactor but fail to perceive code smells. Some can’t judge well when or when not to refactor. Some architects may know architectural patterns well but fall short in problem-solving or communicating in effective language.
3. Filling the gap effectively
Once a specific gap, such as fine motor skills, is identified, you could strengthen the child’s finger with other toys, which could be more effective as they learn through play, and the skills are transferable to writing.
With the plethora of courses, many people consume vast amounts of content to learn about a topic. Ask yourself, what’s the most effective way to learn? Let me reframe this from a cognitive psychology lens: what’s the most effective way to consolidate information into long-term memory? The answer might surprise you.
Textbooks as the best way to learn new material: Less Wrong.
This was a different and very interesting read!
"...but fail to perceive code smells."
That makes sense!
I think a good exercise before adding new code, ask about the existing code: "Is there any way I can make this cleaner, and how would it look like?"
I consider it an exercise to improve your understanding of clean code.