- Please share your personal AutoHotkey style guide.
- I've included all of the choices I could think of. There may be others that I missed out, so do please include examples of other choices (other points of debate).
- People are welcome to post general posts, but please try to keep your complete (up-to-date) style guide within one post. Thank you all.
Code: Select all
;YES
;comment
;NO
; comment
;Indentation style - Wikipedia
;https://en.wikipedia.org/wiki/Indentation_style
;YES (Allman style)
Loop, 3
{
MsgBox
Loop, 3
{
InputBox, vInput
}
}
;NO (K&R: one true brace)
Loop, 3 {
MsgBox
Loop, 3 {
InputBox, vInput
}
}
;YES
if (var1 = var2)
;NO
if ( var1 = var2 )
;YES
oArray := ["a", "b", "c"]
;NO
oArray := ["a","b","c"]
;YES
DllCall("MessageBox", Ptr,0, Str,"text", Str,"title", UInt,0)
;NO
DllCall("MessageBox", "Ptr", 0, "Str", "text", "Str", "title", "UInt", 0)
;YES
MsgBox, % var "text" var var "text" "text" var "text"
;NO
MsgBox, % var . "text" . var . var . "text" . "text" . var . "text"
;YES (initial commas)
Loop, Parse, vText, `n, `r
;NO (no initial commas)
Loop Parse, vText, `n, `r
;YES (initial commas)
MouseGetPos, vCurX, vCurY, hWnd, vCtlClassNN
MouseGetPos,,, hWnd, vCtlClassNN
;NO (no initial commas)
MouseGetPos vCurX, vCurY, hWnd, vCtlClassNN
MouseGetPos ,, hWnd, vCtlClassNN
;YES
vText
oArray
;NO
text
array
;YES
if !(var1 = var2)
;NO
if not (var1 = var2)
;YES
if (var1 && var2)
if (var1 || var2)
;NO
if (var1 AND var2)
if (var1 OR var2)
;OBVIOUSLY YES
var := "text"
var1 := var2
;OBVIOUSLY NO (NOTE: NOT AVAILABLE IN AHK V2)
var = text
var1 = %var2%
;YES
vText := "line 1`r`n" "line 2`r`n" "line 3"
;NO (the 'n' combines with the string, bad for spellchecking)
vText := "line 1`r`nline 2`r`nline 3"
;YES
vText := A_Space A_Space
;NO (never have multiple consecutive spaces)
vText := " "
;YES (indentation of 1 tab)
if (var1 = var2)
MsgBox
;NO (indentation of 4 spaces)
if (var1 = var2)
MsgBox
;AMBIGUOUS CASES ...
;YES
if (var1 = var2)
MsgBox
;IT'S OK (UNNECESSARY CURLY BRACES)
if (var1 = var2)
{
MsgBox
}
;IT DEPENDS
var := 1 + 1
;IT DEPENDS
var := 1+1
your personal AutoHotkey style guide - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 06#p217206
Links:
v2 docs contribution questions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 55#p221055
AutoHotkey style guide - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 17&t=14089
GitHub - aviaryan/Ahk-Best-Practices: [WIP] AutoHotkey Best Practices
https://github.com/aviaryan/Ahk-Best-Practices
Coding Style Guidelines - Programming - AutoHotkey Community
https://autohotkey.com/board/topic/8205 ... uidelines/
Codestyle: implicit and explicit concatenation - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 17&t=46983
Syntax and naming conventions? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 17&t=44183