scrap commands?

Discuss the future of the AutoHotkey language

Should command-like syntax for functions (functions without parentheses) be removed?

Remove the command-like syntax for functions.
26
72%
Keep the command-like syntax for functions.
10
28%
 
Total votes: 36
iseahound
Posts: 222
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: scrap commands?

18 Apr 2018, 04:36

@jeeswg: What do you think the WinWait command is doing? If you had to write your own, what would it be?

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



In the first version, the function returned the identity (own hwnd), or it never returned. In the second version, it's returning the identity or an ErrorLevel. Try to write a terminating WinWait function that doesn't require an external "counting" variable. You actually can't. So the WinWait "function" isn't really taking one input - it's taking two. WinWait(hwnd, ErrorLevel) But that's why commands can be very intuitive, after all the command syntax isn't bound by a pair of parenthesis, so when I write WinWait, hwnd, maybe it actually runs WinWait, hwnd, ErrorLevel

@nnnik there are functions that terminate and never return as well.

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

Shutdown() {
Shutdown, 1
return "SUCCESS" ; <- ???
}
User avatar
nnnik
Posts: 2789
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: scrap commands?

18 Apr 2018, 05:27

Yeah but you see I dont think they matter a lot.
They are both incredibly rare and mostly covered by documentation - even if you do denote that they don't terminate or terminate the script/thread it will be useless extra unless you have a standard way to describe what the function actually does.
e.g. like pydoc or javadoc are good examples of this. It would also be nice if we could at least define types or denote them in some way. Compared to that the fact we mentioned above is both rare and of minor information value.
Recommends AHK Studio
guest3456
Posts: 2298
Joined: 09 Oct 2013, 10:31

Re: scrap commands?

18 Apr 2018, 09:24

iseahound wrote:Try to write a terminating WinWait function that doesn't require an external "counting" variable. You actually can't. So the WinWait "function" isn't really taking one input - it's taking two. WinWait(hwnd, ErrorLevel)


i have no idea what point youre making about the 2nd counting variable. WinWait has a timeout parameter

there is absolutely no need to recurse for a WinWait function.

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


User avatar
nnnik
Posts: 2789
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: scrap commands?

18 Apr 2018, 13:17

Another method would be a callback.
Also iseahound I would advise against using recursion and avoiding it whereever possible.
Recommends AHK Studio
iseahound
Posts: 222
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: scrap commands?

18 Apr 2018, 13:44

Actually I think it's unlikely WinWait was ever a function. Here's a WinWait that is closest to the original - a function that doesn't return.

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

StartTime := A_TickCount
while not DllCall("IsWindow", "ptr", hwnd) {
if (A_TickCount - StartTime > 6000)
break
Sleep 10
}
Last edited by iseahound on 18 Apr 2018, 15:42, edited 1 time in total.
User avatar
nnnik
Posts: 2789
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: scrap commands?

18 Apr 2018, 13:54

I feel like I don't understand the point that your trying to make anymore.
I get that you have a specific abstract model of programming - we all do and we regularily fight which model handles which situations the best and try to find a middle path that works for the most AHK users.
Could you say again what you actually want to happen to the language and why that is a good and meanigful addition?
Recommends AHK Studio
iseahound
Posts: 222
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: scrap commands?

18 Apr 2018, 15:42

I'm just pointing out that it isn't so easy to convert commands into functions. If it was, then the conversion would have occurred already. Commands have this idea of finality, but functions have this idea of being chainable.

Unfortunately you can do pretty weird stuff

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

five(Shutdown()) ; returns 5?

five(int) {
return 5
}


Of course in current AutoHotkey nobody is stopped from writing their own Shutdown() function to try and do this.
User avatar
nnnik
Posts: 2789
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: scrap commands?

18 Apr 2018, 16:00

But the question comes down to is it really neccessary to add a new case to denote such a change in flow?

I think that the usage and consequences of a function are dependent on it's body and the context it is used in.
It is the programmers responsibility to know of those consequences and act accordingly and hint at them accordingly.

Therefore I conclude it's unneccessary.
Recommends AHK Studio

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: kczx3 and 1 guest