This is a great essay about not beating yourself up for feeling stupid when you try to learn something new in programming:
This might not seem like a big deal, but it's huge. Every single time (and this will happen constantly) you come across a concept that seems foreign or difficult or even just unintuitive, instead of thinking "It's OK. Programming is hard." you're going to be thinking "This is supposed to be easy. What's wrong with me? I must be stupid." These feelings will keep you from seeking help or pushing through to discover why things work the way they do, and that is what's stupid.
Programming is not always intuitive, it's inherently complex, and it's challenging. Once you start feeling like you've gotten a handle on it, you'll learn something new that will make things seem even more complex for a while. Your level of stupidity is certainly up for debate, but not being able to program without long hours of steady practice is not an indicator of intelligence one way or the other. The discomfort is normal, so get over the self-consciousness now and fight it whenever it appears in the future.
I agree, I wish I had this advice when I first entered the field. It took me the better part of a decade to come to the same realization, that you felt stupid because you were really learning a lot of new and unfamiliar stuff. It makes you grow as a developer, and as a person, and is also probably fending of future brain degradation in the process. My most recent experience was relearning the math for Where is Io.
I spent days just trying to understand what should be a simple coordinate transformation, so much so that I almost gave up the project multiple times for being too hard. But the problem was, I knew someone else had figured this out, so it couldn't be beyond me. A few weeks of banging my head against the table eventually got me past that. It would have been easy to just walk away, it was a hobby project after all, but pushing forward and overcoming the challenges made it that much more rewarding on the other side.