After reading up on TABS (they compile sequentially, after eponymous file), I started renaming them appropriately.
The idea was to get something like this:
A00-Main Program, contains explainers
A10- contains #includes, #defines, variable declarations etc
A20- contains the setup
A30- contains the main loop
B10.... subsequent functions.
I started moving sections of code into the new tabs, starting from the backmost, compiling after every move...
Made it to moving the main loop into A30...
After that the B category tabs started throwing "not defined" errors.
I even tried to move the whole shebang, A10-A20 from A00 to A10, nothing going...
If each of your files ends in ".ino" the IDE will combine them all into one single file to do the compile. The IDE will also auto generate function definitions and place that information at the beginning of the combined file. You can run into issues based on how things are all stuffed together before it is compiled.
If each of your files ends in ".ino" the IDE will combine them all into one single file to do the compile. The IDE will also auto generate function definitions and place that information at the beginning of the combined file. You can run into issues based on how things are all stuffed together before it is compiled.
Thanks Blh64,
How do you suggest I divide my code for readability/editability? Isn't that what those tabs are for after all?
Strange tab names- why don't you name them something more meaningful?
If you don't specify a suffix, the tabbed files are all *.ino and the compiler processes them from left to right. (Not precisely correct, but it helps with the visualization).
Your error is putting the includes and defines after the main tab. It would be the same as
void setup()
#includes
#defines
void(loop)
Which won't compile.
My projects are getting pretty complex and I have found that splitting the functions into tabs has helped make my main section easier to manage. It also makes my functions more portable into other projects.
If you want to see a ridiculous number of tabs, check out tasmota.
SteveMann:
Strange tab names- why don't you name them something more meaningful?
If you don't specify a suffix, the tabbed files are all *.ino and the compiler processes them from left to right. (Not precisely correct, but it helps with the visualization).
Your error is putting the includes and defines after the main tab. It would be the same as
void setup()
#includes #defines
void(loop)
Which won't compile.
My projects are getting pretty complex and I have found that splitting the functions into tabs has helped make my main section easier to manage. It also makes my functions more portable into other projects.
If you want to see a ridiculous number of tabs, check out [tasmota](https://github.com/arendst/Tasmota/tree/development/tasmota).
Thanks Steve,
I understand that the Compiler compiles in alphabetical order after the eponymous file.
Hence the Axx Byy nomenclature, followed by the "meaningful" name. A is for main code sections, B is for functions. The numerals allow me to insert stuff without having to renumber a bunch of stuff... Like chapters in a book.
If it is compiling left to right, it would then be following the alphabetical order.
Now, A00 (eponymous file) contains explantations,
Followed by A10, with includes and Definition, then
A20 with void setup and finally
A30 with void loop...
From where the code stands now, when I move void setup() into the A20_SetUp loop, it should be AFTER the definitions and BEFORE the void loop, compiling in the same sequence... But it doesn't...
gfvalvo:
For a much better (IMO) technique of using multiple files / tabs, see Reply #3 Here.
Thanks gfgalvo;
While I concur totally with your suggestion (I actually read this post while doing my research), my programming acumen is not at a level of writing classes yet. I feel that I'm slowly getting there though, hemming and hawing. Trying to get this project to stand on its own legs, before I start the beautification process.
Not sure, if I should interrupt the design process and concentrate on library building instead...
Robin2:
They are not compiled sequentially but they are combined sequentially (in the order you describe) into a single .ino file.
This means that something defined in A can be seen by code in B but not vice versa.
...R
OK, understood. Best explanation yet. Thanks for that Robin!
I'm not going to rip out my hair trying to get the compile sequence right. For now taking the approach of having includes, definitions, variables AND setup() in the eponymous file/tab and all others in sequential tabs. In order to make the setup more legible, I call a bunch of void functions() in separate tabs.
trilife:
Hence the Axx Byy nomenclature, followed by the "meaningful" name. A is for main code sections, B is for functions. The numerals allow me to insert stuff without having to renumber a bunch of stuff... Like chapters in a book.
It's only clear to you. Today. A10, B20, etc means nothing to anyone else- or to the compiler. In a year when you revisit the program, A10 won't make much sense to you either.
As I said, giving the tabs meaningful names makes them more portable. For example, I have a tab named "setupWiFi" where I place all WiFi related functions. When I want to use WiFi in another project, I just copy the tab to the new project.
Look at the Tasmota project I linked to above. 168 tabs. Can you imagine the confusion using your tab name protocol?
SteveMann:
A10, B20, etc means nothing to anyone else
I would agree if the file names were actually like that, but it's not so. trilife appended meaningful names to the prefix that forces the correct concatenation order.
SteveMann:
means nothing to anyone else- or to the compiler
The compiler never sees these names. All the .ino files are concatenated into a single .cpp file.
For the Arduino sketch preprocessor, on the other hand, these names mean a great deal. That's the whole point of doing this.
SteveMann:
In a year when you revisit the program, A10 won't make much sense to you either.
I have sketches where I did the same thing that I wrote 7 years ago, and it still makes perfect sense to me.
SteveMann:
As I said, giving the tabs meaningful names makes them more portable. For example, I have a tab named "setupWiFi" where I place all WiFi related functions. When I want to use WiFi in another project, I just copy the tab to the new project.
If you want to share code between multiple projects, put it in a library. That's the real portability.
SteveMann:
It's only clear to you. Today. A10, B20, etc means nothing to anyone else- or to the compiler. In a year when you revisit the program, A10 won't make much sense to you either.
As I said, giving the tabs meaningful names makes them more portable. For example, I have a tab named "setupWiFi" where I place all WiFi related functions. When I want to use WiFi in another project, I just copy the tab to the new project.
Look at the Tasmota project I linked to above. 168 tabs. Can you imagine the confusion using your tab name protocol?
Ok, which part of Bxx_SendEmail is not meaningful? I achieve sequentiality in the first part and know what the Tab does in the second part.
I agree with you though, that too many tabs, if not named "meaningfully" will turn into a mess.
pert:
If you want to share code between multiple projects, put it in a library. That's the real portability.
I concur! Once I grow up to programming like you guys (I'm only 57!), I'll build libraries too! In the meantime, thanks for humoring me with answers to my naive questions.
What does proper programming etiquette dictate: do I put the #defines related to the funcions on that Tab on that tab, or do I put them at the beginning, in the eponymous file?
And, can anyone recommend a good source for programming etiquette?