Cognitive driven development

CDD is based on 2 psychological theories

  1. Magical Number Seven Theory
  2. Cognitive Load Theory

Increases Code Readability

Applications of Cognitive Driven Development Practice

Encapsulating error handling

AOP can make code closer to plain English

Encapsulating business rules

Concatenating logical expressions

Several nested ifs can optimize the compute if the evaluation of each if is expensive. Otherwise grasping nested ifs is hard. Prefer Truth Tables over very complex or repetitive conditions.

Extract class/functions

Listing all imports

Asserting conditions

AOP can make code closer to plain English

Ternary Operators

Generally disliked. But better than Options and can be replaced with Elvis operator instead for null checks.

Encapsulating for loops

Use custom functions to loop or use functions like reduce, maps, select, first etc. as the function names represent the intent explicitly. This is a common practice in languages with functional paradigms.

Reduce Global or state variables


📌 Tagged As