your personal AutoHotkey style guide

Talk about anything
Helgef
Posts: 3151
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: 4965
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: 3151
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: 3201
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: 1004
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 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
john_c
Posts: 174
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: 4965
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: 1004
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 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
john_c
Posts: 174
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: 1004
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 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
john_c
Posts: 174
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: 3151
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.
User avatar
jeeswg
Posts: 4965
Joined: 19 Dec 2016, 01:58
Location: UK

Re: your personal AutoHotkey style guide

08 May 2018, 19:20

Text barriers.
I use:

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

;==================================================
;==============================
;====================
;===============
;==========
;=====
;===
;50 and possibly also: 3, 5, 10, 15, 20, 30
User avatar
jeeswg
Posts: 4965
Joined: 19 Dec 2016, 01:58
Location: UK

Re: your personal AutoHotkey style guide

09 May 2018, 15:08

More notation debates to take note of.

Indentation. The big debate:
indentation systems - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39920

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

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

Re: your personal AutoHotkey style guide

19 May 2018, 20:25

- @nnnik: I was interested in these principles. I agree with them, and was wondering whether you'd read anything that led you to use them.
- In theory it might be good to split the parameters across lines, to comment on a particular parameter, although I would instead put the comment above the DllCall/MsgBox etc line.
- Also, you might have a long and complex parameter. So it would help to split the parameters across lines in that case. What would you do in that situation? Would you create a separate variable?

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

User avatar
Cerberus
Posts: 95
Joined: 12 Jan 2016, 15:46

Re: your personal AutoHotkey style guide

31 May 2018, 14:26

I think giving variables clear names is paramount, as mentioned above. Thinks I consider when naming:
- What does it contain?
- What will it be used for?
In the example of getting the PID of a windows, I might do it like this (pseudo-code):

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

GetPID, Active_PID
If (Active_PID = DesiredValue)
Notepad_PID := Active_PID
ExpandWindow(Notepad_PID)


And I always try to capitalise everything at the beginning of a line or proper names, because I like code to look as much like proper English as possible.
User avatar
Flipeador
Posts: 1004
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: your personal AutoHotkey style guide

13 Jun 2018, 12:08

@jeeswg, Hello, since you omit the quotes when declaring the data types in DllCall, I wonder what happens in cases where super-global variables (or classes) have been declared with the same name as a data type (eg. UINT)?. Do not you think it's confusing?.
I'm sorry, but I can not prove anything at this time.
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
User avatar
jeeswg
Posts: 4965
Joined: 19 Dec 2016, 01:58
Location: UK

Re: your personal AutoHotkey style guide

13 Jun 2018, 12:35

- Originally, a long time ago, I thought that AutoHotkey would parse the DllCall lines, and convert Int into "Int" automatically. Since then I don't think that this is the case, and so yes, there are potential (minor?) (major?) disadvantages to omitting the quotes, although clearly readability is the advantage.
- Since I already wrote the code to convert them all, I could potentially convert them all at some point.
DllCall converter/cleaner (e.g. x32 to x64/x32 two-way compatible) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31365
- HotKeyIt, and I to an extent, have been working on lists of DllCall functions. He added built-in support for a DllCall alternative in AutoHotkey_H, and I have looked at creating a custom function for AutoHotkey_L, however, because my converter script is so easy to use, and because I try to avoid scripts that I share having additional dependencies, it hasn't been a priority to pursue the alternative function route.
C++: DllCall: get parameter types/sizes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=23&t=39426
WinApi
https://hotkeyit.github.io/v2/docs/commands/WinApi.htm
- Also, lexikos recently added support for creating pointers to strings on the fly. That makes a DllCall alternative, that omits parameter types, more feasible.
AutoHotkey v2 alpha (UPDATES) - Page 3 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=2120&p=211067#p211067
Changed &address-of to work with literal and temporary strings.
User avatar
Flipeador
Posts: 1004
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: your personal AutoHotkey style guide

13 Jun 2018, 12:46

although clearly readability is the advantage

This seems totally subjective to me, and it depends on the editor you use. In my editor, which supports syntax highlighting, it's just the opposite, quotes are much clearer than without them.
The rest you have written, I do not know what has to do with my comment. In my opinion, the only good thing I rescue from AHK_H is the multi-thread.
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
Helgef
Posts: 3151
Joined: 17 Jul 2016, 01:02
Contact:

Re: your personal AutoHotkey style guide

13 Jun 2018, 12:51

It is unreadable, even in notepad.
Issue example, probably unlikely, but still,

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

global str := 'char'
f
f(){
dllcall 'MessageBox', 'ptr', 0, str, 'abcde', 'ptr', 0, 'uint', 0x42
}

Hopefully, this will not be allowed in future v2.

Return to “Offtopic”

Who is online

Users browsing this forum: neokid2416 and 8 guests