As a beginner, how should I go about learning difficult concepts? - eviltoast

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.

  • simonced@lemmy.one
    link
    fedilink
    English
    arrow-up
    7
    ·
    edit-2
    1 year ago

    Her is my take to try to help you.

    If it’s your own code, you can add docstrings comments to your functions, so you don’t have to re-read the function body everytime. Also, name functions to be understandable more easily when possible.

    If not your code, write on a piece of paper (not on computer) the in and out of a function, maybe like so:

     [1,2,3] -> (sum function) -> 6
    

    Then, you can even connect the functions together and see the whole algorithm:

    [1,2,3] -> (sum) -> (multiplyBy2) -> (...) -> final_result
    

    When projects get more complex, paper will not cut it, then some note taking app of some sort will help. (logseq could help, but some mind mapping or sequence diagram programs would help as well)

    Also, I don’t know what language your are working with, but learning LISP (maybe clojure) could help.
    Why? Because you have to connect your functions together, and it forces you to do so.
    At first, it might be harder compared to what you’re used to, but it’ll give you better fundations to keep learing.