How do programmers think while they program?
I work on VBA coding in Microsoft Excel!... and I have been doing so for the past 4 years.
VBA coding is done in modules and sub-routines (and functions). What that means is, you don't write all your code in one block. You divide your program into logically separate tasks, and write code for these tasks in separate sub-routines. Again, for a big program, there can be a lot of sub-routines. You can further group these into logical groups... Modules. I will be talking primarily about sub-routines.
I have very weirdly started to think of these ‘sub-routines' as "beings" or "people".
Every routine is someone I "create", with a very specific task in mind. He (or she, or that) knows precisely what to do, and they do not know what else is going on my little world. Lets call these the "experts". You call them, they do the job you expect of them and they vanish. The are even named such that it is easy to tell what they do. So it's easy to call them when needed. Often they ask questions (inputs) in-order to do their job, sometimes they give you a few answers back (outputs; in case of functions).
Then there are others who get small sub-task done. They have quite a bit of responsibilities and frequently take help from the experts, calling in a different one, every time they need something done quickly. These are like your low level managers. For every task they are assigned to do, they do some of it, when they know that an expert something, they simply call them, get the part done and move on to the next step. They can call as many experts as they want, but calls to a couple of experts, gets them by. Again, inputs, outputs, questions, answers. Compared to the experts, relatively fewer questions.
Now, you have your managers. They manage! They are very very good at getting things done, have very few tasks of their own, and rely heavily upon low level managers and experts to get things done. They simply call the right low level managers and ask them to get things done. Sometimes, they also call-in experts to do a few simple tasks. But these are experts on a larger scale. You assign them a task and they will do it, no questions asked. They hardly ever require inputs, and very few times give outputs. They simple get jobs done.
And finally there are leaders (void main, remember!). When there is a task to be done, they call a few managers, period.
The idea is, all of the experts are your super reusable code, you design them in such a way that they are useful to a lot of different managers. Low level managers are super reusable too, they do quite more things than your average expert, but know very less of the overall process or bigger picture. Managers get more task specific, they call experts, managers and sometimes even leaders from other departments to get something done. Its a coding world, if someone knows to do something you need to get done, call them.
So all these people exist, my my weird little world and in every VBA powered Excel I ever created. While coding, all of them are available to my beck and call when I need them. Of course, the number and complexities hierarchies vary. In a start-up, (again, void main) the leader does all the work, there are no experts, there are no managers, there is just one guy in a room. (yes, he is writing code!)
One more thing while creating these people, these experts-at-what-they-do, I abuse them a lot, like A LOT! If they are not doing their tasks right (because I am such a bad coder "!"), if an "expert" does not exist and I have to now create one or I don't know how to train this new expert. Codes get abused left and right when they are in development. But the satisfaction received after a successful execution, it's all the pleasure in the world!