AutoHotkey Community

It is currently May 26th, 2012, 9:08 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: June 30th, 2009, 10:43 pm 
Offline

Joined: June 12th, 2009, 3:53 am
Posts: 43
Location: United States
The subject is organizing an AutoHotKey program. What are the best practices?

(A) Have a number of scripts, kept in one file, each with a different name?

(B) Have just one script in one file, with a number of functions which call each other?

(C) Have a number of scripts in a number of files, then use the include command to bring them together? Each script could be unit-tested separately?

Tom, who is a veteran IT person but a newbie to AutoHotKey

_________________
Tom


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2009, 10:58 pm 
Offline

Joined: March 9th, 2007, 2:47 am
Posts: 509
Location: Unknown
B is the best choice


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2009, 11:20 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
I agree with SysMonitor, B (top down) is deff the best way to get started.


I started my 1500 line GUI that way. I have since made smaller #include files, and ini files, and I have the GUI call data from them as needed.

We have 16 people with 16 different PC's and screen resolutions and set ups and programs. I was finding If I keep the main GUI file the same, and just modify the #includes, the others would have an easier time 'updating' there versions of the GUI. A simple rightclick/reload of the GUI vs the normal delete this, copy and paste that. I say this only becuase my team mates are dumb as rocks and I've had to learn how to build around their stupidity as opposed to what is the AHK best practice =-)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 6:37 pm 
Offline

Joined: June 29th, 2009, 8:09 pm
Posts: 28
Well, I feel like this could be a silly question, but... also being an AHK noob (and software developer), I'll hide my shame:

Whats the difference between options B and C? How would functions for option B call cross-file scripts?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 7:16 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I personally use C for my work script, as I have to be able to control about 30 different programs. It would be too difficult to find the proper sections for each program in one single script that large, easier to have them as separate scripts which define what program each is for, which are #included in one main script.

I also maintain a separate #Included script for all of my predefined variables and functions.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 2nd, 2009, 3:43 am 
Offline

Joined: June 12th, 2009, 3:53 am
Posts: 43
Location: United States
jones172 wrote:

(B) Have just one script in one file, with a number of functions which call each other?

(C) Have a number of scripts in a number of files, then use the include command to bring them together? Each script could be unit-tested separately?



In computers, there is no such thing as a dumb question if you don't know the answer to it.

Option (B) uses just one file, which simplifies communication. Option (C) uses a number of files and may be appropriate for a very large computer program. In my own case, following the advice, I am using option (B).

_________________
Tom


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 3rd, 2009, 6:05 pm 
Offline

Joined: June 29th, 2009, 8:09 pm
Posts: 28
jones172 wrote:
jones172 wrote:

(B) Have just one script in one file, with a number of functions which call each other?

(C) Have a number of scripts in a number of files, then use the include command to bring them together? Each script could be unit-tested separately?



In computers, there is no such thing as a dumb question if you don't know the answer to it.

Option (B) uses just one file, which simplifies communication. Option (C) uses a number of files and may be appropriate for a very large computer program. In my own case, following the advice, I am using option (B).


Thanks for the clarification - I definitely misread that. I missed the "in one file part! D'oh


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2009, 6:15 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
What I do is for functions I'm going to use again, I put them in my library folder. This way, I don't have to manually include them, because they are included automatically, as needed. Also, this way, if I find a bug, I only have to change one file, and the others which use the function will use the fixed version. Also, it reduces code size by exporting commonly done tasks to an external file. Finally, you don't have to copy and paste the function each time you use it, since, as stated above, it will be included automatically, as needed.

For functions that are only going to be used in that one project, I put them in one script. However, usually, when creating a script, I find useful little snips of code that I can see using again. So, I make a function and put it in a separate file in my library folder. So, usually, my code doesn't get insanely large because a lot of the functionality is done through my library functions, and libraries that I downloaded from the site. Also, not meant to be a plug for my library, but I'm used to OOP (Object-Oriented Programming), so I have classes that handle some of the jobs that I need, such as bmcclure's IniFile, which I use to interact with ini files.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2009, 11:01 am 
Offline

Joined: November 24th, 2005, 8:16 am
Posts: 851
I have created some full blown apps with AHK, some with thousands of lines in total.
To me, there is no clear cut answer, since it depends on a few factors.
  • If you want to have a high level of portability, and you want other people to have your uncompiled script, than I usually try to do it one file only, with functions and routines inside it (thats becoming less comfortable as the file grows of course).
  • For small scripts (100-500 lines) I am using a single file, and calling some of my standard library includes (for example, I have my INI handlers as a library).
  • For larger scripts, I am trying to adopt ways from other programming languages. I am creating each set of related functions in a file, then including them in the main script. Sort of like "classes". Also consider some naming convention here, like ClassName_functionName().

Some important points I try to follow:
  • Keep your "auto executing" section minimal - all should go in functions or routines
  • Whenever possible, use functions and not labels - since labels are global in scope, and with functions you get some degree of scope separation.
  • Keep all user configuraion in INI files and all internal configuration at the top of your script. I usually have an "Init:" label for my internal configs that are not relevant to the user.


Anyways, thats my approach. :)

_________________
Sector-Seven - Freeware tools built with AutoHotkey


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, Exabot [Bot], krajan, patgenn123, Yahoo [Bot] and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group