Wiki: 7±2 Reasons Psychology Will Help You Write Better Code
For agents: Markdown version · Wiki index · Explore
- Speaker: Moran Weber, Jonathan Avinor
- Event: Reversim Summit 2018
- Video: https://www.youtube.com/watch?v=_JYKovIAnGs
- Transcript: /transcripts/2018/58-_JYKovIAnGs.md
- Language: Hebrew · Type: talk · Level: general
- Topics: Software Engineering
Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.
Summary
This talk explores how cognitive psychology can help developers write more readable and maintainable code. The speakers explain how human brains process text and information, using concepts like the Stroop effect, working memory limits, and cognitive filtering systems. The audience learns practical techniques for naming variables, structuring functions, and conducting code reviews to reduce mental fatigue for other developers.
Key points
- 3:12 The Stroop test demonstrates how the human brain automatically reads and processes text without our conscious control, causing friction when text colors and words mismatch.
- 5:15 Variable and function names should not only be accurate but actively build and fulfill the correct expectations for whoever reads the code next.
- 10:21 Human working memory is limited to about five to nine items, known as the magical number seven plus or minus two.
- 11:21 Developers can bypass working memory limitations by using chunking, which groups related information, parameters, or logic into smaller, meaningful pieces.
- 16:23 System 1 is our fast, instinctive, and emotional thinking system that constantly filters out noise and relies on predictable patterns.
- 18:25 Writing predictable and neatly formatted code allows System 1 to easily filter out routine syntax and plumbing, saving System 2 for complex logic.
- 22:29 Code readability is inherently subjective, making code reviews essential to verify that your intentions are clear to others.
- 24:34 Cold code reviews, where the reviewer reads the code independently without the author explaining it, are necessary to spot hidden bugs and design issues.
Takeaways
- Choose variable and function names that create accurate mental expectations and consistently fulfill them.
- Apply chunking to long parameter lists and complex functions to respect the limits of human working memory.
- Format code predictably so that readers’ brains can automatically filter out routine syntax and focus on business logic.
- Conduct cold code reviews without explaining the code verbally to ensure it is truly readable to others.
Questions this talk answers
- How does cognitive psychology influence the way developers read and process code?
- What is chunking and how can it be applied to refactor long functions or parameter lists?
- Why are cold code reviews more effective than walkthroughs when evaluating code readability?
Technologies
AngularJS, JavaScript
Tags
clean code, code readability, code review, cognitive psychology, software craftsmanship, working memory