Wish optional parameters with default

Would optional parameters help you?


  • Total voters
    33

NeoTechni

Well-Known Member
Licensed User
Longtime User
I'd like to suggest how this could be implemented.

I'm pretty sure you have some code that enumerates the parameters for a given function and stores it in a variable type like:
type Parameter(Name as string, pType as string, isArray as boolean)
which gets put in a list
Add 2 members, 1 named Default as string, isOptional as boolean
In the code that parses the parameter list, check if a parameter has an = sign in it, if it does get everything after that as Default and set isOptional to true
Then do a check to be sure that every parameter after the first optional one is also optional (show the red squiggly line if one is not)

Then in the code that parses the parameters for a function call, if any parameter is missing, just use the default value for it instead.
I'd imagine it could be done quite easily, though I'd need to see Erel's code to be sure.

But I'd love optional parameters. I keep using dirty code to use a single parameter to act as two rather than find every time the function is called to add the new parameters and it's pretty annoying.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Or at least an option to add a new parameter to every time the function is called

ie: the code is currently

functionane(par1)

we add a new parameter to the function itself, and then it changes the code to

functionname(par1, par2)
 
Top