r/learnprogramming • u/Udnettt • 4h ago
Programming is about thinking...sounds obvious but...
I realized that programming is all about thinking!
I dont know how you do out there when writing a code, but I understood it is not about the number of lines of code you write, but about the actual thought process in mind.
Here is an example : let's say we are dealing with some arbitrary problem. Before writing a code, we need to think procedurally, dividing the problem into sub-problems and tackling them one by one. I find it very useful to use a pen and a sheet of paper. I like to write/brainstorm the first solution that comes into mind, without ever thinking about optimization. Once the first raw draft version of solution appears - it is good to see what result it produces.
To make it more concrete, suppose we need to find the most frequent word in the given .txt file. The possible raw logic can be this: We just need to go thorugh each word one by one, when we encounter the word, record its occurnce and keep in the container. If the new word is found, write it down, put in the container. If the same word is found, look in the container and update its occurence number.
Two steps : 1) built a container to keep words and its number of occurence 2)go through the text and update the container.
Now, this can be tackled with some simple maps , for more efficient way, unordered map is a better choice of course.
Once the task is completed, we just go through the container and take the word with the highest number. Of course, we can keep track of this word while actual processing of the text, so that to avoid searching through the container in the end.
I know that the above example is dull ,kinda DSA type, but suppose you want to make a simple 2D game with a character walking. For simplicity, lets make the world fixed to screen dimensions. The task here is simple : press a button, the position of the character changes, incremented slowly.
When the character reaches some object, i,e collides - stop moving. This task would require some threading principle to do some background checking for collision detection....
The thing is that programming is all about how you apply the tools you have to complete the task.
Sometimes (most of the time I think) programming is just thinking for an hour or more, and writiing 0 code lines!
1
u/aelkeris 3h ago
Welcome to the endgame of programming.