What is recommended, %Func%() or Func.Call()? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User
Posts: 407
Joined: 26 Jun 2017, 08:12

What is recommended, %Func%() or Func.Call()?

27 Dec 2018, 21:30

What is recommended, %Func%() or Func.Call()?

and how to force function call on few parameters?

Code: Select all

test := "FT"

%test%("Dynamic_1 - 111", "222", "333", "444", "555", "666")

%test%("Dynamic_2 - 111", "222")	;few parameters, so not called (How to force function call?)

;_____

func("Ft").call("func.call_1 - 111", "222", "333", "444", "555", "666")

func("Ft").call("func.call_2 - 111", "222")	;few parameters, so not called (How to force function call?)

;_____

bindTest := Func("Ft").Bind("bind_1 - 111", "222", "333", "444", "555", "666")
%bindTest%()
bindTest.Call()

bindTest := Func("Ft").Bind("bind_2 - 111", "222")	;few parameters, so not called (How to force function call?)
%bindTest%()
bindTest.Call()


FT(a, b, c)	;________ FT(Function) _______
{
msgbox, % a " - "  b " - " c

}
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: What is recommended, %Func%() or Func.Call()?

27 Dec 2018, 22:17

For recommendations wait for better answers.
For fewer parameters try optional parameters:

Code: Select all

test := "FT"
%test%("Dynamic_1 111", "222", "333")
%test%("Dynamic_2 111", "222") ; fewer parameters

func("Ft").call("func.call_1 111", "222", "333")
func("Ft").call("func.call_2 111", "222") ; fewer parameters

bindTest := Func("Ft").Bind("bind_1 111", "222", "333")
%bindTest%()
bindTest.Call()

bindTest := Func("Ft").Bind("bind_2 - 111", "222") ; fewer parameters
%bindTest%()
bindTest.Call()


FT(a, b, c:="") {
    msgbox, % a " - "  b " - " c
}

return ; end of auto-execute section
I hope that helps.
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: What is recommended, %Func%() or Func.Call()?

27 Dec 2018, 22:39

wolf_II wrote:
27 Dec 2018, 22:17
For fewer parameters try optional parameters:
or use something like %test%("Dynamic_2 - 111", "222", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0")

There are some cases where you can't define optional parameters, such as for built-in functions, functions created by other people, etc, etc!
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: What is recommended, %Func%() or Func.Call()?

27 Dec 2018, 22:54

wolf_II wrote:
27 Dec 2018, 22:17
For recommendations wait for better answers.
One disadvantage of using Call() is that users are forced to use func("FunctionName")

but still, I really don't know what is better, %func%() or func.call() ?

Code: Select all

test := "FT"

%test%("Dynamic_1 - 111", "222", "333")		;works

test.call("call_1 - 111", "222", "333")		;does not work

;______

test := func("FT")

%test%("Dynamic_2 - 111", "222", "333")		;works

test.call("call_2 - 111", "222", "333")		;works


FT(a, b, c)	;________ FT(Function) _______
{
msgbox, % a " - "  b " - " c

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

Re: What is recommended, %Func%() or Func.Call()?

28 Dec 2018, 05:15

%fn%() is what I recommend.
.call() does not only disallow functionnames but many other things too.
Recommends AHK Studio
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: What is recommended, %Func%() or Func.Call()?

28 Dec 2018, 05:50

Finally, a dynamic call to a function is slightly slower than a normal call because normal calls are resolved (looked up) before the script begins running.
does that pertain only to %fn%(), or fn.Call() too
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: What is recommended, %Func%() or Func.Call()?

28 Dec 2018, 09:53

wolf_II wrote:
27 Dec 2018, 22:17
For fewer parameters try optional parameters:
A better solution: https://www.autohotkey.com/boards/viewt ... 76&t=60402
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: What is recommended, %Func%() or Func.Call()?

28 Dec 2018, 10:21

@swagfag, Edit, it applies to fn.call() too I tried to say.

If you do repeated calls to %var%() and var contains a function name, it is much better to call var := func(var) first to avoid repeated look-ups. Also note that, in v1, %var%() silently fails if var contains an invalid function name, so you might want to call func(var) beforehand anyways to verify it yields a function reference.

The behaviour of %user_defined_function_object%() in v1 is very awkward, v2 is better :thumbup:.

Cheers.
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: What is recommended, %Func%() or Func.Call()?  Topic is solved

28 Dec 2018, 15:41

So it seems that %Func%() is recommended over Func.Call()
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: What is recommended, %Func%() or Func.Call()?

29 Dec 2018, 01:41

No, you should read the documentation and decide which one is suited for whatever you are doing. Your question is on the same level as asking which is recommend, ++var or var++, sometimes it doesn't matter sometimes which one you go with, sometimes it does, read the documentation...

Cheers :fireworks: :champagne:.
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: What is recommended, %Func%() or Func.Call()?

29 Dec 2018, 10:37

Helgef wrote:
29 Dec 2018, 01:41
Your question is on the same level as asking which is recommend, ++var or var++
No it is not! (Not even close!)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mstrauss2021, Spawnova, william_ahk and 362 guests