I’m trying to learn programming and something I struggle with the most is trying to separate code mentally into chunks where I can think through the problem. I’m not really sure how to describe it other than when I read a function to determine what it does then go to the next part of the code I’ve already forgotten how the function transforms the data and I get stuck trying to figure out the solution. So instead I’ll often cludge something together just to make it work but I don’t feel like I made any progress. Has anybody else run into this issue where they struggle with abstracting code from text to mental instructions?

Edit: Thank you all for the suggestions and advise. I wish I could reply to everyone but there’s been a lot of good information given and I have some ways now to try and train my brain to think about how to break down the code. It’s also a little reassuring knowing I’m not the first to have these same struggles.

  • @[email protected]
    link
    fedilink
    88 months ago

    I’ll often cludge something together just to make it work but I don’t feel like I made any progress

    That’s a good first step! I’ve been programming for ~25 years and that’s still usually where I start. Get a little code that compiles and produces some kind of output or tracing. Then compare the output to your requirements and tweak the code to get it closer to the right behavior. Run it and repeat till it’s doing what you want. Do this cycle with small changes, like a handful of lines or a short function, not 20 mins of coding at a time.

    Test-driven development can also help with breaking down tasks. It takes a good amount of practice to learn the right patterns, but it’s an approach that forces you to work with small narrowly scoped tasks. Then you chain those testable tasks together to create more complex behaviors to create robust testable code.

    Experience takes time. Junior developers frequently ask me after I’ve helped them “but how did you just know how to do that? I’ve been trying to solve that for an hour and you did it in 10 seconds!!” The answer is because I’ve solved that exact problem before. More than a few times.