Working with multiple #includes....
Copy link to clipboard
Copied
As there is no way to include a header guard (from what I can tell) in extendScript, is there any harm in having the same #include line in multiple files that may get included multiple times by the final script?
Explore related tutorials & articles
Copy link to clipboard
Copied
Hi @jsavage77, I'm not anything of an expert on this exact topic (and hopefully you'll hear from one of them soon) but I've done a lot of scripting and here's some notes on your question:
1. 'including' a file in ExtendScript seems to just run that file at the time the interpreter reads the include directive. You can test this by simply putting alerts at different places in the included file.
2. ExtendScript will run the included file again if it has already been included before.
3. Therefore, the answer to your question "Is there any harm...?" is almost certainly depends on what the code in your included file does when run more than once.
There are ways to reduce the impact of accidentally including a file more than once, depending on the architecture of your code. For example, if your included code creates an object then, at the start of that included file, you can put in a check to see if that object already exists and if it already exists then don't bother making the object again.
Anyway they're my quick notes. There are some folk here who are really knowledgable about the workings of this sort of thing, so we might hear from them too.
- Mark
Copy link to clipboard
Copied
I'm not an expert either, but #include is just a way to share global variables (including function declarations) between files. To avoid reference errors, put the #includes at the top of the script. If an included file uses variables from another included file, make sure the #includes are in the logical order.

