The Psychological Impact of Code Consistency

The Psychological Impact of Code Consistency

Bernardo Oliveira · March 26, 2024

Across the life journey, some aspects of life become more relevant than others, they make us even more unique in our uniqueness. Our professional life is merely a reflection of it.

I believe that giving the best care and equilibrium in every corner of our daily lives contributes to a more positive and happy balance. With this sentence, we could write thousands of articles, ranging from nutritionism and mindfulness to exercise routines, time management strategies, circadian cycle, self-care practices, and fostering healthy relationships. Each aspect contributes to our overall well-being and enhances our journey toward a fulfilling life.

But today, I want to engage in a less-expected topic. How can code consistency sum up for a better day in our daily journey? In the world of software development, consistency in code is often praised for its technical benefits, such as easier maintenance, readability, and scalability. However, its impact on psychological factors and productivity is equally profound yet often overlooked.

Companies like Facebook, Airbnb, and many others use internal style guides to enforce code consistency, ensuring that their software development teams adhere to established conventions and standards. These guides cover aspects such as naming conventions, formatting rules, code structure, and best practices, ultimately promoting maintainability, readability, and collaboration within the development process.

In a psychological path, it goes beyond just looks, it fosters a sense of order and predictability within the codebase. The human brain is inherently drawn to patterns, organization, and predictability, as they reduce cognitive load and make information processing more efficient.

Android Jones art

Image credit: Android Jones

Evolutionary History

Throughout our evolutionary history, humans have relied on patterns and predictability as fundamental survival mechanisms. In prehistoric times, early humans needed to recognize patterns in their environment to identify potential threats, locate sources of food, and navigate their surroundings safely. This ability to detect patterns and anticipate outcomes was crucial for survival in a constantly changing and often unpredictable environment.

As our ancestors transitioned from hunter-gatherer societies to agricultural and eventually industrial civilizations, the importance of patterns and predictability persisted. Agricultural societies relied on seasonal patterns to determine the timing of planting and harvesting crops, while industrial civilizations established predictable systems of production and trade to facilitate economic growth.

From a psychological standpoint, the human brain is wired to seek out patterns and impose order on the world around us. This innate tendency, known as pattern recognition, allows us to make sense of complex information and make decisions more efficiently. When faced with chaotic or disorganized stimuli, our brains instinctively seek patterns to create a sense of order and predictability.

Moreover, the human brain is optimized for processing and retaining information that follows predictable patterns. Studies in cognitive psychology have shown that information presented in a structured and organized manner is more easily encoded into memory and retrieved when needed.

Cognitive Principles

In the context of software engineering, when code is well-organized and formatted, it conforms to cognitive principles such as chunking and schema formation. Chunking refers to the process of grouping information into meaningful units, allowing the brain to process larger amounts of information more effectively. Well-formatted code facilitates chunking by breaking down complex logic into manageable sections, making it easier for developers to grasp and work with.

Furthermore, the brain relies on schemas, or mental frameworks, to interpret and organize information. Well-organized code conforms to established coding conventions and design patterns, enabling developers to quickly recognize familiar structures and understand the underlying logic. This adherence to schemas reduces cognitive strain, as developers can rely on their existing mental models to navigate and comprehend the codebase.

Moreover, cognitive psychology highlights the importance of attention and focus in information processing. Clean, readable code minimizes distractions and cognitive noise, allowing developers to maintain attention to the task at hand. The ratio of time spent reading versus writing is well over 10:1. By reducing the cognitive load associated with deciphering poorly formatted code, developers can allocate more mental resources to problem-solving and creative thinking.

Syntax highlighting serves as a prime illustration of our brain's inclination toward patterns. Can you picture coding throughout the entire day without any syntax highlighting? Let's now apply the concept of pattern recognition to the following images:

No syntax highlighting

Bad consistency

Good syntax highlighting

The first image is a code snippet without syntax highlighting, the second image is a code snippet with bad consistency, and the third image is a code snippet with good consistency and highlighting. Which one is easier to read? Which one is easier to understand?

Conclusion

Programs are meant to be read by humans and only incidentally for computers to execute. — H. Abelson and G. Sussman (in “Structure and Interpretation of Computer Programs”)

As artists, our predominant means of communication is through art. We use our art to engage and interact in harmony with the world around us.

When we see how beautiful our art is and how it impacts other Pablo Picasso’s, we understand that we are not just writing code, we are writing a masterpiece. A masterpiece that will be seen, felt, and used by thousands of people and perhaps (hopefully not) for thousands of years.

You are leaving a Mona Lisa not only for your future self but for countless other artists. Bring the best of you into your masterpiece.

By implementing code consistency in your team, and in your company, you’re not only improving your product but caring for the people who give their lifetime to it. You are increasing their sense of belonging, confidence, and happiness. Cultivating a culture of collaboration and productivity within software development teams.

Code style is very subjective, collaborate with your team to establish a style that satisfies everyone, and rigorously maintain it using tools such as ESLint or the appropriate linting tool for your programming language. For each linting tool there is several plugins to go even deeper, for example, eslint-plugin-perfectionist and stylelint-config-clean-order.

If you made it here, I just want to let you know you are amazing.

Thank you very much!


Bernardo Oliveira

Bernardo Oliveira

Frontend Engineer @ Braga

Follow me on