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 

Organizing a program--best practices question

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
jones172



Joined: 12 Jun 2009
Posts: 43
Location: United States

PostPosted: Tue Jun 30, 2009 9:43 pm    Post subject: Organizing a program--best practices question Reply with quote

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
Back to top
View user's profile Send private message
System Monitor



Joined: 09 Mar 2007
Posts: 509
Location: Unknown

PostPosted: Tue Jun 30, 2009 9:58 pm    Post subject: Reply with quote

B is the best choice
Back to top
View user's profile Send private message Visit poster's website
Carcophan



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Tue Jun 30, 2009 10:20 pm    Post subject: Reply with quote

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 =-)
Back to top
View user's profile Send private message
yourbuddypal



Joined: 29 Jun 2009
Posts: 25

PostPosted: Wed Jul 01, 2009 5:37 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Wed Jul 01, 2009 6:16 pm    Post subject: Reply with quote

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.
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
jones172



Joined: 12 Jun 2009
Posts: 43
Location: United States

PostPosted: Thu Jul 02, 2009 2:43 am    Post subject: Re: Organizing a program--best practices question Reply with quote

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
Back to top
View user's profile Send private message
yourbuddypal



Joined: 29 Jun 2009
Posts: 25

PostPosted: Fri Jul 03, 2009 5:05 pm    Post subject: Re: Organizing a program--best practices question Reply with quote

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
Back to top
View user's profile Send private message
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Sat Jul 04, 2009 5:15 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Icarus



Joined: 24 Nov 2005
Posts: 851

PostPosted: Sat Jul 04, 2009 10:01 am    Post subject: Reply with quote

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. Smile
_________________
Sector-Seven - Freeware tools built with AutoHotkey
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help 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