Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reading code

Reading code

As developers, we spend a lot of time learning to write code, while spending little to no time learning to read code. Meanwhile, we often spend more time reading code than actually writing it. Shouldn’t we be spending at least the same amount of time and effort improving this skill? Deliberate practice can help us get better at reading code. Learning how to better read and understand code, can in turn teach us what makes code readable. This might even help us to write code that is easier to read.

In this talk we will discuss the benefits of deliberately practicing reading code in a code reading club or session without an IDE, as well as common strategies to navigate a new codebase and familiarise ourselves with the code using the IDE.

Marit van Dijk

August 31, 2023
Tweet

More Decks by Marit van Dijk

Other Decks in Programming

Transcript

  1. Reading Code
    ArnhemJUG - August 31st, 2023
    https://maritvandijk.com/

    View Slide

  2. Reading Code
    Introduction
    • We spend more time reading code than writing code

    View Slide

  3. Reading Code
    Introduction
    "developers on average spend as much as 58% of their time comprehending
    existing source code" -

    Felienne Hermans,

    The Programmer's Brain

    View Slide

  4. Reading Code
    Introduction
    We read code when:

    • onboarding to a new project

    • adding or changing functionality


    fi
    xing bugs

    • doing code reviews

    • reading books, blogs, ...

    • etc.

    View Slide

  5. Reading Code
    Introduction
    • We spend more time reading code than writing code

    • But we don't practice reading code explicitly (much)

    View Slide

  6. Reading Code
    Introduction
    • What if we practice reading code explicitly?

    View Slide

  7. Reading Code
    Introduction
    • Code Reading Club
    https://codereading.club/

    View Slide

  8. Reading Code
    Introduction
    • Fragment of code (outside an IDE)

    • Structured exercises

    View Slide

  9. Reading Code
    Introduction
    • So many insights!

    View Slide

  10. Reading Code
    Introduction
    • But what about the IDE?

    View Slide

  11. Reading Code
    Introduction
    • Di
    ff
    erent strategies / approaches for di
    ff
    erent tasks

    • With & without your IDE

    View Slide

  12. Reading Code
    Agenda
    • The bigger picture
    • Understanding a codebase

    • and it's context

    • Down to the details
    • Find a place to start

    • Search

    • Navigate from there

    • Understanding a speci
    fi
    c piece of code
    • Hints from your IDE

    • Exercises for deliberate practice

    View Slide

  13. Reading Code
    Introduction
    • Focus:

    • Reading to understand
    • Not to judge

    View Slide

  14. Reading Code
    The bigger picture

    View Slide

  15. Reading Code
    The bigger picture
    • Onboarding to a new team / code base

    View Slide

  16. Reading Code
    The bigger picture
    • What does the code do?

    View Slide

  17. Reading Code
    The bigger picture
    • What is the context?

    View Slide

  18. Reading Code
    The bigger picture
    • Background knowledge

    • Business domain

    • Programming domain

    View Slide

  19. Reading Code
    The bigger picture
    • Read the documentation!

    • Do some research

    View Slide

  20. Reading Code
    The bigger picture
    Strategies:

    • Identify components

    • Identify relationships / dependencies

    • Gain background knowledge

    View Slide

  21. Reading Code
    The bigger picture
    • Take notes!

    View Slide

  22. Reading Code
    The bigger picture
    But
    fi
    rst:

    • Check out the code

    • See if you can build it

    View Slide

  23. Demo time

    View Slide

  24. Reading Code
    The bigger picture
    • Draw your own diagrams

    • Write down questions

    • Write down suggestions (maybe)

    View Slide

  25. Reading Code
    The bigger picture
    Science:

    • Chunking

    View Slide

  26. Reading Code
    Down to the details

    View Slide

  27. Reading Code
    Down to the details
    • Find a starting point

    View Slide

  28. Reading Code
    Down to the details
    • Search

    View Slide

  29. Reading Code
    Down to the details
    • Navigate

    View Slide

  30. Demo time

    View Slide

  31. Reading Code
    Down to the details
    • Draw your own diagrams

    • Write down questions

    • Write down suggestions (maybe)

    View Slide

  32. Reading Code
    Understanding a piece of code

    View Slide

  33. View Slide

  34. Reading Code
    Understanding a piece of code
    • Exercises

    View Slide

  35. Reading Code
    Understanding a piece of code
    • Your IDE can help!

    View Slide

  36. Reading Code
    Understanding a piece of code
    • Structure

    View Slide

  37. Reading Code
    Understanding a piece of code
    • Restructure

    View Slide

  38. Reading Code
    Understanding a piece of code
    • Behavior

    View Slide

  39. Reading Code
    Understanding a piece of code
    • Context

    View Slide

  40. Demo time

    View Slide

  41. Reading Code
    Next steps
    • What's next?

    View Slide

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

    View Slide