Open QuentinOchem opened 10 months ago
@raph-amiard @eliericha following our discussions with regards to constructor syntax, I would like to propose an alternative. How about extending the notation used for initializing an object on the heap? e.g.:
V1 : Some_Type'(constructor_parameters);
V2 : Some_Type_Access := new Some_Type'(constructor parameters);
In V2 case, if "constructor parameters" is an instance of Some_Type, we're already in the right semantic, e.g. this is a case where you want to all a constructor by copy anyway. So in a sense, this becomes "just" an extension of a pre-existing Ada syntax (you already have implicit constructor by copy in the context of heap allocation, you now have constructor by copy in the context of stack allocation and extend to cases where constructors take different parameters).
@raph-amiard @eliericha following our discussions with regards to constructor syntax, I would like to propose an alternative. How about extending the notation used for initializing an object on the heap? e.g.:
V1 : Some_Type'(constructor_parameters); V2 : Some_Type_Access := new Some_Type'(constructor parameters);
In V2 case, if "constructor parameters" is an instance of Some_Type, we're already in the right semantic, e.g. this is a case where you want to all a constructor by copy anyway. So in a sense, this becomes "just" an extension of a pre-existing Ada syntax (you already have implicit constructor by copy in the context of heap allocation, you now have constructor by copy in the context of stack allocation and extend to cases where constructors take different parameters).
Following live discussions, it seems that this syntax is promissing, and has the nice property of avoiding confusion with conversions.
However, the syntax
V1 : Some_Type'(constructor_parameters);
Introduces a number of problems from a language design perspective (it is bizarre to mix both a variable type declaration and a call to a constructor. This is not common).
The proposal for the above is to have the user write instead:
V1 : Some_Type := Some_Type'(constructor_parameters);
The exact interaction with aggregates isn't entirely clear yet, but that's a potential path to the right direction. Updating the proposal to reflect that.
Link to the root RFC: https://github.com/QuentinOchem/ada-spark-rfcs/blob/oop/considered/rfc-oop.rst