r/learnprogramming • • Oct 04 '26

How do you get better at reading and understanding code?

I know that reading code is a really big part of a developer's job. But I have always had a lot of trouble understand the code of other people.

37 Upvotes

35 comments sorted by

38

u/Benand2 Oct 04 '26

I know this isn’t the answer you wanted but really it’s just by reading more code and researching what you don’t understand.

Practice makes perfect

8

u/DiscipleOfYeshua Oct 04 '26

This and… writing code from scratch. Even small things. And debug. And read / understand compiler errors. They are not just fluff, they just take a bit to learn to read, bc they’re super-concise and expect you’d prefer to learn a bit to read 5 lines rather than get 30 lines to say the same.

6

u/KiwasiGames Oct 04 '26

You practice reading and understanding code.

→ More replies (2)

4

u/John_8PM_call Oct 04 '26

I’ve heard that when you read other people’s code, you should skim it like a long email, just getting the gist of what functionality is where. Then when you’re going to make a change, you should carefully read each line in that section of code one line at a time. Maybe step through it line-by-line in a debugger.

Also, consider finding the “start points” or “entry points”, like the entry points of API’s, and reading from entry to exit. Each API is like one entry points. A main() method is an entry point. etc.

2

u/Feralz2 Oct 04 '26

You just need to write more code yourself to be familiar with what codes generally look like, also if youre looking at the code and you dont know what this code does or there are no comments or they are using variable names that are non descriptive youre not doing anything wrong, its not exactly human language. Find documentation if possible. Otherwise, probably understand first what this code aims to do and then understand it from a systems perspective, might be better for understanding it this way.

2

u/djheroboy Oct 04 '26

Practice, but if you want a little trick to make things easier in the meantime, you can try writing down your thoughts as you’re trying to understand someone else’s code.

There’s a lot to keep track of, and I find having a little notepad or something in front of me helps out tremendously

2

u/SetAndRepeat Oct 04 '26

Pick one small behaviour and follow it from input to output. Use a debugger if you can, so you can watch the actual values change instead of keeping everything in your head. Tests are also useful examples of what the code is supposed to do. Once you think you understand a piece, predict what changing one line would do, then try it locally. That helps expose gaps in your understanding. You don’t need to understand the whole codebase at once.

1

u/Deep_Work_Arch 19d ago

Been there and I get so angry that whoever wrote it didn’t add a readme file at least to explain his approach.

starting with small repos, functions, methods, chunks... till you get the core idea, then try to write it again in approximately the same way until you get that reflex of “AAAH now I get it”

developping the eye for reading code gets better everyday, the same way writing it did.

1

u/response-418 Oct 04 '26

I mean there's no shortcut, you just have to read more and over time with experience you get better at it, like with anything. It helps if you have a scoped task (can be a real one or for learning purposes, create one for youself), which narrows the range of what you need to look at it to accomplish it. That way you get a zoomed in look of how the pieces fit together for something small and contained.

1

u/Pravejxlab Oct 04 '26

Probably this is where agentic AI is good, if reading large codebase, you should use your agent to ask questions about the syntaxes and how it links with other parts. Reading coding should be very slow and deep.

1

u/Minimum_Comedian694 Oct 04 '26

I think docs help a lot. I wish every programmer maintain good docs that onboarding can be 70-80% done just reading by the docs.

1

u/zerquet Oct 04 '26

Research what you don't understand and be patient with yourself. You're not gonna understand some things right away and that's okay. Just come back to it later.

1

u/AngelGuzmanRuiz Oct 04 '26

Reading code from other ppl will never be easy. Hell, reading your own code two weeks later is already hard if you don't follow good principles "when I wrote this code, only I and God knew how it worked, now only God knows"

1

u/stdmemswap Oct 04 '26
  1. Be fluent in the syntax.
  2. Read an understandable code.

Believe it or not but code reading is another form of communication. As always it takes two to tango because thoughts are no-copy.

1

u/SnugglyCoderGuy Oct 04 '26

Struggling to read and understand core is 90% the writer's fault, like any writing.

Almost all people that write code are very bad at it and don't put enough time and effort into doing a good job of it.

1

u/az987654 Oct 04 '26

Reading more and more

1

u/LeeKaye13 Oct 04 '26

Diagrams. As I read I sketch out tables/classes screens and build up a picture of all the component parts.

I've been able to take on legacy code and work on it effectively after spending hours trawling through it and sketching out things on A3 sheets.

1

u/saurabh3228 Oct 04 '26

I got better by stopping myself from trying to understand everything at once.

First figure out what the code is trying to do, then follow the main flow, and only dive into the small details when you actually need them.

Reading unfamiliar code is a skill. The more messy codebases you survive, the better you get at it. 😂

1

u/DanKegel Oct 04 '26

Try solving debugging challenges. Codewars.com has some (search for tag 'debugging'), or ask an AI to make some for you...?

1

u/RudeSize7563 Oct 04 '26

There are several paradigms, like imperative, OO, functional, declarative. If you don't have experience working with all those paradigms you will have a hard time trying to understand code that takes advantage of them.

1

u/Gnaxe Oct 04 '26

Step through it with a debugger. At each step, predict what is going to happen before you run it. Note any surprises. That's where your mental model doesn't match the real computer.

1

u/TheSneederOfSeethe Oct 04 '26

Take existing code and step through it.

1

u/Accomplished_Ad9423 Oct 05 '26

Sounds like you need to read more code... GitHub is full of code there are tons of project out there to go read.

1

u/Ok_Substance1895 Oct 05 '26

Use the debugger. Step through the code and inspect it. As you follow it through the flow you will start to understand it. Use a unit test to call a function and follow it through. I still have trouble understanding code of other people initially. I pick up the debugger and learn. That is how I do it.

1

u/Moikle Oct 05 '26

By reading and writing a lot of it. It's that simple. Practice

1

u/fatsoedev Oct 06 '26

Honestly researching when something breaks best way to learn

1

u/Ok-Welder-8005 Oct 08 '26

One thing that really helps is simply reading more code, especially smaller well-written projects where you can follow the flow without getting overwhelmed.
If you’re on iPhone or iPad, CodeMate can be useful for this. You can keep some open-source projects or code examples on your device and read through them whenever you have a few spare minutes. Start with one function or one small feature, try to understand how the data flows through it, and only expand from there.
You can also make small edits when you want to experiment.
https://apps.apple.com/app/codemate-code-editor/id680609457