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
    41 year ago

    Is this with your own code or someone else’s? It’s always harder to understand someone else’s code (at least at first). Everyone thinks and writes in a different way.

    In either case, I think you could benefit from stepping through the code in a debugger. Depending on what the code is, give some data as input where you know/can guess what the output is. Using the debugger, step through each line to see what happens to the data. It can help break down long or complicated functions into simpler chunks.

    Recognition of functions or snippets of code will come through repetition and exposure. Writing code helps more than reading as well. Even with all of that, it’s still okay and common to have to look things up or review. I constantly have to check the syntax of C++ library functions, like snprintf, which I have used but not enough to memorize (and that’s okay). Don’t be discouraged. I’ve been in my career for 11 years now, around 9 of which is working with embedded C++, and I still feel like an imposter.