Slide 1

Slide 1 text

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); } } } }

Slide 33

Slide 33 text

Dimensions of code reading • Structure • Domain • Concepts • Context 💔

Slide 34

Slide 34 text

Structure Code is not read linearly

Slide 35

Slide 35 text

Domain • Behavior • Data

Slide 36

Slide 36 text

Concepts

Slide 37

Slide 37 text

Context

Slide 38

Slide 38 text

Reading Code The bigger picture

Slide 39

Slide 39 text

Understanding a new code base • Joining a new team / organisation • Using a new code base

Slide 40

Slide 40 text

Reading Code • What does the code do?

Slide 41

Slide 41 text

Context

Slide 42

Slide 42 text

Reading Code A good place to start: • Check out the code

Slide 43

Slide 43 text

Help in the IDE

Slide 44

Slide 44 text

Help in the IDE • Project structure • Build & run • README • Dependencies • Diagrams

Slide 45

Slide 45 text

Strategies • Identify components • Identify relationships / dependencies • Identify concepts • Gain context

Slide 46

Slide 46 text

A slice of the application

Slide 47

Slide 47 text

Find a starting point

Slide 48

Slide 48 text

Find a starting point • Generic • Main method • Endpoint • Speci fi c • Error message / Exception • Logic / Functionality

Slide 49

Slide 49 text

Help in the IDE

Slide 50

Slide 50 text

Help in the IDE • Search • Navigate

Slide 51

Slide 51 text

Strategies • A particular use case • Draw your own diagrams

Slide 52

Slide 52 text

Reading Code Understanding a piece of code

Slide 53

Slide 53 text

Reading Code • Structured exercises

Slide 54

Slide 54 text

Help in the IDE

Slide 55

Slide 55 text

Help in the IDE • Structure • Hints from your IDE • Tests • Debugging • Refactor for understanding • Context • AI Assistant

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

Strategies • Structured exercises • Memory aids • Dependency graph • State table • Gain context

Slide 58

Slide 58 text

Reading Code What's next?

Slide 59

Slide 59 text

Structured exercises • Code Reading Club: https://codereading.club/ • Code Reading Club Resources: https://github.com/CodeReadingClubs/Resources • The Programmer's Brain - Felienne Hermans

Slide 60

Slide 60 text

Let your tools help you

Slide 61

Slide 61 text

... and your brain

Slide 62

Slide 62 text

Reading code Slides & More https://maritvandijk.com/presentations/reading-code/