Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Working with multiple #includes....

Engaged ,
Jun 05, 2023 Jun 05, 2023

 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?

TOPICS
Scripting
200
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jun 05, 2023 Jun 05, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 07, 2023 Jun 07, 2023
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines