Parameter order

Discuss the future of the AutoHotkey language
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Parameter order

12 Apr 2017, 20:29

Exaskryz wrote:I do see your point, but the solutions would be throwing omittable parameters to the front of the command,
That's how it is already; Control is optional, for ,, Value, ahk_id %ControlHwnd% vs , Control, Value, WinTitle.

For the ControlSetText command, all parameters are optional, because even the text can be set to an empty string. For a function, the Text parameter would logically be mandatory, while Control is optional. (Maybe Control would be mandatory if it could be a HWND, but only for commands where a control is required.)

For ControlMove, usually the WinTitle parameter is specified, so there can already be blank parameters/lots of commas if some coordinates are omitted.
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Parameter order

13 Apr 2017, 00:18

I would also prefer ordering the command arguments according to natural language:

Code: Select all

"Give   | a banana          | to the monkey (except to hoppfrosch - as he's an frog!)"
WinSet, | x,y,width,height, | WinTitle, WinText, ExcludeTitle, ExcludeText
:-)
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Parameter order

13 Apr 2017, 01:28

Give the monkey a banana.

Most natural languages are flexible, and different languages have different structure. What's natural to you might not be natural to another, even one who ostensibly speaks the same language.

There are better reasons for this order, like grouping related parameters but putting WinText, ExcludeTitle and ExcludeText last because they're usually omitted.
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: Parameter order

18 Apr 2017, 17:22

just me wrote:I'd prefer the order: command, command options, controlandorwindow criteria:

Code: Select all

ControlMove [, X, Y, Width, Height, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
ControlSend [, Keys, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
ControlSetText [, NewText, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]

WinSetTitle, NewTitle [, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinMove [, X, Y, Width, Height, WinTitle, WinText, ExcludeTitle, ExcludeText]
This goes accord what you intend to do and what the point of the command is. You want to move a control, you use the controlmove, otherwise, you do not use that command. You want to send something, its natural (to me i guess) to want to get to get to the send first, since thats the point of the command.

It comes down to either object, or functional, or a hybrid of the two (how it kind of already is). While a control is subset of a window, to me, these control commands are somewhat overloaded, they are very spaghettish, they want to act on controls of a given window, on controls only, or on a window only (ahk_parent), then if you want to use the control's hwnd, you need to work with the window parameter instead of the control parameter itself. But to not derail im not going to elaborate on this.

Controlsend, control, windowstuff,..., keys would emulate functional, controlsend(control, windowstuff,..., keys) or control(send, control, windowstuff,..., keys), since from a purely functional standpoint, there are no 'objects' and you would need to specify the object you want to act on everytime. With the drawback of omitable parameters meaning act on "this" i.e last/topmost object, so it just throws the entire purpose of the commad towards the end and dirties up the parameter list if you want to act on "this" by having a bunch of empty parameters. While this form may look like OO because you are always specifying an object to act on (trying to emulate OO), it's not, its just an emulation for appearance's sake, if it were, the controlsend command would have the reference to the object itself and thats not possible. So, the purely functional approach throws the whole point of the command towards the end of it, i.e, it gives the purpose, the least importance.

Just me's suggestion (the one i agree with), Controlsend, keys, control, window would be more OO when acting on "this", i.e ctrl.send(keys), we already know the control, its this, or the last, topmost, whatever, so, the control object is implied and thus, ignored as a parameter. If you need to diverge from "this" object in the command, in which case it would be the non-default usage, then you specify the object to act on after the main purpose of the command has been set. It gives the most importance to the wholesome purpose of the command. You want to send something to a control? k, use controlsend, keys. It's not this implied control? then state what you want to send (since thats the reason why you are even using me), then tell me where to send it. Therefore, purpose first, and the object to act on is all grouped together.

The current way, the hybrid way, where the object to act on may not be grouped together, so, if you try an odd situation with a functional approach, wintitle and windowstuff are on the other side of purpose of the command. If you try oo on "this", you have a dead parameter right before the purpose of the command. Which can be the cause of the confusion, because the command itself is not prioritizing its own purpose. I want to reiterate we are working with AHK's unique command way of doing things, so purely functional is confusing and wasteful (overloaded), purely object is impossible.

TLDR, my opinion is that just me's approach sounds best since it prioritizes the actual purpose of the command, which would be the main reason why you would even use it. And don't try to emulate OO using a functional approach, because it will just make it messier.

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: cumulonimbus and 47 guests