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

Reading Code Is Harder Than Writing It

Trisha Gee
February 20, 2025

Reading Code Is Harder Than Writing It

It's funny that computer languages are the only languages where one learns to write before learning to read. It's actually not uncommon for people to never really learn to read code. This seems a little unbalanced given that we actually read code much more frequently than we write it.

Even those who promote software as a craft sometimes fall into the trap of often talking about writing clean code that people can read, yet not placing much emphasis on the skill of reading the code.

The ability to read code must also be a skill, and as such it must be something that can be learnt and practiced. In this presentation, we're going to look at:

- The different reasons we might have to read code, and how that should impact our reading
- The problems we face when reading code (even our own!)
- Tips to bear in mind when we're reading code
- Tools we can use to help our understanding
- How and where to practice these skills

At the end of the talk we will at least have considered whether we need to level up our "Reading Code" skill.

Trisha Gee

February 20, 2025
Tweet

More Decks by Trisha Gee

Other Decks in Technology

Transcript

  1. • Lead Developer Advocate • Java Champion & JetBrains Community

    Contributor • 20+ years development experience • Author Trisha Gee
  2. “Every programmer occasionally, when nobody’s home, turns off the lights,

    pours a glass of scotch, puts on some light German electronica, and opens up a file on their computer. They read over the lines, and weep at their beauty….” https://www.stilldrinking.org/programming-sucks
  3. “This file is Good Code. It has sensible and consistent

    names for functions and variables. It’s concise. It doesn’t do anything obviously stupid…. It reads like poetry written by someone over thirty.” https://www.stilldrinking.org/programming-sucks
  4. “After enough exposure with feedback, your brain began detecting patterns

    and underlying structures, without your conscious awareness. With more exposure, your brain finetuned its perception and eventually figured out what really mattered. Your brain was making finer distinctions and sorting signal from noise even if you couldn’t explain how.” Badass: Making Users Awesome Kathy Sierra
  5. Where to practice • Your codebase • Open source •

    Libraries you’re using • Coding katas
  6. Don’t Judge • Explore • Make notes • Questions •

    Discoveries • Assumptions • Draw diagrams • Don’t change the code
  7. Structure • Services • Modules • Packages • Layers •

    Patterns • Naming • Relationships • Responsibilities • Data flow • Build order
  8. “If music be the food of love, play on, Give

    me excess of it; that surfeiting, The appetite may sicken, and so die.” Twelfth Night William Shakespeare
  9. Whylom, as olde stories tellen us, Ther was a duk

    that highte Theseus; Of Athenes he was lord and governour, And in his tyme swich a conquerour, That gretter was ther noon under the sonne. The Canterbury Tales, and Other Poems Geoffrey Chaucer (1387–1400)
  10. Consider • Language • Libraries • Age • Patterns •

    Standards • Code shape • False friends
  11. “If you don't think about the underlying mechanics of the

    simulation—even if that thinking happens in a semiconscious way—you won't last very long in the game. You have to probe to progress.” Everything Bad is Good for You: How Popular Culture is Making Us Smarter Steven Johnson
  12. Run code to understand it • Code analysis tools •

    Debugger • Watches • Evaluate expression
  13. “The game scholar James Paul Gee breaks probing down into

    a four-part process, which he calls the ‘probe, hypothesize, reprobe, rethink’ cycle” Everything Bad is Good for You: How Popular Culture is Making Us Smarter Steven Johnson
  14. “It may, or may not, have helped Anathema get a

    clear view of things if she’d been allowed to spot the very obvious reason why she couldn’t see Adam’s aura. It was for the same reason that people in Trafalgar Square can’t see England.” Good Omens Neil Gaiman & Terry Pratchett
  15. Tips 1. Practice 2. Reading is not reviewing 3. Code

    bases have a shape 4. Code bases have a dialect 5. Code is not linear 6. Code is meant to be run 7. If you must write, write tests 8. If you must change it, throw it away 9. Not all knowledge can be codified
  16. “I’m grizzly and grumpy and grouchy and grumbly I’ve not

    been called lovely before!” The Giant of Jum Elli Woollard & Benji Davies
  17. Donald Knuth – Literate Programming (1984) Code should be written

    to be read and understood, not just executed. Steve McConnell – Code Complete (1993) Developers spend more time reading code than writing it. Raymond Chen – Microsoft Developer Blog (2007) "Code is read much more often than it is written, so plan accordingly." Robert C. Martin (Uncle Bob) – Clean Code (2008) “Indeed, the ratio of time spent reading versus writing is well over 10 to 1.” Daniel Roy Greenfeld “Code is read more than it is written.” ChatGPT
  18. “My fingers,” said Elizabeth, “do not move over this instrument

    in the masterly manner which I see so many women’s do. They have not the same force or rapidity, and do not produce the same expression. But then I have always supposed it to be my own fault — because I will not take the trouble of practising.” Pride & Prejudice Jane Austen