I was wondering, how i can split up my large and messy code into separe files (tabs). I have read a few topics here and there, but averybody is for creating beside the main.cpp file for example foo.cpp and a header file foo.h. In the header file we must specife all th function prototypes which is fine, but for a quick prototype of a code this is not the best option. Is there some better way (I would imagine something like creating a new file (tab) and write down the functions we need and so on.) Is this is a bad habbit and we should all create the .h file separatelly or is there some better solution?
Yes, I would consider it bad style to do every implementation in only header files.
That said it’s not impossible to do implementation in only header files. There are also many header-only libraries. See cxxopts. But, be aware of the downsides.
As Max said… it is a bad habit… which Arduino has encouraged by the virtue of their preprocessor creating the function prototypes for you, and automatically combining the code of all the tabs without any need for
For something quick 'n dirty, you could implement it as a
.h only, but I really wouldn’t get into that habit. Just create the cpp file, write your functions, copy the function prototypes to your header file, add an include guard and don’t forget to
#include the header in your
main.cpp. Not as simple as how Arduino does it, but it’ll work everywhere then!
Thanks, that is exactly for what i was looking for!