Ahk-Best-Practices
Ahk-Best-Practices copied to clipboard
Should commands use lowercase or CamelCase?
Can there be a section discussing a consistent capitalization style for commands and variables?
^j::
msgbox, Hello World! ; lowercase
msgBox, Hello World! ; camelCase
MsgBox, Hello World! ; CamelCase
MSGBOX, Hello World! ; UPPERCASE
return
Most coding guides seem to use a mixture of lowercase and CamelCase. Take this example from the AutoHotkey Beginner tutorial.
2 - Hotkeys & Hotstrings
^j::
MsgBox Wow! ; CamelCase
MsgBox this is ; CamelCase
Run, Notepad.exe ; CamelCase
winactivate, Untitled - Notepad ; lowercase
WinWaitActive, Untitled - Notepad ; CamelCase
send, 7 lines{!}{enter} ; lowercase
sendinput, inside the ctrl{+}j hotkey ; lowercase
Return ; CamelCase
Even this repository mixes CamelCase and lowercase. (Examples from Flow of Control and Commands)
if var = AHK
msgbox match ; lowercase
Good question.
I definitely prefer ProperCase over any other alternatives.
Since MsgBox
is also a command, it should be ProperCase as well. What do you think?
I like guest3456's suggestion on the AHK forums.
- lowercase for Control Flow statements:
if
,else
,return
,while
- CamelCase for regular commands/functions:
MsgBox
,Send
,WinActivate
The only downside is that the distinction between the two categories could be confusing for commands like IfWinActive
, SetTimer
, OnExit
.
~~I haven't really put enough thought into the best style for variable names.~~
As for variable names, RaptorX suggests using a mix of lowercase and CamelCase. (strLength
, fstLetter
, myString
)
@aviaryan After doing some more research, I think it makes more sense to look to jNizM's AHK Syntax Highlighting addon for Notepad++ for guidance. (also on GitHub)
Like guest3456 had suggested, the AutoCompletion addon uses CamelCase for regular commands and functions. However, the implementation of control flow statements is a bit inconsistent.
In the provided screenshot, control flow statements like if
, return
, loop
, and byref
are lowercase. However, in my personal testing (image below), I've found that the autocomplete recommends CamelCase for these statements.
(Note: Color differences are due to me using the Default AHK theme, while the official screenshots use the "Lazy" Theme.)