Reference examples should include #include's

Hello, Particle team,

Would you please update the examples to include the appropriate header files?

For example, in the software timers, doing #include "header.h" would be really helpful.

Thanks!

Could you be a bit more specific, since I don’t need to include anything for the software timers to work(?)

Sure. Create a standalone class in a separate file that needs a timer.

Have you tried #include "Particle.h"?

No, but why would I want to include anything more than what’s necessary?

If the Timer class needs to #include things, it should. If it doesn’t need them, it shouldn’t include them. Same principle.

i.e., if I don’t need stdlib.h, I don’t #include it…

Only actually used modules will be linked.

Unless you prefer writing dozens of include statements over just having one while the binary will be no smaller your way.

And why? I'd guess because you want to save yourself the extra work. But if you did, your binary wouldn't be any bigger.

The firmware API is accessed by including Particle.h - if you include specific header files, you risk your app breaking should we need to rename any headers. Of course, we try to preserve backwards compatibility, but the names of headers are not strictly part of our public API. E.g. there are many headers that start “spark_wiring…” these will be renamed.

You mention that you want to only include what is needed, but why give yourself that additional work? It won’t make any difference to the resulting executable and I doubt you’d notice the change in compile time.

By only using one header, we considerably reduce the cognitive load for new users, so they don’t have to remember in which header file each feature lives. That amounts to quite a lot less things to remember. :smile:

5 Likes

I brought it up on the IRC channel, and one of the Particle guys asked me to post this here to remind him.

Do you happen to know which one ;)?

Of course I do.

Well, if you tag him in here, he’ll get a notification, otherwise this won’t be much of a reminder, would it?

Questions like this usually imply the question: "And who was it", even without explicitly saying it :wink:

1 Like