Coding Style Guidelines
My Scripts are written for the latest released version of AutoHotkey.
Need a secure, accessible place to backup your stuff? Use Dropbox!
But the most funny thing is watching them post "whats wrong with my code!!?!?!?!??" in the support session :lol:
"What is a suitable automation? Whatever saves your day for the greater matters."
Barcoder - Create QR Codes and other Barcodes using only Autohotkey !!
[quote name="Chapter 1]Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.[/quote]
I like reading an instruction guide that tells you what to do and then insults you (and your code) if you don't like it. :wink:
In short, 8-char indents make things easier to read, and have the added benefit of warning you when you're nesting your functions too deep. Heed that warning.
class test { f() { loop 10 { if(A_Index = 1) msgbox first } } }
[quote name="Chapter 1]The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.[/quote][quote name="fragman"]I tend to disagree, atleast for an example like this:
class test { f() { loop 10 { if(A_Index = 1) msgbox first } } }[/quote]
Well, I wouldn't count the first two indentations as part of the 3-indentation "limit". The statements in the loop would be the first indentation I would count.
My Scripts are written for the latest released version of AutoHotkey.
Need a secure, accessible place to backup your stuff? Use Dropbox!
SubroutineName: MsgBox,0,,This is msg box 1 MsgBox,0,,This is msg box 2 returnthis form of indentation helps me quicky identify where subroutines begin and end in my code. Especially in longer pieces.
Another form of styling is the naming conventions for variables, subroutines and functions. Occasionally i will use something called Hungarian Notation to help me remember what a given routine, function or variable's purpose is http://en.wikipedia....garian_notation this can be handy if not overdone.
Whether to leave in debugging code or not and the extent of errorchecking for boundary cases is also a style guideline. Code generalization and routine factoring are also style issues as well.
If i were to give any advice at all, I'd say pick a simple subset of styling conventions and stick with them for all your projects. Start with indentation and code factoring and try to keep your code as simple as possible given the job you need to do. The principle of Occam's Razor http://en.wikipedia....i/Occam's_razor is an important concept to apply to any code you write. And try to make your code as re-usable as possible to help you keep from having to reinvent the wheel every time.
The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter KeyLooperDemo Key Spammer TinyClickRecorder GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Do not add spaces around (inside) parenthesized expressions. This example is
*bad*:
s = sizeof( struct file );
not so sure i agree here
i've been working on my code and was finding that its much easier to read if () statements with function calls inside if there is a space such as
if ( isMyFunctionTrue(param1, param2) )
Since a function follows the if, you don't need the outside parentheses at all.i've been working on my code and was finding that its much easier to read if () statements with function calls inside if there is a space such as
if ( isMyFunctionTrue(param1, param2) )
In addition, the open-parenthesis may be omitted entirely if the first item after the word "if" is a function call or an operator such as "not" or "!".
if isMyFunctionTrue(param1, param2)
My Scripts are written for the latest released version of AutoHotkey.
Need a secure, accessible place to backup your stuff? Use Dropbox!
Me too - AHK has too many special handlings when parenthesis are omitted that I tend to use them always. In v2 this might change, as a if will always be followed by an expression.yea i know that, i've tried that as well, but i like to enclose all my ifs in parenthesis not only to standardize the use of expression-if but also because i find it easier to read (pradoxically i know)
Some other rules I use - personally but also enforce in teams, no matter what language used:
[*:2mm0qmes] Good readable Variable names / Method names (no abbreviations, no one-char names; exception: i,j for counters)
[*:2mm0qmes] Method Line-Count should fit on a single screen. Max 3 nested Code-Blocks. (=> create new Methods where the code is "out-sourced")
[*:2mm0qmes] Never ever have redundant code. Sounds obvious, but some people don't get it.... they copy 30lines of code, and change one single thing and generate lot of redundant overhead
I have a question regarding the user of upper/lower case in AHK.
Why is "if" not capitalized but "IfWinExist" is? I know it doesn't really matter but I am a big fan of standards so it would be useful if anyone would kindly post a list of keywords that should be lower-case.
RegJump() - Jump to registry path in Regedit
HoverScroll() - HoverScroll() - Scroll controls without focus