In order to understand this, you have to understand what named arguments do... why are you using them? You might have a reason for using them, but it may not be 'the' reason.
The reason for named arguments is so that you can pass the arguments in any order you like, and not just in the order they are defined in the function.
For example, compile and run this as a dot-command. You will find you get "hi" as a system message:
Code: Select all
use uo;
program Testing(who)
var huh := "hi";
Hello(what := huh, char:=who);
endprogram
function Hello(char, what)
SendSysMessage(char, what);
endfunction
Note that my function, 'hello', does not have optional parameters. Named parameters have basically NOTHING to do with optional parameters, directly. However, sometimes you might want to use them to help you with optional parameters. Take this example:
Code: Select all
use uo;
program Testing(who)
var huh := "hi";
Hello(things := 1, char:=who);
endprogram
function Hello(char, what := "hi", things := 0)
if (things)
SendSysMessage(char, what);
endif
endfunction
I am using named parameters here to avoid the need to define the 'what' parameter.
Again, this is the important part:
Named parameters exist to let you order your parameters any way you wish - they do not have anything directly to do with optional parameters. It just so happens that defining named parameters in a function definition/prototype has the same syntax as using named parameters in a function call.
Once the compiler sees a named parameter in a call to a function, all bets are off as far as the order of parameters having anything to do with which are what... so while YOU might think it 'knows' what goes where... it does not know. When you pass a named parameter, you MUST name any subsequent parameters, as well.
All of that said, I find the use of named parameters to generally be very bad form. They invite confusion, IMO.