v2:
Some functions have "essential" parameters and "less essential" parameters. For example, a MsgBox always has a message, and sometimes has a title or options. Therefore, a decision was made for the MsgBox syntax to look like this.
MsgBox([Text, Title, Options])
Now consider the case of a Gui text control. It always has text (or a plan to have text), but options are often absent. Nonetheless, the syntax is "backwards", as follows.
MyGui.AddText("Options", "Text")
The suggestion here is to swap the options with the main content-- text in this case-- and to do so for all other functions with this same issue. This would make the essential parameter the first parameter.
[v2]: Put the most frequently used function parameters ahead of the rest
Re: [v2]: Put the most frequently used function parameters ahead of the rest
I think you're too late, don't you? AHK v2 has been developed over many years, time enough to suggest breaking changes. It might be something for v3.
Re: [v2]: Put the most frequently used function parameters ahead of the rest
Good goal but in the case of AddText I think there are stronger reasons for keeping the current syntax, even setting aside backward compatibility.
The Options, Text order is consistent for controls creatable with Gui Object method Add
MyGui.Add(ControlType , Options, Text)
MyGui.AddControlType(Options, Text)
For many of those controls adding options data is common so it ok that that option comes first there. And a consistent pattern for all of them is easier to remember and document.
Another benefit with options first is that position data can line up nicely visually in the editor when creating controls. I find that helpful when trying out different positionings for controls. Compare:
Code: Select all
G := Gui()
G.Add("Text", "x30 y30 w100", "hello world")
G.Add("Text", "xp y+10", "a long text here about how mikeyww provides awesome help to people in the AutoHotkey forums")
G.Add("Edit", "xp y+10")
Code: Select all
; not working code, illustrates larger visual distance for position data if options was 2nd argument
G := Gui()
G.Add("Text", "hello world", "x30 y30 w100")
G.Add("Text", "a long text here about how mikeyww provides awesome help to people in the AutoHotkey forums", "xp y+10")
G.Add("Edit", , "xp y+10")
Re: [v2]: Put the most frequently used function parameters ahead of the rest
im not so sure about that. parsing some oldforum archive dumps yielded ~5000 Gui, Add, ControlType,s of which, even accounting for v1 crap like v...., g... and hwnd...., ~80 contained no options, whereas ~1000 contained no text. 2% vs 20%
anyway, u can change the order to whatever u like in ur scripts
Code: Select all
#Requires AutoHotkey v2.0.0
MakeGuiGreatAgain()
MakeGuiGreatAgain() {
for propName in Gui.Prototype.OwnProps()
if (propName ~= 'Add\w+')
Switch132(propName, Gui.Prototype.GetMethod(propName))
Switch132(propName, Method123) => Gui.Prototype.DefineProp(propName, {
Call: (this, Text?, Options?) => Method123(this, Options?, Text?)
})
}
Re: [v2]: Put the most frequently used function parameters ahead of the rest
OK. Thank you (x3) for the details. You all convinced me not to place my AHK order for the year 2030 (v3), and instead use v2 like there is no tomorrow.
I hereby disable my gui1.AddText(, wish). Good explanations, really!
I hereby disable my gui1.AddText(, wish). Good explanations, really!
Re: [v2]: Put the most frequently used function parameters ahead of the rest
Thank you; I had not seen that post earlier. Perhaps we can at least agree that (1) Gui syntax is inconsistent with MsgBox syntax in v2-- but that seems OK since, unlike Gui, every MsgBox function must have a message-- and (2) there is no consensus about which approach is better for Gui parameter order. TextOrOptions seemed appealing to me earlier as well-- with MsgBox a noted example of TextOrOptions already present in v1, though this approach might not translate so well to Gui, and putting the options in an object just seems like extra work. I guess I'm mostly convinced that putting the options first has some advantages.
Who is online
Users browsing this forum: No registered users and 16 guests