Re: your personal AutoHotkey style guide
Posted: 13 Jun 2018, 12:53
i like to name variables containing strings str.
Yeah we can just hope that this gets forbidden.
Yeah we can just hope that this gets forbidden.
Let's help each other out
https://www.autohotkey.com/boards/
https://www.autohotkey.com/boards/viewtopic.php?f=81&t=47140
Code: Select all
DllCall("user32\MessageBox", Ptr,0, Str,"text", Str,"title", UInt,4) ;most readable IMO
DllCall("user32\MessageBox", "Ptr",0, "Str","text", "Str","title", "UInt",4)
DllCall("user32\MessageBox", Ptr, 0, Str, "text", Str, "title", UInt, 4)
DllCall("user32\MessageBox", "Ptr", 0, "Str", "text", "Str", "title", "UInt", 4)
Code: Select all
#IfWinActive, ahk_class Notepad
^#v:: ;notepad - paste text wrapped in double quotes
vText := Chr(34) Trim(Clipboard, Chr(34)) Chr(34)
Control, EditPaste, % vText, Edit1, A
return
#IfWinActive
Code: Select all
DllCall("user32\MessageBox", Ptr,0, Str,"text", Str,"title", UInt,4) ;most readable IMO
DllCall("user32\MessageBox", "Ptr",0, "Str","text", "Str","title", "UInt",4) ;the double quotes add obscure the content
DllCall("user32\MessageBox", "Ptr", 0, "Str", "text", "Str", "title", "UInt", 4) ;it's now less clear which type goes with which argument
Easiest on the eyes, yes, and due to syntax highlighting. The common case for dllcall parameters are hard coded types, for example "str", and variables for the arguments, you do not pass a quoted string usually. Hence, the most readable is, as you shown,Code: Select all
DllCall("user32\MessageBox", Ptr,0, Str,"text", Str,"title", UInt,4) ;most readable IMO
Code: Select all
DllCall("user32\MessageBox", "Ptr", 0, "Str", text, "Str", title, "UInt", 4) ; most readable IYO
; or, which is fine too,
DllCall("user32\MessageBox", "Ptr",0, "Str",text, "Str",title, "UInt",4) ; most readable IYO
Of course, unquoted strings being interpreted as quoted strings doesn't fit in here. Besides, v2 is not only about syntax, I would not have taken an interest if that was the case.jeeswg wrote: I haven't noticed any philosophical shift re. AHK v1 to AHK v2, only a drive towards a more consistent syntax.
Code: Select all
f
f(){
msgbox type(func("g"))
return
dllcall 0, ptr, 0
g(){
(ptr)
}
}
Code: Select all
DllCall("user32\MessageBox", "Ptr",0, "Str","text", "Str","title", "UInt",4) ;more readable, no?
DllCall("user32\MessageBox", "Ptr", 0, "Str", "text", "Str", "title", "UInt", 4)
Code: Select all
DllCall("user32\MessageBox", Ptr,0, Str,"text", Str,"title", UInt,4)
DllCall("user32\MessageBox", "Ptr",0, "Str","text", "Str","title", "UInt",4)
Code: Select all
DllCallEx("user32\MessageBox", "tssui", 0, "text", "title", 4)
Yes, because the quotes where omitted for the type parameter of the dllcall.It reports 'Closure'.
No.Do you not find the first of these examples clearer?
If they where reserved for declaring types, sure but then we would also omit the comma, but that is not going happen.I prefer that they could be omitted
I think you got this exactly backwards. Why don't you write an article on why OOP is bad, you are the one on the crusade, I'm not advocating OOP.If you (or nnnik) think that you could write a decent article/mini-article, 'why OOP is good'/
I'm not sure what you mean. The point is that writing ptr in the dllcall only has the intention of specifying the type of the argument following it, the purpose is not to create a free variable.We have an input (how DllCall is used), and an output ('Closure' is reported).
dllcall 0, ptr causes a variable named ptr to be created, as we have seen, hence, the nested function becomes a closure when it referres to it. This is the correct behaviour of course, interpreting the variable name as a the argument's type is not correct.I looked at the example, if you use (ptrr) you get Func, if you use (ptr) you get Closure, can you explain?
Code: Select all
q::
MsgBox, % MyFunc1("a") "`r`n" MyFunc2("a")
MsgBox, % MyFunc1("") "`r`n" MyFunc2("")
return
MyFunc1(var)
{
if var
return 1
else
return 0
}
MyFunc2(var)
{
if var
return 1
return 0
}
Code: Select all
MyFunc1(var)
{
if (var = 1)
return "a"
else if (var = 2)
return "b"
else if (var = 3)
return "c"
else
return "ERROR"
}
MyFunc2(var)
{
if (var = 1)
return "a"
else if (var = 2)
return "b"
else if (var = 3)
return "c"
return "ERROR"
}
Code: Select all
q::
MsgBox, % MyFunc1("a") "`r`n" MyFunc2("a")
MsgBox, % MyFunc1("") "`r`n" MyFunc2("")
MsgBox, % Bool("a") "`r`n" Bool("")
return
MyFunc1(var)
{
if var
return 1
else
return 0
}
MyFunc2(var)
{
if var
return 1
return 0
}
;-------------------------------------------------------------------------------
Bool(var) { ; make a boolean
;-------------------------------------------------------------------------------
Return, !! var
}