Breaking down your project code into sub functions generally is a very good idea, as this makes your code more readable, more maintainable and more re-useable. It also avoids "copy & paste" of same code again and again. Contrarily, merging everything into the main()
function would only create messy code that is very difficult to understand and very hard to maintain. So, better do not do this at all!
Whenever you see a block of code that can be generalized into a separate function, then do it.
In order to reduce program compilation time, you should split your classes/functions into separate compilations units – i.e. separate .cpp
files with corresponding .h
files. By doing this, every time you build your application, only the .cpp
files that have actually changed will be re-compiled. All other .cpp
files will not be re-compiled (unless you force a full re-build), which can save a lot of time!