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