aviaryan / Ahk-Best-Practices

[WIP] AutoHotkey Best Practices
32 stars 5 forks source link

Should commands use lowercase or CamelCase? #3

Open Stevoisiak opened 7 years ago

Stevoisiak commented 7 years ago

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
WinClose Notepad  ; CamelCase
aviaryan commented 7 years ago

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?

Stevoisiak commented 7 years ago

I like guest3456's suggestion on the AHK forums.

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)

Stevoisiak commented 7 years ago

@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.)

Local screenshot of NotePad++ AHK AutoComplete