π§ Cognitive load is how much a developer needs to think in order to complete a task.
π§ The average person can hold roughly four chunks of information in working memory; cognitive overload occurs once this threshold is passed.
π Focus must be placed on reducing extraneous cognitive load, which is created by the way information is presented, rather than the intrinsic load, which is the inherent difficulty of the task.
π‘ Use intermediate variables with meaningful names to break down complex conditionals.
π§± Prefer composition over inheritance to avoid an inheritance nightmare where functionality is scattered across multiple classes.
π Deep modules are superior to shallow modules because they provide powerful functionality yet have a simple interface, maximizing information hiding.
ποΈ Information hiding is paramount, and shallow modules do not effectively hide complexity.
π₯ The Single Responsibility Principle means a module should be responsible to one, and only one, user or stakeholder, not just performing βone thing.β
π Too many shallow microservices lead to a distributed monolith, causing debugging issues and unacceptably high time to market and cognitive load.
βοΈ Limit the number of choices and reduce cognitive load by using language features that are orthogonal to each other.
π The mindset βWow, this architecture sure feels good!β is misleading; a far better approach is to observe the long-term consequences, like ease of debugging and new developer onboarding time.
π΄ The best code is often boring and straightforward, not the most elegant or sophisticated.
π€ Evaluation
π‘οΈ While this philosophy champions simplicity, Clean Code and Domain-Driven Design (DDD) advocate for structured complexity and rigorous separation of concerns.
βοΈ Clean Code often encourages many small functions and classes, which this article labels as shallow modules that ultimately increase cognitive load by forcing developers to mentally untangle numerous interactions.
π Identify topics to explore for a better understanding.
π¬ Further exploration is needed into the scientific definition of cognitive load (intrinsic, extraneous, and germane) to better match the informal application in software engineering contexts.
π The concepts of βDeepβ vs. βShallowβ modules require practical, domain-agnostic metrics beyond mere line count to guide architects on optimal component and service boundary delineation.
π§βπ» Research into the onboarding timelines of new engineers in well-crafted monoliths versus distributed systems would provide empirical data to conclusively support the argument against overly granular microservices.
π Book Recommendations
π‘ Similar
A Philosophy of Software Design: π Reinforces the concepts of deep modules and complexity reduction through principles like information hiding and simple interfaces.
π€ππ’ Thinking, Fast and Slow: π§ Explores the two systems of thought in the brain, providing a psychological basis for why code should be designed to minimize effortful, high cognitive load (System 2) thinking.
πΊπͺπ‘π€ The Design of Everyday Things: π οΈ Discusses how good design minimizes the cognitive effort required to use physical objects, a principle directly applicable to designing software interfaces and codebases for human consumption.