r/learnprogramming • • 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

30 comments sorted by

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?

4

u/Dazzling_Music_2411 19h ago

Yeah, but HOW do I Reeeeaaad it bro, I'm honestly completely lost, PLEEEZ HLP

šŸ˜‚ šŸ˜‚ šŸ˜‚ šŸ˜‚ šŸ˜‚ šŸ˜‚

1

u/BrannyBee 15h ago

Stop treating it like engineering, its much more like learning a language.

You see experienced devs like us typing hundreds of lines of code per minute and being able to read someone elses code and understanding it the first time, and it seems like they're insanely smart.

We arent. Do you see someone reading a book and think to yourself "wow, that person is really smart"? Do you think that when you hear any two random people speaking in English to each other that they must have massive brains? I sure don't, I'm a fucking idiot, and even I judge how other people can be so dumb when I read or hear them sometimes.

Writing code and reading code is the easiest part of the job because it's automatic just like typing without looking at your keyboard or speaking to another person. Sometimes yeah, you have to slow down and search your brain for the right word or google the definition of a word you just saw for the first time, same thing with coding. You build that baseline by practicing, and then occasionally look in the "dictionary" (internet/documentation) to clarify things

If they make AI easy enough for a literal baby to use it, you today would still be better at using that AI than a baby who cant speak english. You can use AI for code today, but you wont use it to it's full potential the same as someone who has that baseline knowledge.

So if you want to read and write code, literally do the same thing you did when you learned a language the first time. You learn the basic vocab, the basic grammar, and then you re-learn those things over and over again even if you think you understand the first dozen times. Then you spend a lot of time practically using the grammar and vocab and making short "sentences" or programs. Then you do that a million times, even if you understand it the first thousand times.

Then you start combining words and grammar points, and using new more complicated things you've learned to make longer and more descriptive sentences. Even then, you still are re-learning the basics, and using them over and over again as you boringly practice over and over again. Then you learn paragraphs and repeat, then you learn how to structure an essay and keep using the basics.

You already did this, you spent years learning English. If you want to read code like experienced devs can, you need to read code and write code. If you want to speak English, you need to read english writing and make your own english sentences. You can't say "i cant learn to read code because i dont understand the code", because you already know enough english to read how simple things like loops and conditionals work. If you said that in the 1st grade, it wouldnt be an acceptable answer, because there are books that are designed to be read at that level.

You may have been frustrated as a 1st grader that you couldnt read Lord of the Rings, and maybe you tried and found out yourself that you didnt know enough. Exact same thing happens with code, you dont understand how to build your own game engine from scratch and will not be able to read Unity's source code and understand it. But you understand how to read a "Hello World" program. Sure, maybe that doesnt seem useful to you because it's so simple... but thats like a 3rd grader saying The Very Hungry Caterpillar isn't useful... it was very useful... the 3rd grader just practiced literally everyday a ton and now reads Animorphs books. Both use nouns and verbs. Complicated code uses the same basic stuff Hello World does.

You are older now and understand one language at least, English. So you dont have to comoletely spend the next 12 years mastering a programming language like you did to learn English (or whatever your native tongue is)... but the only reason you dont have to do that is because you've learned how to learn, and have the advantage of knowing a language to search in the dictionary (documentation/internet) to speed up the learning. You also know that you can go and write your own code right now or go to github and find other peoples code to read and learn from. You were a literal toddler with no resources like that the first time you learned a language, so it won't take 12 years to get the basics, but if you havent written a thousand loops at least, you're gonna forget keywords or how an inner loop works over and over again because you havent practiced.

If you want to READ code, take a step back and recognize that seniors say its the easiest part of the job for a reason. If it's hard for you, thats not an insult to your intelligence, plenty of idiots like me learned english... its an indicator that you haven't "done your homework" like that dumb kid we all knew in school who never did his homework and eventually grew into that dumb teenager who you prayed never was picked to read out loud in class because he was so slow.

Its repetition and practice, and more repetition abd more practice. Then more repetition and practice. Even when you don't realize you're practicing, its practice because you are using the basics every single time you ever write even a line of code. Same as learning any other language, you read comments on reddit, and you're getting more reps in practicing english.

If you cant read code, its literally the same reason you can't read Japanese or Spanish.

1

u/EdiblePeasant 12h ago

Do we have a FAQ about AI?

9

u/GItPirate 19h ago

If you truly want to learn programming you have to practice writing it by hand.

-22

u/Due-Result7928 19h ago

Not anymore. Software as a craft is almost over.

2

u/tobiasvl 18h ago

Maybe, but if OP still wants to learn software as a craft, there's only one way to do that and that is to craft software

-4

u/Due-Result7928 18h ago

Software as we knew is dying. Emacs's artists and Neovim's fanatics will be a souvenir faster than you think.

In this business for 30 years with anything Unixes. AI is a destructive technology for software development. Numbers are here already in term of productivity. Junior jobs are vanishing and trainee can not find opportunity. 24 % less candidates for study software engineering in all university.

AI is everywhere even with small shops. Software people were behind savage cuts in many fields in the past such as banking, insurances, travel industry...I remember..train yourself, learn Python. It is their turns now and they do no like it a bit.

Slop..a term used to indicate poor quality...when you know the pathetic state of the software industry (including open source) you can pause. More than 40 % of the projects are collapsing, 30 % deliver poor quality products or products not delivering added value to customers, bugs are everywhere.

1

u/tmtowtdi 15h ago

And none of your blathering does a single thing to answer the posted question of "How do you practise reading code?".

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.

1

u/outlined-dev 19h ago

Style guides are important. Google has excellent style guides. E.g. avoiding the pyramid of doom via early exits so that error handling stays near the error, or forbidding mutable references in C++ so that only pointer arguments can be changed. When I worked at Microsoft, SAL annotations and prefix annotations took a long time to get used to but then helped.

Ultimately though, the only way to get used to reading code is to read code you didn’t write. If you want smaller chunks, read pull requests on GitHub rather than whole repositories

1

u/Annual_Berry8043 18h ago

The PR suggestion is a great idea. I might try that tonight. Thank you!

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.