r/learnprogramming • u/TalkHot2112 • 20h ago
How do you practise reading code?
Software engineering student here. With AI, the expected output is so high that I barely have time to understand code, let alone write it myself.
Since AI writes most of it now, I think reading and understanding code matters more than writing it. How do you practise that? Any exercises, resources, or habits that helped you?
Something like LeetCode that displays an excerpt of code and asks about your understanding of it would be great.
0
Upvotes
11
u/BranchLatter4294 19h ago
Write code. Being able to read code will happen the more you write.
5
u/SolsticeAlpenglow 19h ago
By... reading it?
9
u/GItPirate 19h ago
If you truly want to learn programming you have to practice writing it by hand.
4
u/UltraPoci 19h ago
so many questions about AI can be answered in the some way: don't use it for 100% of everything you do. Use your brain
8
u/denlillepige 19h ago
you practice it by reading it.
One thing you can do, write tests for the code, at least then you can try to understand what the overall code is supposed to do, the edgecases, limits, etc. if you can get that down, then you are at least 1 step closer.
Then try to just take it line by line, and "translate" it into pseudo code. see if it makes sense, whenever you don't understand what a piece of code does, try to google the functions, look deeper into code, etc.
2
u/Ok_For_Free 19h ago
Hold code review sessions with fellow students and make PRs part of your dev process even for solo dev projects.
Even for AI generated code. One of the first take aways from reviewing code will be to improve readability. Tell your agents that source code is meant to be read by humans and not just agents.
2
u/nneiole 19h ago
For context: I am senior engineer working in an educational program, our participants mainly develop fullstack web applications, I do high-level code reviews of their repos. I start from requirements or readme or whatever to understand the intent and then I would go from frontend/ui to backend/api. I would try to sketch which data exists in the app, what structure does it have and how is it transformed. Sometimes I do a small refactoring to understand a big component/service better.
2
u/OAMNG 19h ago
When I have to review piles of code I don't understand, I take the time to write documentation. If you cannot explain the code to yourself in writing, then you don't understand it. By the time you understand it well enough to write documentation about how the system incorporates that code and why it does what it does, well then not only have you produced a valuable product (documentation) but now you understand it.
At work, management will often ask you to "review code" so that they can sleep better at night about forcing engineers to man the slop cannons, but they will also pressure you to not take time to write your own documentation, which is saying the quiet part out loud: they don't care if you understand it, they just want you to approve it. Resist. Or try to find a job with a better engineering culture.
1
u/TheSeeker_99 19h ago
I read it
1
u/good_name_0 18h ago
The better you get at writing real code, the better you get at reading it, and vice versa. It's just a matter of experience. You will have to be patient, it will come
Don't know about ai stuff though
1
u/Tilroe 17h ago edited 17h ago
This is one of the pitfalls of over reliance on AI at the learning stage I believe. All these people making fun of this by saying "just read it.. durr", it isn't as simple as that IMO. It's like studying for a test. Do you study for a test solely by reading the textbook? No. You do practice questions to make sure you understand what it's telling you, and have a mental map of the material without having it right in front of you. If you're just reading the textbook, it's so easy to look at a concept once, understand what it said, and convince yourself that you will remember it. Then the test comes and BOOM you forgot. Similar for reading AI generated code, your eyes will start glazing over the mountains of code, and you take for granted what it wrote, as well as your understanding of it, which will likely disappear shortly after.
If using AI from the onset is truly the way software development is going to be taught from here on out, and youre using it to write from non-specifc prompts, I think your best bet is to 1. Take time to read it piece by piece yourself and 2. Iterate on it by questioning its design decisions with design patterns and concepts you might have learned in school. Basically interrogate it I suppose. Make it convince you that it's the best way to do it.
That or write by hand.
1
u/justforthisholloween 16h ago
Thereās actually a book called āReading Codeā by Diomidis D. Spinellis. It will help you read code in a disciplined way.
0
u/TehMasterer01 19h ago
I donāt.
0
u/Annual_Berry8043 19h ago
Idk if this is unpopular or im just a total moron. I hate reading most peopleās code. Itās difficult. I can read AI code fine, I can read my code fine, and I did an interview with engineers from ex-Microsoft and ex-Google where I could read their code fine when asked to review it and give input.
Iām literally code blind 90% of the time.
0
u/devdruxorey 19h ago
Good God, I canāt believe your brain is this fried. AI couldnāt have arrived at a worse time, right when peopleās attention spans are at their absolute shortest.
0
u/mxldevs 19h ago
Get AI to read the code for you.