AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

new directive to support the new function statement

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
Jerry



Joined: 24 Jun 2004
Posts: 39

PostPosted: Tue Apr 12, 2005 4:10 am    Post subject: new directive to support the new function statement Reply with quote

How does it sound to have a new directive that would set the search path to find the functions? The path idea is stolen from the 'path' dos statement. I am also suggesting two variables that autohotkey maintains
1) %install_directory% <-- would be the directory path that the install program places functions that users have written and are included in the install.

2) %A_WorkingDir% <-- the working directory

Eg. #IncludePath c:\my functions;install_directory;%A_WorkingDir%

Using this scripts would not need to specify the #include statement at the top of the script. When a function is encountered, the includePath(s) would be searched to find where the function is, if it is the first time the script has encountered the function.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Apr 12, 2005 3:38 pm    Post subject: Reply with quote

That's pretty interesting because it's more advanced, and potentially more useful, than what is typically used to implement a standard library of functions.

In many languages, you use special symbols to indicate that a #Include file is coming from a standard location. For example, if the C language style were used, you would use <>:

#include <ProcessMemory.ahk> ; For Read/WriteProcessMemory().

Your idea would avoid the need to ever do #include if a standard search path for functions is set up. Although this is convenient, it suffers from at least one major problem: performance. If there are a lot of scripts in the standard includes folder, finding the correct one and the correct function inside it might require several seconds of disk access (if the files aren't already cached). This seems an unacceptable amount of overhead to incur whenever a function definition isn't found, especially since the sheer amount of file data that must be scanned might someday be several MB. Even when the files are cached, this might be a slow and/or memory-consuming process.

Comments and contrary opinions are welcome.
Back to top
View user's profile Send private message Send e-mail
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Tue Apr 12, 2005 4:56 pm    Post subject: Reply with quote

I think the classic, standard method (<>) seems more sensible, to me at least. For one thing, I wouldn't like a few seconds of loading for basic functions that will probably become widely used, and for another, I think that way is simpler.

My two cents.
Back to top
View user's profile Send private message
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Tue Apr 12, 2005 5:53 pm    Post subject: Reply with quote

Hi,

the idea sounds good, but I see also a problem: code sharing. If you use a lot of function files, how do you know exactly which of them you are using? If you like to share your scripts, you have to find all the necessary files...

Using explicit #include statements should be better for the coding.

Another point:
You have a lot of files and you have two functions with the same name and maybe the same number of parameters. But your new script won't work as expected. How long does it take to find the old function?

DOS had a lot of good ideas, and if I remember, DOS 2.11 was carried out on a 320 kb floppy disk. The system doesn't knew anything about directories...

But with directories and the PATH variable the second problem appeared.

NiWi.
Back to top
View user's profile Send private message
Jerry



Joined: 24 Jun 2004
Posts: 39

PostPosted: Tue Apr 12, 2005 5:57 pm    Post subject: Reply with quote

I was thinking that the name of the function would have to match the name of the file, without the extention on it.

This would limit the search to just scanning the directory(s) for the function.

I'm not sure I would want the ability to embed a function in another script. And if I did, I would go back to using the include directive for clarity.
Back to top
View user's profile Send private message
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Tue Apr 12, 2005 6:16 pm    Post subject: Reply with quote

Hi Jerry,

this would be a solution. So it may be possible to use a second include statement which will search for needed function files (i.e. with suffix .ahf) in the specified directory.

On the other hand why do you need this directive? If you have a lot of functions you should know which one do you need. Can you give me an example for better understanding?

NiWi.
Back to top
View user's profile Send private message
Jerry



Joined: 24 Jun 2004
Posts: 39

PostPosted: Tue Apr 12, 2005 6:40 pm    Post subject: Reply with quote

Quote:
Another point:
You have a lot of files and you have two functions with the same name and maybe the same number of parameters. But your new script won't work as expected. How long does it take to find the old function?


Finding the old function is a matter of change management. While the new function is still in beta testing, I would put it in a different directory and place that directory first in the search order.


eg.
Code:
#includePath c:\beta script\project001;c:\my functions;install_directory;%A_WorkingDir%


The other part is "standards". It would be wise to place a section at the top of each function indicating at the least version #, # and kinds of parameters to be passed into the function, parameters that are passed out, and what the function does. And if you lose a script you can always issue the dos command "dir /s script.ahk"

Quote:
If you use a lot of function files, how do you know exactly which of them you are using?


I would embed the new variable A_LineFile in the function to be displayed if a certain value is passed to the function.


Also, if the user were to switch directories where the functions are located he/she would have to go through every script and change the #includes to point to the new location.

Anyway, that's my thought
Back to top
View user's profile Send private message
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Tue Apr 12, 2005 7:01 pm    Post subject: Reply with quote

Jerry wrote:
Finding the old function is a matter of change management. While the new function is still in beta testing, I would put it in a different directory and place that directory first in the search order.

That's right. But you will have to manage them either.

Jerry wrote:
eg.
Code:
#includePath c:\beta script\project001;c:\my functions;install_directory;%A_WorkingDir%

Ok, this is also clear. I don't think there is a big difference of the style if you use this:
Code:
#includePath c:\beta script\project001
#includePath c:\my functions
#includePath install_directory
#includePath %A_WorkingDir%

This is the same. But you also may write:
Code:
#includePath c:\beta script\project001\fun2.ahk
#includePath c:\beta script\project001\func2.ahk
#includePath c:\my functions\work1.ahk
#includePath c:\my functions\work4.ahk
#includePath c:\my functions\work1955.ahk

But this way you can alwas see which files are really used.

Jerry wrote:
The other part is "standards". It would be wise to place a section at the top of each function indicating at the least version #, # and kinds of parameters to be passed into the function, parameters that are passed out, and what the function does. And if you lose a script you can always issue the dos command "dir /s script.ahk"

Also ok, but this should be done even if there is no path which is included. This is just a better programing style Smile ok, I know, my script documentation is not as good as is could be at the moment...

Jerry wrote:
Quote:
If you use a lot of function files, how do you know exactly which of them you are using?

I would embed the new variable A_LineFile in the function to be displayed if a certain value is passed to the function.

Ok, but if the number of values are correct and you expect a string but you get a number? Or if you expect a number greater zero but you get -5?
There are a lot of problems you might run into if you do not really know which script is used.

Jerry wrote:
Also, if the user were to switch directories where the functions are located he/she would have to go through every script and change the #includes to point to the new location.

So if you use the path include you have to do this also.

Jerry wrote:
Anyway, that's my thought

The same for my thoughts.

Another example, I'm still wondering why a script will not run as expected even if it is small. And most of the problem is that I you the If clause and compare to text:
Code:
If var1 = var2

instead of
Code:
If var1 = %var2%

So I believe using a PathInclude directive may help a few people but may cause a lot of problems for many others...

But, that's just my opinion.

Maybe there is another workaround:
You can limit your functions to just a few files. The #include directive will load the file to the calling position. So if you have 20 functions in math.ahk, you can include them all, even if you just need one.

NiWi.
Back to top
View user's profile Send private message
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Sun Apr 17, 2005 10:49 am    Post subject: Reply with quote

Hi,

I've got an idea about this question:
@Chris:
Is it possible to have an additional parameter for the #include statement?

If this can be done easily, maybe it will help the whole community to use global functions, which will be provided with the AHK packet. So there can be stored some functions, divided into a few topics like
Strings.ahf
Math.ahf
Gui.ahf
and so on. All these functions should be build by Chris (not written, just put them into the files Smile ) and will be distributed with ahk. So if someone needs a function which is not used to much so it will not be part of the autohotkey.exe, it will be stored in one of these files. And a user can load this with something like this:
#include, math.ahf, system
The parameter system indicates that the file should be loaded from the installation source, i.e. %ProgramFiles%\Autohotkey\functions.
Also a new statement like #SysInclude may be possible.

What do you think about this?

As an example for "strings.ahf":
Code:
;   This script contains some functions which can be used in expressions.

MidString(__string, __pos, __count)
{
   StringMid, __return, __string, %__pos%, %__count%
   Return __return
}

LeftString(__string, __count)
{
   StringLeft, __return, __string, %__count%
   Return __return
}

RightString(__string, __count)
{
   StringRight, __return, __string, %__count%
   Return __return
}

Len(__string)
{
   StringLen, __len, __string
   Return __len
}


NiWi.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sun Apr 17, 2005 12:59 pm    Post subject: Reply with quote

This is a good approach and is probably close to what will be done. The only difference is that it seems simpler not to have a new directive or to require a new parameter, but to instead use characters that are normally illegal in a filename to flag an included file as "special":

#Include <ListMgmt.ahk>

The angle brackets in the above would signal that the file should be loaded from some standard folder rather than the script's working directory.

Also, it seems better not to have a new ".ahf" extension because in general, I think creating new extensions should be done only when there is a very large benefit. The is because new extensions increase the learning curve and the complexity of the program and its installer. In addition, a user would have to remember to associate both ahf and ahk files with their editor of choice, and configure their editor to recognize both extensions as eligible for syntax coloring, etc. Therefore, it's probably best to keep them all as ".ahk" files (but counterarguments are welcome).
Back to top
View user's profile Send private message Send e-mail
niwi



Joined: 27 Feb 2005
Posts: 128
Location: Heidelberg, Germany

PostPosted: Mon Apr 18, 2005 7:21 am    Post subject: Reply with quote

Hi Chris,

Chris wrote:
This is a good approach and is probably close to what will be done. The only difference is that it seems simpler not to have a new directive or to require a new parameter, but to instead use characters that are normally illegal in a filename to flag an included file as "special":
#Include <ListMgmt.ahk>

Yes, this is a possibility, like in the good old c language Wink


Chris wrote:
Also, it seems better not to have a new ".ahf" extension because in general, I think creating new extensions should be done only when there is a very large benefit. The is because new extensions increase the learning curve and the complexity of the program and its installer. In addition, a user would have to remember to associate both ahf and ahk files with their editor of choice, and configure their editor to recognize both extensions as eligible for syntax coloring, etc. Therefore, it's probably best to keep them all as ".ahk" files (but counterarguments are welcome).

Yes, but a file which just contains functions should not be started by ahk. Ok, this is not really a problem because ahk will just quit.

Another question is, what will the script compiler do with the functions? Will it compile all give functions or will it just compile the used functions?

Will it be allowed to stack the include statements in "function" files? (One function file may include one or more others?)

NiWi.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Mon Apr 18, 2005 4:26 pm    Post subject: Reply with quote

niwi wrote:
Will it compile all give functions or will it just compile the used functions?
Currently, it compiles them all because detecting which ones are actually used would probably require a lot of extra code to work reliably. If each #Include file is kept relatively small and focused, this should not cause much of an increase in EXE size because compression works very well on plain text (which is how the script is stored in the EXE, though the text is encrypted).

Quote:
Will it be allowed to stack the include statements in "function" files? (One function file may include one or more others?)
Yes, and I believe this is already the case if you were to try it with your own #Include files now.

Thanks.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group