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

Reading code (Dev2Next)

Reading code (Dev2Next)

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

October 03, 2024
Tweet

More Decks by Marit van Dijk

Other Decks in Programming

Transcript

  1. Reading Code We read code when: • adding features •

    fi xing bugs • understanding a new system • doing code reviews • learning new technologies • etc.
  2. Reading Code "developers on average spend as much as 58%

    of their time comprehending existing source code" - Felienne Hermans, The Programmer's Brain
  3. Reading Code • We spend more time reading code than

    writing code • But we don't practice reading code explicitly (much)
  4. Reading Code "How to teach programming (and other things)?" by

    Felienne Hermans https://www.youtube.com/watch?v=g1ib43q3uXQ
  5. Code reading exercise First glance The goal of this exercise

    is to practice getting a fi rst impression of code. (1 min) Independently - Glance at the code Note down the fi rst thing that catches your eye. Then note the second thing that catches your eye. Think about why you noticed those things fi rst.
  6. Examples of exercises • First glance • Identify components &

    relationships • Most important lines • Identify concepts
  7. Examples of exercises • First glance • Identify components &

    relationships • Most important lines • Identify concepts • Summary
  8. Code Reading Club Learned about ... • reading code •

    other peoples' perspectives • making my own assumptions explicit https://maritvandijk.com/code-reading-club/
  9. Reasons why code is confusing 1. Lack of knowledge 2.

    Lack of information 3. Lack of processing power in the brain
  10. Lack of knowledge • Programming domain • Language / syntax

    • Programming constructs / algorithms • Business domain • Domain concepts • Business logic
  11. Dealing with a lack of knowledge • Create a list

    • Research • Memorise (if relevant)
  12. Lack of information • Unknown details • Unfamiliar names •

    Code connected in unknown ways • Too many things at once
  13. Lack of processing power in the brain • Too many

    processing steps • Too many variables
  14. Dealing with lack of processing power in the brain •

    Memory aids • Dependency graph • State table
  15. 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); } } } }
  16. Understanding a new code base • Joining a new team

    / organisation • Using a new code base
  17. Help in the IDE • Project structure • Build &

    run • README • Dependencies • Diagrams
  18. Find a starting point • Generic • Main method •

    Endpoint • Speci fi c • Error message / Exception • Logic / Functionality
  19. Help in the IDE • Structure • Hints from your

    IDE • Tests • Debugging • Refactor for understanding • Context
  20. Structured exercises • Code Reading Club: https://codereading.club/ • Code Reading

    Club Resources: https://github.com/CodeReadingClubs/Resources • The Programmer's Brain - Felienne Hermans