[Gambas-user] "Groups" of optional arguments
T Lee Davidson
t.lee.davidson at gmail.com
Wed Nov 30 17:15:28 CET 2022
On 11/30/22 03:04, BB wrote:
> Maybe I'm overthinking this or maybe my brain is just not as sharp as it used to be.
>
> Short explanation: I think I need to group optional arguments something along the lines of :
>
> Sub XYZ ( arg1 As String, Optional ( arg2 As Boolean, arg3 As Integer = 0), Optional ( arg4 As Date = Null, arg5 as Integer =
> -Inf ) )
>
> The illogical thinking is that calls to the method
>
> * must have arg1 provided and
> * either
> o arg2 and possibly arg3
> * or
> o possibly arg4 and possibly arg5
>
> The example is simpified, btw. 😁
>
> Is there a way to do this?
>
>
This may be a gross misunderstanding of the problem. But, couldn't you pass in the callee's class as a required parameter in
addition to the reqion, and pass all the optionals as variadic or, simply, positional optionals?
Ie.: given Sub XYZ ( arg1 As String, Optional ( arg2 As Boolean, arg3 As Integer = 0), Optional ( arg4 As Date = Null, arg5 as
Integer = -Inf ) )
data = XYZ(regionid, Object.Type(Me), ...) , or
data = XYZ(regionid, Object.Type(Me), Optional arg3 as blah, Optional arg4 as blahblah, etc.)
and handle the myriad optional arguments based on who's calling? Or would that lead to more spaghetti code?
--
Lee
More information about the User
mailing list