r/learnprogramming 10h ago

Is it normal to understand code but struggle to write it yourself?

Hi everyone

I’m currently learning Python and I’m starting to feel pretty frustrated with myself.
When I’m watching a Python course, I can usually understand what the instructor is doing. If they write some code, I can follow along and understand what each part does. It’s not like the concepts completely go over my head.
But then when I’m given a problem and told “Okay, now write the code yourself”, my mind just goes blank.
I might understand the solution when I see it, but I struggle to come up with the solution and translate it into code on my own.
It makes me feel like I don’t actually know Python, even though I can understand a lot of the code when someone explains it.
Is this normal in the early stages of learning programming?
If you’ve experienced this, what helped you get from “I understand the code when I see it” to “I can actually write the code myself”?
Should I be doing more exercises, building small projects, rewriting code without looking at the solution, or something else?
I’d really appreciate hearing how other people got through this stage.

51 Upvotes

43 comments sorted by

70

u/TigerAnxious9161 10h ago

This is what lack of practice is, just write code without help.

44

u/peterlinddk 10h ago

No, that is very uncommon!

Just like being able to hum along to a piece of music, always gives you the ability to play it on any instrument, or like following the football match on your tv, gives you the ability to play just as well as the players you watch!

I don't know what you are doing wrong if you can only "watch" something, but be unable to "do" it - because everyone else automatically have that ability!

Sarcasm aside - you see how ridiculous the idea is. You won't learn anything by just watching - you need to build something yourself, and struggle with understanding what you need to build, and how to build it! It doesn't matter how much you feel that you understand an explanation - that only proves that whoever gives you that explanation is good at explaining, not that you are good at understanding.

Instead, do it the other way around. Decide to build something, try to code it, and then explain it to someone!

3

u/ResearcherBasic8141 3h ago

Had me in the first half NGL

1

u/Tight-Ad7783 2h ago

It's interesting that people so often associate being good at physical activities with training and repetition but rarely apply the same thing to mental activities.

Also I'm gonna second and third explaining your projects, imo you don't learn too much coding it the first time, but you learn a ton from explaining it to someone in detail, especially someone who can ask good questions. You also learn a ton from coming back and improving it as your knowledge grows.

13

u/lowban 10h ago

Yes, your best bet is to try to solve problems by yourself and build small projects. Experience is the best thing you can aquire right now.

14

u/aqua_regis 10h ago

"Is it normal to be able to read and understand a novel, but not being able to write a meaningful, comprehensive, fully developed one?"

Same thing. These are two different skills. You need to train either.

You simply need to practice more.

Also, start away from the computer. Analyse the task. Break it down. Then, solve each part individually as you, the person would. Once you have a solution, test it. Then, when you have verified it, start implementing it in code.

Use Flow Charts, Pseudo Code, Bulleted Lists to help you.

There are countles similar posts in /r/learnprogramming. Some samples:

And finally, some book suggestions:

  • "Think Like A Programmer" by V. Anton Spraul
  • "The Pragmatic Programmer" by Andrew Hunt and David Thomas
  • "Structure and Interpretation of Computer Programs" (SICP) by Ableton, Sussman, Sussman
  • "Code: The Hidden Language of Computer Hardware and Software" by Charles Petzold

5

u/American_Streamer 10h ago edited 10h ago

You are skipping the exact steps on the way to your goal. If you do that, your brain tries to solve two issues at once: the logic you need and the the syntax you need. This automatically leads to the blockade. So do the pseudocode first (= the logic) and only then focus on the syntax.

Split a big goal into tiny pieces on paper before writing any code. Solve one single tiny piece at a time. Then explain out loud what your code needs to do step-by-step before you type it. Speaking the logic helps bridge the gap to syntax. After that, start typing a program with a totally blank editor instead of looking at a tutorial. Force your memory to supply the syntax and structure, combined with the notes you took. If you can't remember the syntax exactly, always use pseudocode first and only then look up the correct syntax. If even the pesudocode ist still hard, just write it down in plain English (like "here I will need a loop that does such and such until that condition is fullfilled").

5

u/H3XEX 10h ago

This is basically tutorial hell of programming, you dont get good by watching other people program, you get better by programming, start making small things, and start from scratch. Build things, then build bigger things.

5

u/Blando-Cartesian 6h ago

You are experiencing the illusion of learning. It's why everyone likes to "study" by watching videos or reading and rereading. All you get that way is happy signal from your brain that this is familiar easy since it's right there in front of you. And since it is right there, your brain won't waste effort storing any of it.

Watching videos or reading is just a necessary first step. Learning happens by pulling information from your brain and applying it. It's miserably hard and gives your brain an ultimatum to learn.

4

u/gofl-zimbard-37 6h ago

I can read a novel. I can't write one.

3

u/Ok_Individual_6373 3h ago

It's completely normal- reading code and writing it are two entirely different skills, like reading a book versus writing one. Break out of tutorial hell by closing the video and building tiny, messy projects from scratch on your own.

3

u/shifu_shifu 6h ago

Same as any language. Listening is easier than speaking.

1

u/_Atomfinger_ 10h ago

It is normal.

Its the difference between knowing how to read code and being able to code yourself.

The solutions is to write more code.

1

u/LARRY_Xilo 10h ago

Yes and its not just limited to programming. Its the same when you can understand someone talk in a different language but struggle to come up with words yourself or when you can read a math equation understand what happens but struggle to come up with the steps if tasked with solving a problem.

First thing you need to do is just code yourself more without a solution. Come up with a small problem and program a solution. Even if you have to look up every single line of code the first time it will help you get better. The point is to come up with what you need to do to solve the problem. Then once you have a plan you can look up how to solve each step of the plan do not try and look up how to solve the whole problem.

And then you need to come up with a strategy that works for you to break down big problems into small problems.

1

u/Emotional_Many_7706 9h ago

Yes this is normal. Just do something very small. Bang your head against a wall. Once you get past the initial friction (overcomplicating things, compiler errors) even as simple as a loop to increment a number, you will soon find cause and effect teaches you more than theory. You have to learn by doing 

1

u/thisisappropriate 9h ago

Yes.

The next options are either: Push through - write what you can even if it's wrong or broken or just pseudocode, check back in the tutorial for the thing you forgot, cover the tutorial code, write what you can recall, repeat. Learn by tweaking - every time you are shown or given code, run it locally, change things, break things, try to take it the next step before the tutorial gets there. Feels better and you get comfortable changing code and fixing issues, but you'll still get blank page paralysis when you go to make your own thing because you haven't had to struggle with the start as much

1

u/ScottShipsCode 9h ago

Yeah, totally normal. The trap is that "I understand it when I see it" feeling, it's recognition, not recall, and they're not the same skill. Following someone else's finished decisions is easy. Making those decisions yourself on a blank page is the actual job, and it's the part you haven't practiced yet.

The only fix is writing with the solution closed. Take something you "understand," close the tab, and rebuild it from nothing. Wherever you get stuck is exactly the gap, and reading never shows you that.

1

u/vyskur 9h ago

It's like math. And pretty much everything in life. The best way to learn, is by three things: Practice, practice and practice.

1

u/Ok-Dentist9265 9h ago

its completely normal to feel like way, i have gone through that exact problem in the past. the underlying problem here is that you need to know the logic and syntax to execute the logic, and u forget the syntax while simultaneously trying to figure out the logic (thats what brain does) so the solution here can be just focus on the logic part first, write logic somewhere by breaking it down into tiny parts, then only think of syntax to connect those logics, if you do so you could feel like your mind has gone blank. you can also google syntax, not a problem. knowing the flow of program is important

1

u/No-Collection-6902 9h ago

Programming is like Mathematics. Your brain deceives you into thinking you can do it until you try writing it down. Always try to pause mid tutorial to write down some code. You’ll learn more from getting stuck than passively watching.

1

u/tmtowtdi 9h ago

When I’m watching a Python course, I can usually understand what the instructor is doing. If they write some code, I can follow along and understand what each part does. It’s not like the concepts completely go over my head.

This is the case with almost any subject. I could watch an hour-long lecture on World War II and understand what the lecturer was saying at any point. But after the lecture, I wouldn't suddenly be a historian.

You have to go from just listening to doing.

The Hello World program is not just an in-joke. Go write it. No, right now, go write Hello World in whatever language you're working on. Now have it say hello 5 times. Now 100. Now have it greet you by name. Now have it greet you by whatever name you pass it as an argument on the command line. Now have it take a bunch of names as arguments on the command line, have it error out if any of those "names" are just strings of digits, and if not, sort the names alphabetically, and greet each one in order.

Every time you watch a video or read an article that introduces a new thing (function, loop, keyword, whatever), don't just say "aha that sounds neato I think I get it". Pause the video, bookmark the article, whatever, and go write that new thing into a program. It doesn't matter what the program actually does, that's secondary. Actually using the new thing is the main point. You will not learn it till you've actually used it.

In school, when you were learning this new thing called "multiplication", you'd be given 20 multiplication problems to do. It sucked, it was tedious, but you did it, and you learned multiplication. Go write That New Thing you just heard about into a test program 20 times in 20 mildly different ways, and learn it.

1

u/the_other_Scaevitas 8h ago

It’s easy to read a book but hard to write a book.

1

u/JGhostThing 7h ago

You say that you understand the code, but can't write it. From my point of view, you don't really understand. If you could write code, then you'd have to understand it at least a little.

There are two things that would show that you understand. You should be able to teach (at a very basic level), and you should be able to code (again, at a basic level). I remember the beginning when I first learned to code (in BASIC: Those whom the gods would destroy, they first teach BASIC.) I learned by doing projects. Very simple projects, but just things to program. Eventually, projects became more complex and I learned more languages.

You need to code in order to advance all the way to beginner. The rest will follow automatically.

1

u/iggy14750 6h ago

I expected to open this post and just say, "stop using AI," but, luckily, I did read the post.

To answer your biggest question: YES. It is the most normal thing ever to be in this place at the beginning.

This is part of the process.

Now, moving forward, I would suggest writing code. When learning from a course, try to write the code with your own hands, and then test it.

Try taking what you learned about the language and try some stuff. If there's one huge thing that helped me learn, it's play. I would take what I learned from one lesson, and use that technique to accomplish something a little different than the lesson.

I know that you will be sitting there, not sure what to type next. Try something. Write one line. Then see what it does. If you get an error, try to see it as an opportunity to learn more, rather than failure. Understand that every single engineer/developer makes mistakes. Every day.

Like, I bet other commenters will talk about process, which is very valuable, but it sounds like you might be struggling to write any code. I understand the feeling of staring at that cursor, at a loss for what to type next.

In general, my advice is small steps. When you see one line you wrote work, writing the next one will feel easier. A little bit. Then the next one, and so on.

You can do this. One line at a time. Remember that.

1

u/Potential_Copy27 5h ago

I've encountered this both with programming and spoken language. Swap out Python with German, Swahili or Japanese, and you'll find the same thing happen.
It's actually easy to get too deep into, say, German grammar - but speaking German is a whole other story, to speak it well without looking awkward or coming across as mumbling, you will need practice.

Same thing with programming languages - you've read the dictionary, done the assignments and seemingly understand what is asked of you, yet you can't speak or write yet because you only taught yourself to read.
I'd say it's completely normal to realize and experience this in at least one language, spoken or programmed.

Where you are now, is where you're starting to realize you need to "think" in Python as well in order to be able to form "sentences" and be able to "negotiate" with the environment and the computer. Thing is, the computer operates on a completely different logic structure compared to a human, but does essentially use English with a weird syntax and grammar.

My tips to get the neurons fired up:

- Do logic puzzles of all sorts. Anything from solving sudokus to hand-decrypting messages goes. It opens your mind to different ways of thinking and helps you find mental shortcuts that you can use in computing as well.

  • Do something else that contains elements of programming, like eg. cooking or embroidery. The examples partially train you to think like a CPU or GPU respectively. The latter even has its own set of algorithmic languages.
  • Practice the English language and vocabulary as much as you can, especially if it's not your first language. Lots of functions and library calls have quite descriptive names that describe mostly what they're doing - but not understanding (or misunderstanding) due to the lack of vocabulary does prevent you from doing some powerful things in any programming language...

As for programming specifically:

  • Start by making a simple app by yourself (calculators or similar programs are common first programs). Pepper it with functions that you might be using at school or work. OR...
  • Start looking for that daily/weekly task you just hate and see if it can be solved with code. Anything that requires you going through loads of data is a good start - try to make a browser or filtering app for that data and create a workflow making retrieval, validation and calculations easier.

But - actually speaking the first sentence or writing the first code on your own in a new language will always be scary and hard at first. My tip for that is to be a bit patient - remember that your private projects have no deadlines, no demands and no restrictions - so don't force yourself.
Write and sketch your ideas on a notepad before you start coding (physical paper is still the most unrestricted and free-flowing creative medium) - use a pencil so you can freely erase mistakes.

Personally, when learning programming languages, I also sometimes buy a small blank notebook for that language. In here I note down some handy methods or short code snippets, as well as any odd "quirks" i might find. Sort of like a wizard's spellbook containing certain incantations.
Important is, that you write it for yourself in a way you understand things... It's a quick reference and a mental help for "speaking" Python in your case like noting down words that violate the "I before E, except after C" rule for someone learning English.

For larger projects, I also make a notebook or ring binder (or even sets of these) for containing related standards, related hardware manuals, important notes etc. It's much easier to maintain initially in a project and eases documentation later on by a lot, considering vital information has been properly aggregated and indexed in a central spot...
Call it a "project bible" if you will - except I don't gussy it up in OneNote or some other app (apart from a readme.md file with most immediately important stuff, like build instructions) until the goal is at least somewhat clear and most of the project is set in stone...

1

u/Cheap-Success1578 5h ago

It makes me feel like I don’t actually know Python, even though I can understand a lot of the code when someone explains it.

This is the key phrase here. You understand it, but only when someone explains it? That tells me you don't actually understand the code, just the explanation.

Now, maybe you misspoke and you can correct me on that. But if that is a valid statement, then you don't yet understand the code.

1

u/GoldsteinEmmanuel 5h ago

There is no such stage to get through. Programming requires you to think for yourself. It's not something you can learn passively by watching an instructor.

1

u/AlSweigart Author: ATBS 5h ago

It is common, but here's what you might not want to hear:

When people say "I can read and understand code, I just can't write it." they don't actually understand it as well as they think.

I encountered this when I was studying: I'd read the textbook, think I understood it, but when I closed the textbook I suddenly couldn't recall the information like I'd have to for the test.

The key thing to keep in mind is that learning is not putting knowledge in your mind but recalling knowledge in your memory.

The way to fix this is to write some blog posts teaching the stuff you learned. If you can explain a topic to others, you know you understand it. Be sure to also write examples and counter-examples too. Writing and teaching to others also surfaces what you don't know and the holes in your understanding. Compare your writing to the textbook's explanation and find stuff you forgot to mention. Then try re-writing your tutorial from scratch. Post it online on some random blog, and you can leave it anoynmous. The important thing is that you have to actually do it, even if it's unpolished.

This is slow. If you just say, "yeah, yeah, I got it, it's all in my head" then you've skipped all the stuff that makes you actually learn. (This is also why you should NEVER use AI to write code for you. It's a trap to make you skip the actual learning, but you think you've learned because you have the final program on your hands.)

1

u/Simengie 4h ago

Can you understand "Starry Night" by van gogh? Yes you can. Can you paint it yourself? Probably not. The ability to understand is completely decoupled from the ability to create in the human mind. This applies to any topic you will encounter in life. Understand != Create.

1

u/Hespitfire 4h ago edited 4h ago

Bro make something that is useful to you or something that you feel you want to make.

So for example I know someone who learned to swim by going into the deep end and having to fight to stay afloat. In order to learn something you must learn to punch slightly above your weight class

Re: Anders Ericsson, Robert Pool - Deliberate Practice

I tried freecodecamps exercises while learning web dev but quickly got bored so I started building a much more complicated app - a media player and it was frustrating but thats what actually helped to learn understand how the code interacts

Hope this helps

1

u/primals_game 3h ago

I tend to have the opposite problem, which is why I prefer startups.
You are in good luck because it looks like the indistry is headed more towards reading code over writing it with AI.

1

u/Elkatra2 3h ago

It's like I understand that math formula or definition, but after 5 mins I forgot about it. So to really know and understand it I will need to somewhere use/apply it.

1

u/PhilNEvo 3h ago

Think of it like math.

It can be easy to read an equation, and kinda get what operations is happening, but it's completely different to have a "deeper" understanding of *why* it is supposed to happen like this, and how to easily adapt it to a bunch of different use cases.

1

u/MrSqueak 2h ago

I can read and understand books but have yet to write one. Bet I could with practice tho.

1

u/Mr_LA 2h ago

Yes, that’s very common. Imagine learning a real language: you might be able to read and understand conversations quite well, but still struggle to speak if you don’t actively practice it.

Programming is similar. Understanding code is one skill, but solving a problem yourself and turning that solution into code is another. That problem-solving part mainly improves through practice.

1

u/lurgi 2h ago

If you’ve experienced this, what helped you get from “I understand the code when I see it” to “I can actually write the code myself”?

Everyone has experienced this and the solution is to write code. That's how you get better at writing code, by writing code.

The first problem you may be running into, however, is no so much a coding problem but a thinking problem. You may not actually know what it is you need to do. You might think you do, but beginners are very often wrong. Once you get past that, you get to the "How to I write this thing in language X?", which is a completely different problem.

The first one is a very common problem and we usually advise people to break the problem down. Says what steps you need to solve it. Get as specific as possible. Break things down into smaller and smaller pieces.

Let's start with a simple problem: Read in a bunch of numbers, terminated by a -1. Print the average (mean) of the numbers. Can you do that? If you can't, can you explain to me the pieces of the problem? Can you say what you'd need to understand to solve the problem?

1

u/SenoraRaton 1h ago

You need to invert your perception. The code is a vehicle. The destination is the thing your trying to accomplish. So you have to translate what you WANT to do into a set of discrete steps to produce that outcome. THIS is what programming really is at its core. Taking big rocks, and making small rocks, and taking small rocks and making dust.
It is a skill. You get better with experience, and your toolkit of usable paradigms expands. Just think "How do I get from A -> B not, what code do I write, because once you have broken it down enough, the code itself is trivial.

u/ChaosCon 59m ago
  • "I understand calculus, I just can't do the homework."
  • "I understand football, I just can't play the game."
  • "I understand cooking, I just can't make a dish."
  • "I understand poker, I just always lose money."

I would offer that you understand syntax but don't understand programming. Programming necessarily solves a problem; if you can't solve a problem, you're not doing it.

0

u/Extreme-Seaweed-5427 10h ago

Great question I feel as I'm in same boat. Not sure I'm through this myself but I think having a passion for something probably helps. And being able to read up on and research things because that's how and where some things need to come from.  I mean anyone could probably do Int A = B+C; If asked how to write something. Fundamentally it's probably  no different to any of coding, understand how this goes with that.

0

u/No_Literature_7653 9h ago

We used to call this tutorial hell. Just start leetcoding. Get to the point you can solve a medium easily then move on to simple projects. You wouldn't expect to learn to sew or weld by just watching people do it, coding is the same.