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

    The main part you need to pick up is being able to establish the mental hooks around the ideas that are central to programming. Do you know how you can watch a choreography session and see the dancers just pick up the moves as they’re described/demonstrated? That’s because they’ve learned the language of dance. It’s an entire (physical) vocabulary. It’s the semantics of dance.

    What you need to do is do that with programming. There’s a number of getting started with books and videos, but you’re going to want them to learn the fundamentals of not just a language but of programming.

    If you’re talking about using other people’s functions (like in an api), then the function name should give you a clue about what it does. The cool thing about functions is that you don’t have to know how they’re doing their thing, just what they’re doing. If you have the source code, you will find you remember more if you use comments to make notes for yourself (it engages more of your brain than just reading).

    If your problem is writing your own code using functions, start out more slowly. Write a program that’s just a giant block of linear code. Once that’s working, then take a look as to how to break it down into functions. If you have a block of code that sorts a list, for example, and you had to copy and paste it into three different areas, that would mean it should be a function.

    Use comments very often as you’re going. Before you write a block, write a comment about what it’s supposed to do. You’ll start to see some generalities, which will be you learning programming, not just a language.