commands and commas

Discuss the future of the AutoHotkey language

How should initial commas in commands be treated?

We should force initial commas.
2
12%
We should force no initial commas.
9
53%
We should allow both (I prefer initial commas).
4
24%
We should allow both (I prefer no initial commas).
2
12%
 
Total votes: 17
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

commands and commas

05 Nov 2017, 09:02

There are two ways of writing commands in AHK v1:

Code: Select all

;initial commas
Cmd, Arg1, Arg2
Cmd,, Arg2

;no initial commas
Cmd Arg1, Arg2
Cmd , Arg2
This may change in AHK v2.

I'm curious to see what people's views are on the matter.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: commands and commas

05 Nov 2017, 09:20

This may change in AHK v2.
Commands has already been removed.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands and commas

05 Nov 2017, 09:33

You can write functions in a command-like syntax. This issue also relates to control flow statements and directives.

Btw whoever votes first won't be me, because I don't want to influence the result.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: commands and commas

05 Nov 2017, 09:49

We should allow both ( I use no initial commas for certain commands, I use initial commas for others. )
Recommends AHK Studio
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: commands and commas

05 Nov 2017, 12:41

You can write functions in a command-like syntax.
Clarifying, for anyone reading, you can omit () when calling a function without fetching the return value. The opening ( must be replaced by a space. Example,

Code: Select all

msgbox 1,2,3
; is the same as
msgbox(1,2,3)
; but this is not a function call,
ret := msgbox 1,2,3 

This issue also relates to control flow statements and directives.
What issue?
Regarding allowing / forcing initial comma.
What is the purpose of an initial comma? Do you mean msgbox,1,2 should be the same as msgbox ,1,2? That is, both meaning msgbox(,1,2). I'm not very fond of the idea of allowing a symbol after the function name, just for decorative purposes.

Although function calls without () are sometimes convenient, I wonder if there is going to be too much confusion. :think:

Cheers.

Edit: Respecting
jeeswg wrote:I coined the phrase 'initial comma'
Last edited by Helgef on 05 Nov 2017, 13:54, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands and commas

05 Nov 2017, 13:07

I coined the phrase 'initial comma', I don't know if there's an existing/better term for it.

One possibility is to have a directive that specifies your preferred style, so that the error messages will help you stick to that style.

Another possibility is for AutoHotkey to choose one or other of the two styles by default, which you can then override if you want to with a directive. This way, a standard style would be encouraged in scripts.

@nnnik:
Interesting answer. If you were forced to use one or the other, which would you pick?

I generally favour using an initial comma, although it's tempting to miss it out for Sleep.

@Helgef:
I made some comments about initial commas here:
Re: v2.0-a079-be5df98 - Loop statements - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=32941

Here are the points I would make:
- I find the initial comma style easier to read.
- I won't use command-style notation in my own scripts, I will use function-style notation, however other people will be using it in theirs.
- In function-style notation, and in initial comma style notation, there is a character between the command and the first parameter.
- The no initial comma style saves you typing a few commas.
- The no initial comma style can look a bit odd, confusing even, when you omit the first parameter.
- Possibly I would omit initial commas for use with #If, but not for the other directives.
- Possibly I would use initial commas with Loop, but not for the other control flow statements.
- I would use commas for all commands. Although I wouldn't use any commands, I would be using functions instead.
- If you do automatic script checking/conversion like I do, you have to make a concrete decision on each command/control flow statement/directive.

Despite being inclined towards using initial commas. If I don't use commands, and decide to simply omit initial commas in directives and control flow statements, which I don't mind doing, that might make things easier. The only issue would be that #IfWinActive and Loop without initial commas would like quite weird to me. And I'd have to get used to reading scripts by other people with commands that didn't use the initial comma style.

list of every command/function/variable from across all versions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 42#p131642

One important consideration, however, is: should AutoHotkey use function-style notation for all code examples, or not? Again, something I'm undecided on, like this initial comma question.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: commands and commas

05 Nov 2017, 13:31

If I were forced to use one or the other I would get agitated about being forced to use either one.
However I mostly use the no comma style for MsgBoxes. They are my main method of debugging
They other big thing I use commas for is the GUI commands - but since they will change anyways.
I would definitively prefer to keep both and will not settle with an either one or the other decision.
Recommends AHK Studio
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: commands and commas

05 Nov 2017, 13:52

There are no commands, there are function calls without (), so if fn,a meant fn(a), that would be very confusing imo. From the documentation,

Code: Select all

Add(2, 3)
Add 2, 3  ; Parentheses can be omitted if used at the start of a line.
why would anyone reading that page for the first time consider doing

Code: Select all

Add,2, 3	; ?

I don't buy the readability argument, use parentheses for that. If anything, the initial comma should mean the first parameter was omitted, but you would need another example than Add to motivate that :lol:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands and commas

05 Nov 2017, 14:21

I would be interested to hear what happens in other programming languages for comparison.

Code: Select all

;no initial comma
Cmd(2, 3)
Cmd 2, 3
Cmd , 3 ;is that Cmd(3) or Cmd(,3)?

;initial comma
Cmd(2, 3)
Cmd, 2, 3
Cmd,, 3
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: commands and commas

05 Nov 2017, 16:55

I'm missing some choices:
Let the developer(s) decide.
Completely remove the command-style syntax exept control-flow commands.

As soon as you add it, I will vote.
jeeswg wrote:I would be interested to hear what happens in other programming languages for comparison.
We're talking about AHK here.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands and commas

05 Nov 2017, 17:31

Let the developer(s) decide.
- A separate question: should the developer(s) be in charge of AutoHotkey, or should there be some unworkable bureaucratic dreary committee system?
- The assumption is that the developer(s) will decide.
- The questionnaire is made more interesting by presenting the reader with the stark decision that the developer has to make. The reader has to consider the burden of the responsibility.
- I'm actually more interested in people's coding preferences and perspectives than in trying to influence the design of AHK v2.
- My position is that I can live with no initial commas for control flow statements and directives, and perhaps it's better this way, and that although I prefer initial commas for commands, I won't be using commands. I was interested to see if anybody was passionately of the opinion that commands with no initial commas are incredibly ugly, hideous even. I also find it interesting, surprising even, that good coders can like the 'no initial commas' syntax, or even wish to defend it.
- If I wanted to shift the direction of AHK v2 on this issue, I would be very explicit about it.
Completely remove the command-style syntax exept control-flow commands.
- A separate question: should we remove commands completely?
- OK, so you remove commands. The choice re. initial commas for control flow statements and directives remains.
- It seems that my initial 4 choices were perfect after all.
We're talking about AHK here.
- Most of the syntax choices are made in the context of programming languages that the developers and users have experienced.
- It would be interesting to know of any major or minor languages that support one or both of the initial comma syntaxes that AHK uses, and whether there exists a slight variant of one of these two systems. Plus, there may be some arguments on this issue somewhere else also.

[EDIT:] Btw just me, some interesting things for your attention.
[2 resolved items:]
RichEdit controls: get/set text - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=38385
context menu window messages: focus/invoke item - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39209
[2 unresolved items:]
list of dll functions with parameter types for DllCall - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 24#p176624
[COM] Help with the IDropSource and IDropTarget interfaces - Page 3 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 94#p165994
Last edited by jeeswg on 06 Nov 2017, 07:54, 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
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: commands and commas

06 Nov 2017, 04:53

The decision has already been made with v2.0-a079-be5df98. So what do you want to achieve with this poll? Shall every change be a matter of discussion because "I'm used to do ..."? What would be the advantage of an optional comma?

I don't know any up-to-date language using an optional/meaningless comma after the name of a command.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: commands and commas

06 Nov 2017, 05:44

just me wrote:I don't know any up-to-date language using an optional/meaningless comma after the name of a command.
I don't think up-to-date languages are a good comparison for AHK.
Recommends AHK Studio
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands and commas

06 Nov 2017, 06:48

[Forcing no initial commas is not mentioned here AFAICS.]
AutoHotkey v2 alpha (UPDATES) - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 36#p153136

[This is the only reference I know of that lexikos has made to this.]
Re: v2.0-a079-be5df98 - Loop statements - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 75#p155575
(As for requiring, allowing or not allowing the comma, I had deferred thinking about it as I was losing interest and approaching the end of the weekend. It is in my notes to revisit.)
Before any of these changes were made, I had been intending to start a post on commands and commas, a poll possibly. I wanted to establish some default settings for my script converters, and this would include how initial commas were to be treated. Also, I wanted to enquire as to what the standards should be in the help file, should one or other of the initial comma styles always be used, and since the help file was inconsistent, doing a poll could help suggest the best course of action.

Most of the time, re. AHK v2 changes, I feel that I can anticipate what the majority opinion will be when any change is made, but I felt I really couldn't say whether the majority of users preferred using initial commas or not.

I like to have some idea of what the AHK v2 changes will be in advance so that I can write my scripts accordingly and avoid the worst conversion difficulties. Initial commas and the ternary operator (not allowing you to miss out the alternative route, although there is a workaround), were two important issues that were never mentioned on the AHK v2 changes page. lexikos had started threads on most of the other key issues, and I feel that this one is quite important.

I'm struck by two powerful arguments on each side:
- 'No initial commas' looks OK for control flow statements and directives, but looks very ugly for Loop and commands. This is the first step I've seen that could potentially make AutoHotkey into an ugly programming language, by people who continue to use commands. The same is true of introducing single quotes for assigning values.
- No initial commas has the great advantage of eliminating the question of whether to use commas or not.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: commands and commas

06 Nov 2017, 07:28

[Forcing no initial commas is not mentioned here AFAICS.]
Removed legacy command syntax and %expression% substitution in strings.

That is, a "command" is now just a function or method call which sits at the start of the line, lacks parentheses and discards its return value.
jeeswg wrote:
(As for requiring, allowing or not allowing the comma, I had deferred thinking about it as I was losing interest and approaching the end of the weekend. It is in my notes to revisit.)
The whole context is
Parse, Read, etc. are not parameters any more than Loop or in are parameters. There is dubious benefit to requiring quote marks or allowing variables/expressions for the sub-command. (As for requiring, allowing or not allowing the comma, I had deferred thinking about it as I was losing interest and approaching the end of the weekend. It is in my notes to revisit.)
It's not related to commands in general.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands and commas

06 Nov 2017, 08:05

@just me: Thank you, I've read the additional quotes that you've added, but I can't see how they address the initial commas issue.
- If you mean that 'legacy command syntax' includes using/not using initial commas, I don't think that I've ever seen using or not using initial commas described as legacy syntax.
- I'm not sure what you mean by 'It's not related to commands in general', I stated that the initial commas issue relates to commands/control flow statements/directives, perhaps this thread should include a mention of control flow statements and directives in the title.

Btw I've added another interesting link to the post above, there are now 4.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: commands and commas

06 Nov 2017, 08:50

Might be that I'm translating it wrong, but
That is, a "command" is now just a function or method call which sits at the start of the line, lacks parentheses and discards its return value.
or shorter
A "command" is now just a function or method call which lacks parentheses.
clearly means

Code: Select all

Function(Param1, Param2, Param3)
becomes

Code: Select all

Function Param1, Param2, Param3
An optional comma was never allowed after a function name.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: commands and commas

06 Nov 2017, 12:08

An optional comma was never allowed after a function name.
I think this is key. It is a function name, not a command, commands are gone, there shouldn't be any talk about commands. New users (and old) should learn to use functions. If a comma is to be allowed immediately after the function name, it should mean the first parameter was omitted. My speculative guess is that the space is required in order to not confuse those who are used to the command syntax. Or maybe it made the implementation simpler. Again,
helgef wrote:Although function calls without () are sometimes convenient, I wonder if there is going to be too much confusion. :think:
I don't think initial commas are either useful or confusing for the directives.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: commands and commas

06 Nov 2017, 12:24

If that's the point I don't think that functions without () are worth it - even if that somehow relates to control statements being highlighted more easily.
In my opinion thats the job of the IDE.
Recommends AHK Studio
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: commands and commas

06 Nov 2017, 12:35

in AHKv1, i always use initial commas
in AHKv2, i will always use functions
just me wrote:The decision has already been made with v2.0-a079-be5df98. So what do you want to achieve with this poll? Shall every change be a matter of discussion because "I'm used to do ..."? What would be the advantage of an optional comma?
agreed. When lexikos wants opinions, he usually asks before implementing it and puts out a test version

i voted:
We should allow both (I prefer initial commas).

but
Helgef wrote:Do you mean msgbox,1,2 should be the same as msgbox ,1,2? That is, both meaning msgbox(,1,2).
good point, this is ambgious

so really i'm fine with it as-is

having worked on a v1 -> v2 script converter, and knowing that jeeswg is also working on one, its clear to me why this is such an issue for him. but i dont necessarily think the syntax should change simply to make the writing of a conversion script easier. AHK is quirky enough as is, and the less quirks the better.

how about adding this poll option:

Always require parens ()


Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 35 guests