Reading Code
NDC London - Jan 31st, 2025
https://maritvandijk.com/
Slide 2
Slide 2 text
Disclaimer
Contains Java
Slide 3
Slide 3 text
Reading Code
• We spend more time reading code than writing code
Slide 4
Slide 4 text
Reading Code
We read code when:
• adding features
•
fi
xing bugs
• understanding a new system
• doing code reviews
• learning new technologies
• etc.
Slide 5
Slide 5 text
Reading Code
"developers on average spend as much as 58% of their time comprehending
existing source code"
-
Felienne Hermans,
The Programmer's Brain
Slide 6
Slide 6 text
Reading Code
• We spend more time reading code than writing code
• But we don't practice reading code explicitly (much)
Slide 7
Slide 7 text
Readability
When we do talk about readability,
it's often about writing readable code.
Slide 8
Slide 8 text
Reading Code
"How to teach programming (and other things)?" by Felienne Hermans
https://www.youtube.com/watch?v=g1ib43q3uXQ
Slide 9
Slide 9 text
Reading Code
• What if we practice reading code explicitly?
Slide 10
Slide 10 text
Code Reading Club
• Code Reading Club
https://codereading.club/
Slide 11
Slide 11 text
The stars aligned
Do you want to join our
code reading club?
Slide 12
Slide 12 text
Code Reading Club
• Printed code sample
• Structured exercises
Slide 13
Slide 13 text
Examples of exercises
• First glance
Slide 14
Slide 14 text
Examples of exercises
• First glance
• Identify components & relationships
Slide 15
Slide 15 text
Examples of exercises
• First glance
• Identify components & relationships
• Most important lines
Slide 16
Slide 16 text
Examples of exercises
• First glance
• Identify components & relationships
• Most important lines
• Identify concepts
Slide 17
Slide 17 text
Examples of exercises
• First glance
• Identify components & relationships
• Most important lines
• Identify concepts
• Summary
Slide 18
Slide 18 text
Code Reading Club
Learned about ...
• reading code
Slide 19
Slide 19 text
Code Reading Club
Learned about ...
• reading code
• other peoples' perspectives
Slide 20
Slide 20 text
Code Reading Club
Learned about ...
• reading code
• other peoples' perspectives
• making my own assumptions explicit
https://maritvandijk.com/code-reading-club/
Slide 21
Slide 21 text
Reading Code
Slide 22
Slide 22 text
Reasons why code is confusing
1. Lack of knowledge
2. Lack of information
3. Lack of processing power in the brain
Slide 23
Slide 23 text
Cognitive processes
• Long term memory
• Short term memory
• Working memory
Slide 24
Slide 24 text
Lack of knowledge
• Programming domain
• Language / syntax
• Programming constructs / algorithms
• Business domain
• Domain concepts
• Business logic
Slide 25
Slide 25 text
Dealing with a lack of knowledge
• Create a list
• Research
• Memorise (if relevant)
Slide 26
Slide 26 text
Lack of information
• Unknown details
• Unfamiliar names
• Code connected in unknown ways
• Too many things at once
Slide 27
Slide 27 text
Dealing with lack of information
• Chunking
Slide 28
Slide 28 text
Dealing with lack of information
• Chunking
• Concepts & patterns
Slide 29
Slide 29 text
Lack of processing power in the brain
• Too many processing steps
• Too many variables
Slide 30
Slide 30 text
Dealing with lack of processing power in the brain
• Memory aids
• Dependency graph
• State table
Slide 31
Slide 31 text
Dependency graph
Slide 32
Slide 32 text
State table
public class NestedLoop {
public static void main(String[] args) {
for (int i = 0; i < 2; i++) {
System.out.println("i is: " + i);
for (int j = 0; j < 2; j++) {
System.out.println("j is: " + j);
}
}
}
}