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
    68 months ago

    The name of the function, what goes in and what goes out in most cases should be enough to get a good idea on what the function does.

    It also helps to make a diagram of how everything ties together. Just boxes and arrows is enough.

    When writing your own code, it takes a bit of experience to know when to put something in its own function. It’s very obvious when you’re replicating code. It’s also very common to cut things up when a function gets too big. Look for bits of functionality that you can give a good name.