# Separate complex projects into header files

**URL:** <https://forum.arduino.cc/t/separate-complex-projects-into-header-files/976827>\
**Category:** Programming\
**Created:** [April 3, 2022, 6:38pm UTC](https://forum.arduino.cc/t/separate-complex-projects-into-header-files/976827 "2022-04-03T18:38:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![asuryan](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/asuryan/32/1126725_2.png) [@asuryan](https://forum.arduino.cc/u/asuryan)\
**Post date:** [April 3, 2022, 6:38pm UTC](https://forum.arduino.cc/t/separate-complex-projects-into-header-files/976827/1 "2022-04-03T18:38:12Z")

</div>

Hi there!

Im familiar with OOP (coming from C#, Swift, Obj-C) but I was just wondering if it is bad/good practice in C++ to separate methods/properties of large projects into separate .h files and include them in the main .ino file so I have access to them.

To me it seems to be a good approach as I can group methods/properties that belong to each other into separate files and keep the main .ino file slim and clean (if its nothing that definitely needs to be a class/object).

Good or bad practice?

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [April 3, 2022, 7:02pm UTC](https://forum.arduino.cc/t/separate-complex-projects-into-header-files/976827/2 "2022-04-03T19:02:42Z")

</div>

yes, it is the same as for C++ development. ino is at build converted to a cpp file.

but it is also possible to use multiple ino files. is is less encapsulated, but you don't have to maintain the .h files. the ino files are at build concatenated and converted to one cpp file. (the concatenation ordering is the main ino file and then the rest is order by file name)

[https://arduino.github.io/arduino-cli/0.21/sketch-build-process/](https://arduino.github.io/arduino-cli/0.21/sketch-build-process/)

my large project [https://github.com/jandrassy/Regulator#sketch](https://github.com/jandrassy/Regulator#sketch)

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [April 3, 2022, 7:05pm UTC](https://forum.arduino.cc/t/separate-complex-projects-into-header-files/976827/3 "2022-04-03T19:05:41Z")

</div>

consider a program consisting of 10000 lines of code - do you

1. have a single file containing the 10000 lines of code
2. have multiple files (e.g. .h and .cpp) which break the program down into logical components which can be specified. implemented and tested semi-independently and built up into a complete system

do a web search on _modular programming_ you will get plenty of links

I tend to have an .ino file containing setup() and loop() and the remainder of the code in .h and .cpp files.

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [April 3, 2022, 7:18pm UTC](https://forum.arduino.cc/t/separate-complex-projects-into-header-files/976827/4 "2022-04-03T19:18:30Z")

</div>

Here are some [Basic Guidelines](https://forum.arduino.cc/t/organising-code-for-a-large-scale-modular-project/591328/5).

---

<div class="post-metadata">

**Author:** ![asuryan](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/asuryan/32/1126725_2.png) [@asuryan](https://forum.arduino.cc/u/asuryan)\
**Post date:** [April 4, 2022, 7:24am UTC](https://forum.arduino.cc/t/separate-complex-projects-into-header-files/976827/5 "2022-04-04T07:24:14Z")

</div>

Thanks for all your answers!

As far as I understand I can use either

1. simple .h files and include them
2. write multiple ino files in the project directory (where the main file is the file that is named like the directory) and dont worry about to include them as they are included automatically by the compiler
3. write cpp and h files (separate definition and implementation) but not actually create a class but just a namespace

To split a large project into more managable pieces, right?

So this is actually a technique and nothing I have to worry about that it is bad practice to do so?

---

<div class="post-metadata">

**Author:** ![hammy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hammy/32/238813_2.png) [@hammy](https://forum.arduino.cc/u/hammy)\
**Post date:** [April 4, 2022, 7:51am UTC](https://forum.arduino.cc/t/separate-complex-projects-into-header-files/976827/6 "2022-04-04T07:51:11Z")

</div>

You can of course use tabs in the IDE to keep track of those ino files

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 1, 2022, 7:52am UTC](https://forum.arduino.cc/t/separate-complex-projects-into-header-files/976827/7 "2022-10-01T07:52:03Z")

</div>

Closed on October 1, 2022, 7:52am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
