Jump to content

Recommended Posts

Posted

I was wondering why #include-once is an option. It would be good if it was the default setting.

All I see in the help file is:

It is not recommended to add a #include-once line to scripts which are not intended to be used as include files within other scripts.

Why is it that bad to have it in scripts which aren't going to be included?

 

Thank you in advance.

Posted (edited)

the help file is really good

It is quite common to have the same "#include <filename.au3>" line in several of the files included included in a script. If the same file were to be included several times, it is quite likely that this would generate a "Duplicate function" or "Cannot redeclare a Const" error. So when writing a script intended for use as an include file, add #include-once to prevent that file from being included more than once. Note that the #include-once line must be placed at the top of the script and before any other #include lines.
 

regarding that last line, I think it means, if you don't intend to include the au3 file in anything, don't add that to the top. I use the include-once to make my udfs global to the main script. you can use the udfs everywhere then, and only include once overall and logically (all you need is one instance). log4a.au3 logger is like that as well as my WaitForControls.au3

 

it's most likely the way the compiler deals with include files--I can't tell, can't see source.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted
7 hours ago, IAMK said:

I was wondering why #include-once is an option. It would be good if it was the default setting.

The directive exists  because as explained above, you can't add the same functions to a script or you'll get errors.

N.B. - The below is just conjecture:

The reason it's not the default is because it probably adds overhead to the interpreter at run time or compiling time to have it try and determine whether the file has already been included once before. And you don't use it in a script that's not an include for that reason. It probably has to check every file name included every time the script is run or compiled. And by script I mean an uncompiled script being run by the AutoIt3.exe program.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

@Earthshine I have 2 types of scripts:
1- AutoIT_Name.au3
2- AutoIT_Func_Name.au3
Scripts with Func in the name are never compiled, and are only there to be included by other scripts, and to ensure there are no duplicate definition errors, I use #include-once in them. The scripts without Func in the name are never included, so there is no reason for me to use #include-once.
However, I still don't see why #include-once isn't made the default, as it doesn't seem too harmful to have it in all of my scripts.

@BrewManNH Yes, so I assumed that the overhead would just be that the compiler checks other files which include it.
With that being said, I can't see that taking more than milliseconds, and it's only done once for each file used (before turning the script into a single .exe which won't have to ever check this again).

Posted

Feel free to do it how you'd like, there's nothing holding you back from using it. It's just not the default because it doesn't need to be. Putting unnecessary directives into a script like this one won't break anything, just adds to the overhead and unneeded typing.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...