Today I’ve found a reply on r/learnprogramming that best describes how to approach solving a programming problem. It was written by “desrtfx” on reddit.
As a programmer, you need to learn to think in a different way: you need to think in algorithms (and in steps). This is the biggest challenge that aspiring programmers face. The only cure for that problem is to practice, practice, practice, and practice more.
Beginners quite commonly make the mistake of directly going to the keyboard and starting to program away when they are given a problem to solve. Don’t do that. Read the problem description multiple times and then go away from the computer. Ponder about the problem, work through the problem on paper without thinking about actual programming. Devise an abstract solution for your problem (at least describe the way that you as a person, not as the computer would solve the problem). Explain the problem to an inanimate object (Rubber Duck Debugging). Give your brain time to process the information/the problem description. Do something different for a bit of time. Go outside, go for a walk, take a shower, do whatever you want - away from the computer. Get back to the problem after you have spent some time pondering about it.
A good programmer takes some time to analyze the problem before even thinking about writing a program to solve the problem. This is an essential step.
Break the problem down into smaller, easier manageable parts. (set-up with initialization of the variables, input, processing, and finally output) and then attack each part individually. This makes the whole easier to manage.
Programming is no easy task. It takes time and lots of effort to learn. The modern courses make it seem way easier (and Codecademy is extremely good in passing this feeling, but extremely bad in actually teaching) than it actually is.
There is a good book on pre-oder: Think like a Programmer (Python edition) and its already existing counterpart: Think like a Programmer (C++ edition). These books explain the thought process of a programmer from an abstract point of view. The actual programming is secondary.
Don’t give up. It gets easier with lots and lots of practice.
Original post and comment can be found here.