I would like to start a new thread on this feature request from Bee: Feature request: Named parameter
In the last post, Marc says “well it HAS them. it’s just not using the syntax you’d like it to have.”.
But the current implementation with “Multi-part Method Names” has many differences against “named parameters”:
- They are only available when the method is defined with multi-part names, so we can’t use them with methods we don’t write ourself, such as SDK methods.
- The first parameter can’t be named.
- The order of the parameters can’t be changed.
So, it I define the following method:
class method DoSomething (Param1 : Int32 := 1, Param2 : Int32 := 2, Param3 : Int32 := 3);
I should be able to call it with the following syntaxes:
DoSomething (1, 2, 3); DoSomething Param1 (1) Param2 (2) Param3 (3); DoSomething (1) Param3 (3); // Param2 has default value DoSomething (1) Param2 (2); // Param3 has default value DoSomething Param3 (3) Param1 (1) Param2 (2); // changes parameters order
Named parameters have three benefits:
- To be able to skip a parameter in the middle of the list (if default values specified).
- To be able to name all the parameters. Useful if many parameters of the same type to avoid an error in parameter placement.
- To be able to get rid of parameter order.