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.
33
79%
Keep the command-like syntax for functions.
9
21%
 
Total votes: 42
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

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

WinWait(hwnd) {
     Sleep 1000 ; Check every second.

    ; Let's break the loop but to do so, we need some sort of global variable...
    ; We call this global ErrorLevel
    global ErrorLevel++
    if (ErrorLevel > 6)
        return ErrorLevel, ErrorLevel := 0 ; returns 7, resets errorlevel to 0. 

    if DllCall("IsWindow", "ptr", hwnd)
        return hwnd
    else
        return WinWait(hwnd)
}
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

Shutdown() {
    Shutdown, 1
    return "SUCCESS" ; <- ???
}
User avatar
nnnik
Posts: 4500
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: 3454
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

WinWait(title, timeout:=1000)
{
   get starttime
   Loop endlessly
   {
      if WinExist(title)
         return hwnd
      if (thistime - starttime) > timeout
         return TIMEOUT      
   }
}

User avatar
nnnik
Posts: 4500
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: 1434
Joined: 13 Aug 2016, 21:04
Contact:

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

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: 4500
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: 1434
Joined: 13 Aug 2016, 21:04
Contact:

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

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: 4500
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
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: scrap commands?

20 May 2019, 18:10

thread necromancy
yes, yes it should be removed
User avatar
vvhitevvizard
Posts: 454
Joined: 25 Nov 2018, 10:15
Location: Russia

Re: scrap commands?

30 Jun 2020, 07:52

thread necromancy+1

Removal! The majority of misunderstanding stems from 2 syntax systems' co-existence. I don't use command syntax at all since I moved to AHK V2 coding 2-3 years ago. I never missed atrocious batch-like syntax of AHK V1.

My thoughts against the reasons of keeping it:
1. Facility of debugging print-outs with simple msgbox x syntax.
> That's not enuf to weigh down the scale in favor of clogging up the syntax with inconsistency. Typing can be facilitated with any sort of keystrokes/abbreviation expanding utilities after all.

2. Somewhat concerning readability.
> Syntax highlighting of any IDE helps discern one language token from another with ease. For example, even a small (just 200KB .exe file) standalone text editor notepad 2 indicates matching parenthesis and missing open/closing ones.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: scrap commands?

30 Jun 2020, 11:56

helgef wrote: a bunch of stuff
Well, I now omit the () whenever possible, I like it, even for methods :lol:.

Cheers.

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 45 guests