your personal AutoHotkey style guide

Talk about anything
Helgef
Posts: 2840
Joined: 17 Jul 2016, 01:02
Contact:

Re: your personal AutoHotkey style guide

13 Apr 2018, 15:10

nnnik wrote:AHK studio does most of it for me
At some point I'll have to take a closer look at this. Ty.
- Funnily enough I find that o/v really help with readability, it's immediate, you know that what you're looking is an object/variable and not something else.

Regular vs object variables are easily distinguished by the (lack of) object syntax, eg, myvar.stuff. The documentation mentions prefixes here.


I almost never pass a quoted string to dllcall, so in general the quotes helps with readability imo, due to syntax highlighting

Code: [Select all] [Download] GeSHi © Codebox Plus

dllcall("func", "ptr", var, "int", var2)
; vs
dllcall("func", ptr, var, int, var2)

Readability aside, it is a very odd feature to allow this.

jeeswg wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

vRet := !!DllCall("user32\DestroyIcon", Ptr,DllCall("user32\CopyIcon", Ptr,hIcon, Ptr))
vRet := !!DllCall("user32\DestroyIcon", "Ptr", DllCall("user32\CopyIcon", "Ptr", hIcon, "Ptr"))

Horizontal space clearly isn't a big factor.
jeeswg wrote:word wrap
What editor do you use, if it is notepad, please lie :lol:

Cheers.
User avatar
jeeswg
Posts: 4108
Joined: 19 Dec 2016, 01:58
Location: UK

Re: your personal AutoHotkey style guide

13 Apr 2018, 15:26

- Actually, that's an interesting point Helgef, a good style is a good style in Notepad, that is not dependent on syntax highlighting etc.
- You never know when the raw code is going to appear as plaintext on some website, or even, in some Google/Bing search results I saw today. Eek.
Helgef
Posts: 2840
Joined: 17 Jul 2016, 01:02
Contact:

Re: your personal AutoHotkey style guide

13 Apr 2018, 15:34

I'd copy it into my editor if I wanted to look at it... :roll:
User avatar
nnnik
Posts: 2695
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: your personal AutoHotkey style guide

13 Apr 2018, 16:41

You are completely beside the point.
Image
Recommends AHK Studio
User avatar
Flipeador
Posts: 598
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: your personal AutoHotkey style guide

13 Apr 2018, 19:51

What editor do you use, if it is notepad, please lie

a good style is a good style in Notepad, that is not dependent on syntax highlighting etc.

Please, have someone tell me that he does not use Notepad. :wtf: :shock: :eh: :lol:


Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus


:wave:
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2
john_c
Posts: 117
Joined: 05 May 2017, 13:19

Re: your personal AutoHotkey style guide

14 Apr 2018, 08:58

jeeswg wrote:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




Is there some difference between

  • (not)using initial commas with Loop command (Loop, Parse...) and
  • (not)using them with regular commands (MouseGetPos)

?
User avatar
jeeswg
Posts: 4108
Joined: 19 Dec 2016, 01:58
Location: UK

Re: your personal AutoHotkey style guide

14 Apr 2018, 09:05

There should be no difference in functionality, it's simply that I find the initial comma style better-looking and clearer re. omitting the first parameter.

Code: [Select all] [Download] GeSHi © Codebox Plus

;YES (initial commas)
Cmd, Arg1, Arg2
Cmd,, Arg2
;NO (no initial commas)
Cmd Arg1, Arg2
Cmd , Arg2
;function (for comparison)
Fnc(Arg1, Arg2)
Fnc(, Arg2)
User avatar
Flipeador
Posts: 598
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: your personal AutoHotkey style guide

14 Apr 2018, 09:17

I just realized that this is permissive in AHKv2 :shock:

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

DllCall("MessageBox", Ptr,0, Str,"text", Str,"title", UInt,0)

It only brings tremendous confusion and bad practice.


btw, would be great f(ByRef p)`n{`n} --> f(&p)`n{`n}. I would definitely choose &. It would save a lot of space.
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2
john_c
Posts: 117
Joined: 05 May 2017, 13:19

Re: your personal AutoHotkey style guide

14 Apr 2018, 09:24

Flipeador wrote:...


Your style is very interesting in some points!

Code: [Select all] [Download] GeSHi © Codebox Plus

;NO
DllCall("MessageBox", "Ptr", 0, "Str", "text", "Str", "title", "UInt", 0)
;YES
DllCall("DllFile.dll\Function", "Ptr", 0, "Str", "text", "Str", "title", "UInt", 0)


Above: As I understand, you prefer to manually specify the file from which the function will be taken?

Code: [Select all] [Download] GeSHi © Codebox Plus

;YES
if (var1 == "")
;NO
if (var1 = "")
if var1 = var2


Above:

  • For what reason you prefer if (var1 == "") over if (var1 = "")? Why you prefer case-sensitive-equal here?
  • I see you discourage about using if var1 = var2, but it's not very clear what you mean, because it doesn't seem to be an expression... Hm!

; So many things to learn!
User avatar
Flipeador
Posts: 598
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: your personal AutoHotkey style guide

14 Apr 2018, 09:32

john_c wrote:As I understand, you prefer to manually specify the file from which the function will be taken?

Yes, for clarity. sincerely, i do not know if this affects the performance, I have not looked at the source code or done tests, but I do not think so.

For what reason you prefer if (var1 == "") over if (var1 = "")? Why you prefer case-sensitive-equal here?

I just like more ==, like in C++. I use it with "" and numbers. Also, I think it should be faster.

I see you discourage about using if var1 = var2, but it's not very clear what you mean, because it doesn't seem to be an expression

It was just an example, I know, I just want to say that I do not agree to omit the parentheses. I prefer many parentheses, in case of not being readable, I add spaces or use a new line.
:)
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2
john_c
Posts: 117
Joined: 05 May 2017, 13:19

Re: your personal AutoHotkey style guide

14 Apr 2018, 10:58

Was not discussed here yet: objects.

From my point of view:

Code: [Select all] [Download] GeSHi © Codebox Plus

; Bad. Key1 and Key2 are strings, and for that reason we should write them quoted
Obj := {Key1: "Value1", Key2: "Value2"}

; Good
Obj := {"Key1": "Value1", "Key2": "Value2"}


Retrieving values from objects, from my point of view:

Code: [Select all] [Download] GeSHi © Codebox Plus

object := {"foo": "aaa", "bar": "bbb", "foo bar": "ccc ddd"}

; Bad, because it's not possible to retrieve the value of multiword key (foo bar)
msgBox % object.foo

; Good, for the opposite reason
msgBox % object["foo"]
msgBox % object["foo bar"]


What you think about it, guys?
Last edited by john_c on 14 Apr 2018, 11:26, edited 1 time in total.
Helgef
Posts: 2840
Joined: 17 Jul 2016, 01:02
Contact:

Re: your personal AutoHotkey style guide

15 Apr 2018, 02:48

Some additional notes on v2 style
Flipeador wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

;YES (no initial commas)
Loop Parse, Text, `n, `r

In v2, no inital comma is,

Code: [Select all] [Download] GeSHi © Codebox Plus

;YES (no initial commas)
Loop Parse Text, "`n", "`r"

Misc.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


I always just lower case for control flow statments, eg

I also prefer == over = when case doesn't matter.

Cheers.

Edit
Flipeador wrote:btw, would be great f(ByRef p)`n{`n} --> f(&p)`n{`n}. I would definitely choose &. It would save a lot of space.
I'd prefer f(p) ->f(ByVal p), that is, byref is default.

Return to “Offtopic”

Who is online

Users browsing this forum: No registered users and 6 guests