qface icon indicating copy to clipboard operation
qface copied to clipboard

add optional modifier to operation parameter

Open jryannel opened this issue 6 years ago • 2 comments

An operation paraterm shall be able to be optional. This would lead in a C++ generator to an overloaded operation.

void add(int a, optional b);

This feature shall be in the extended language profile

jryannel avatar Apr 18 '18 11:04 jryannel

Having several parameters which are optional will make code-generation complicated.

int add(optional int a, optional int b, optional int c)

You would need to generate several operation in a C++ generator

int add()
int add(int a, int b)
int add(int a, int b)
int add(int a, int b, int c)

This will really difficult in the templates to a) recognise and be handle accordingly.

{{ for par in operation.parameter }}
  {{if par.optional }}
  ???
  {{ endif }}
{{ endfor }}

The generator developer would be required to develop its own extension. This seems to be utterly complex. Better choice would be to have the permutations already ready in the parser, but this would require knowledge about the target language, as for example a python generator would handle these optional parameters differently.

def add(a=None, b=None, c=None):
  pass

Currently I do not see a correct solution here, so this feature will not come if I am not getting enlighted :-)

jryannel avatar May 02 '18 09:05 jryannel

Maybe we could add a special value to the default value, e.g. None.

void add(a = None, b = None, c = None)

This seems to be more in line with default values:

void add(a ="0", b = "0", c = "0")

We then could also use this for properties:

interface Contact {
  property Address address = None
}

Maybe this is also relevant: https://en.wikipedia.org/wiki/Null_object_pattern

void add(int a = Null, int b = Null, int c = Null)

It's then about the code generator to decide if the Null expands to 0 or to an operation override or in case of a complex symbol a null object.

jryannel avatar May 02 '18 09:05 jryannel