i like to name variables containing strings str.
Yeah we can just hope that this gets forbidden.
your personal AutoHotkey style guide
Forum rules
Discuss Autohotkey related topics here. Not a place to share code.
Discuss Autohotkey related topics here. Not a place to share code.
Re: your personal AutoHotkey style guide
- @Flipeador: Whenever you decrease convenience in some way, you should think carefully about increasing convenience in some way. E.g. one aspect of PostMessage/SendMessage was removed but a smart new bit of functionality &(temporary string) was added. E.g. 'if var contains string', I agree with nnnik's proposal that ideally 'string' should be treated as one string, not a comma-separated list, however, if you go along with that proposal, which reduces convenience, you should consider a new proposal to increase convenience. (I'm not sure what the best answer is in this case. An ArrCSL function? A containsCSL operator? Something else.)
- @Helgef: what is unreadable about fewer double quote symbols. Anyhow, I think the main way to improve readability is to group parameters (I only ever do this for DllCall), and omitting double quotes in type parameters is secondary.
- If you compare with AutoIt, Chris must have really valued the ability to omit the quotes for the type parameters, including creating the P instead of * option, just for DllCall.
Function DllCall
https://www.autoitscript.com/autoit3/do ... llCall.htm
- @Helgef: Even though it's unlikely I respect the global str line of argument.
- The move to AHK v2 meant that I just added in this subroutine to my main script:I.e. it's important to keep track of reductions in convenience, and 'var = value' being removed is one of them, in this case I've added a hotkey to help me, but I would propose that 'var `= value' be added as an alternative. Convenience is king, and it's one of the *key* principles of AutoHotkey.
- @Helgef: what is unreadable about fewer double quote symbols. Anyhow, I think the main way to improve readability is to group parameters (I only ever do this for DllCall), and omitting double quotes in type parameters is secondary.
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)
Function DllCall
https://www.autoitscript.com/autoit3/do ... llCall.htm
- @Helgef: Even though it's unlikely I respect the global str line of argument.
- The move to AHK v2 meant that I just added in this subroutine to my main script:
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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: your personal AutoHotkey style guide
Convenience by itself does not exist.
Specific types of syntax are convenient to a specific group of people that like to program in different ways.
You like to save as much characters as possible and you like to avoid using a lot of arrays.
For you AHK v1 was convenient. However the CSLs come at a downside. You need to escape special characters and if you want to use it for something that should work in all cases CSLs are not the way to go.
While they are convenient to the hacker that wants to hack something fast into their PC they are not convenient for the developer that wants to develop entire working projects.
AHK v2 is shifting it's focus from the hacker sort of person to more sophisticated developers. While it should provide a syntax - to satisfy its old hacker users - it's not a neccessity.
Specific types of syntax are convenient to a specific group of people that like to program in different ways.
You like to save as much characters as possible and you like to avoid using a lot of arrays.
For you AHK v1 was convenient. However the CSLs come at a downside. You need to escape special characters and if you want to use it for something that should work in all cases CSLs are not the way to go.
While they are convenient to the hacker that wants to hack something fast into their PC they are not convenient for the developer that wants to develop entire working projects.
AHK v2 is shifting it's focus from the hacker sort of person to more sophisticated developers. While it should provide a syntax - to satisfy its old hacker users - it's not a neccessity.
Recommends AHK Studio
Re: your personal AutoHotkey style guide
I do not mean it is unreadable as in, it cannot be read, I mean mostly that it makes the code harder to understand.
I see no gain from your grouping of variables, rather the contrary. Pairing on individual lines is much better, imo.
Cheers.
I see no gain from your grouping of variables, rather the contrary. Pairing on individual lines is much better, imo.
Cheers.
Re: your personal AutoHotkey style guide
- @Helgef: For me it's like the opposite of the March of Progress (evolution of man) image:
- The first is shorter, has fewer double quotes, and makes clear which type goes with which argument.
- @nnnik: One criticism I've levelled against OOP advocates and even the entire OOP philosophy (which works well in theory, but less well in practice) is that they're *impractical*. I can't think of a more impractical statement than: 'Convenience by itself does not exist'.
- What is that even supposed to mean: 'convenience does not exist', 'no two people can agree on what convenience is'?
- This reminds of a thread on the problems of the Excel 'Ribbon', one of the 'Ribbon' advocates had the username 'SquareWheels'.
- Where something cannot be objectively measured, it would be as well to take a vote on it: A v. B which is more convenient?
- Keeping code short is one of many competing virtues, but yes it's key.
- I like using *arrays*, but I like to avoid using *custom object classes*. (If I want to store data somewhere, standard linear/associative arrays are usually fine, and I don't need custom object classes. I use functions to manipulate those arrays, I find that using object methods does not help anything. Using arrays and functions generally beats designing a new custom class (or reusing one) every time I want to do something.)
- In AHK v1 you could use if var contains % "text", that way you didn't need to escape special characters.
- I haven't noticed any philosophical shift re. AHK v1 to AHK v2, only a drive towards a more consistent syntax. Btw some changes e.g. re. negative offsets for InStr/SubStr are for convenience. New features in programming languages are often for convenience.
- The drive of civilisation is convenience. E.g. the invention and refinement of every kind of notation be it alphabets, mathematical symbols, assembly language. E.g. mechanical inventions, sometimes the clue is in the name: 'labour-saving devices'.
- AHK is king because it's easier to program than in say C++, make AHK too inconvenient, and it's no better than any other programming language.
- The overall goal of convenience is a balance between competing ideas. I generally find that if one approach has some flaws, you can find a better halfway house. You lose some convenience, but gain some convenience elsewhere.
- I didn't hear anyone say that AHK is shifting focus.
- Interesting comments re. 'from the sophisticated hacker/developer sort of person to the think-they're-sophisticated developers. Convenience is not a neccessity.' I was paraphrasing just there.
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
- @nnnik: One criticism I've levelled against OOP advocates and even the entire OOP philosophy (which works well in theory, but less well in practice) is that they're *impractical*. I can't think of a more impractical statement than: 'Convenience by itself does not exist'.
- What is that even supposed to mean: 'convenience does not exist', 'no two people can agree on what convenience is'?
- This reminds of a thread on the problems of the Excel 'Ribbon', one of the 'Ribbon' advocates had the username 'SquareWheels'.
- Where something cannot be objectively measured, it would be as well to take a vote on it: A v. B which is more convenient?
- Keeping code short is one of many competing virtues, but yes it's key.
- I like using *arrays*, but I like to avoid using *custom object classes*. (If I want to store data somewhere, standard linear/associative arrays are usually fine, and I don't need custom object classes. I use functions to manipulate those arrays, I find that using object methods does not help anything. Using arrays and functions generally beats designing a new custom class (or reusing one) every time I want to do something.)
- In AHK v1 you could use if var contains % "text", that way you didn't need to escape special characters.
- I haven't noticed any philosophical shift re. AHK v1 to AHK v2, only a drive towards a more consistent syntax. Btw some changes e.g. re. negative offsets for InStr/SubStr are for convenience. New features in programming languages are often for convenience.
- The drive of civilisation is convenience. E.g. the invention and refinement of every kind of notation be it alphabets, mathematical symbols, assembly language. E.g. mechanical inventions, sometimes the clue is in the name: 'labour-saving devices'.
- AHK is king because it's easier to program than in say C++, make AHK too inconvenient, and it's no better than any other programming language.
- The overall goal of convenience is a balance between competing ideas. I generally find that if one approach has some flaws, you can find a better halfway house. You lose some convenience, but gain some convenience elsewhere.
- I didn't hear anyone say that AHK is shifting focus.
- Interesting comments re. 'from the sophisticated hacker/developer sort of person to the think-they're-sophisticated developers. Convenience is not a neccessity.' I was paraphrasing just there.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: your personal AutoHotkey style guide
You are tagging me but most of the time you are talking about a different topic and you are not responding to my post.
the only time you respond to my post is when you quoted me by saying that "convenience is not neccessary" when I said in my post that convenience depends on point of view.
I proceeded to explain why AHK is never going to have a nuilt in CSL operator or function by saying that it prefers convenience that is from a different point of view on AutoHotkey.
the only time you respond to my post is when you quoted me by saying that "convenience is not neccessary" when I said in my post that convenience depends on point of view.
I proceeded to explain why AHK is never going to have a nuilt in CSL operator or function by saying that it prefers convenience that is from a different point of view on AutoHotkey.
Recommends AHK Studio
Re: your personal AutoHotkey style guide
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.
My guess is that it has not been removed yet because virtually no one uses it, and, removing it actually requires some (not very interesting) work.
However, I realised there is a much more severe problem with this than the unlikely case that one of the unqouted types coincide with a variable referring to a string which is another type. Example,
Code: Select all
f
f(){
msgbox type(func("g"))
return
dllcall 0, ptr, 0
g(){
(ptr)
}
}
Cheers.
Edit: Added some missing quotes .
Re: your personal AutoHotkey style guide
- @Helgef: Could you explain your example? It reports 'Closure'.
- Re. grouping. Do you not find the first of these examples clearer?- I find the second example to be slower to read, significantly slower. With syntax highlighting turned on or off.
- There may be some arguments for enforcing double quotes, but considering readability *only*, I prefer that they could be omitted.
- Anyhow, an alternative could be this which is especially useful for converting code directly from other languages, and for functions with 5+ parameters. It's *an* alternative.
- Re. grouping. Do you not find the first of these examples clearer?
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)
- Anyhow, an alternative could be this which is especially useful for converting code directly from other languages, and for functions with 5+ parameters. It's *an* alternative.
Code: Select all
DllCallEx("user32\MessageBox", "tssui", 0, "text", "title", 4)
offtopic
Last edited by jeeswg on 16 Jun 2018, 19:38, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: your personal AutoHotkey style guide
jeeswg, I edit my example code.
I have already told you I'm not interested in that sort of debate, it is useless.
Cheers.
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 have already told you I'm not interested in that sort of debate, it is useless.
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'/
Cheers.
Re: your personal AutoHotkey style guide
- We have an input (how DllCall is used), and an output ('Closure' is reported). In-between stages? Free variables or something like that? I haven't had the time to investigate closures in AHK yet.
offtopic
Last edited by jeeswg on 16 Jun 2018, 19:39, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: your personal AutoHotkey style guide
As I told you before this guys arguments are neither valueable nor sensible.
And yes there is a debate. But you seem to think that this debate is between equally large partners - thats not true.
80-90% of all programmers mainly use OOP and only use procedural programming on the side.
Most of the Open Source projects are object oriented or support an object oriented interface.
Most professional work with programs that are written on a request basis are written in Java a completely OOP language.
80-90% of modern day websites were written using some sort of OOP framework or even using an OOP language.
Even if you continue this debate we won't change our behavior nor will the entire world.
Even if you really prove that procedural programming is better than oop in every situation we'd still rather remove it than OOP.
Thats simply because this is a language that should be used by people. It should not focus on whats better or not.
It should appeal to the people. And most people use OOP.
And yes there is a debate. But you seem to think that this debate is between equally large partners - thats not true.
80-90% of all programmers mainly use OOP and only use procedural programming on the side.
Most of the Open Source projects are object oriented or support an object oriented interface.
Most professional work with programs that are written on a request basis are written in Java a completely OOP language.
80-90% of modern day websites were written using some sort of OOP framework or even using an OOP language.
Even if you continue this debate we won't change our behavior nor will the entire world.
Even if you really prove that procedural programming is better than oop in every situation we'd still rather remove it than OOP.
Thats simply because this is a language that should be used by people. It should not focus on whats better or not.
It should appeal to the people. And most people use OOP.
Recommends AHK Studio
Re: your personal AutoHotkey style guide
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).
Good day.
ot
Re: your personal AutoHotkey style guide
- @Helgef: I looked at the example, if you use (ptrr) you get Func, if you use (ptr) you get Closure, can you explain?
offtopic
Last edited by jeeswg on 16 Jun 2018, 19:40, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: your personal AutoHotkey style guide
You cannot even write OOP why should I even talk to you on the matter xD
Recommends AHK Studio
Re: your personal AutoHotkey style guide
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?
Cheers.
ot
Re: your personal AutoHotkey style guide
- @Helgef: Thanks for the info.
offtopic
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: your personal AutoHotkey style guide
I've simply never seen you write a proper OOP script that would validate any claim of you understanding the topic.
And as long as that doesn't happen I can only see you as someone that uses big words and opinions without even grasping them completely.
And as long as that doesn't happen I can only see you as someone that uses big words and opinions without even grasping them completely.
Recommends AHK Studio
Re: your personal AutoHotkey style guide
- If/else styles, any opinions?
- Or another example:
- @nnnik:
jeeswg's object classes tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=54588
- Also, please always use spoilers, as Helgef and I have done.
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"
}
jeeswg's object classes tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=54588
- Also, please always use spoilers, as Helgef and I have done.
Last edited by jeeswg on 02 Sep 2018, 03:24, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: your personal AutoHotkey style guide
I prefer a single line function for this.
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
}
Re: your personal AutoHotkey style guide
- Thanks wolf_II, but if you had to choose between MyFunc1/MyFunc2, which would you choose?
- Re. spaces v. tabs. Tabs for the win.
Spaces and tabs in Python - xkcd
http://forums.xkcd.com/viewtopic.php?t=58867
- Re. spaces v. tabs. Tabs for the win.
Spaces and tabs in Python - xkcd
http://forums.xkcd.com/viewtopic.php?t=58867
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Return to “General Discussion”
Who is online
Users browsing this forum: No registered users and 11 guests