you write first the main function, that calls stubs, then you subdivise these stubs in smaller stubs until a real work has to be done, that you code in the final files.
you write (or gather) small components that do basic actions that are required to do the full program work. Then you assemble them by custom code, then assemble these parts to write the main method.
The reality is seldom one or other approach, but a combination of them.
What is certainly wrong is trying to start coding from the middle ...