-
Notifications
You must be signed in to change notification settings - Fork 55
Provide default init method implementation #734
Comments
This issue would probably be best moved to Ergo. There is a default
Does that address this issue, or is this about something else? |
I would be in favour of removing I'm not sure what the use case for |
I would like a default implementation that works even if I have a custom state object. For example: clause init(request : Request) : Response { |
Oh. I see, I didn't get that. That sounds like this would need the ability to synthesize a valid value based on its (arbitrary) type, which definitely requires some thinking and possibly non-trivia work. I'm not personally a super big fan of magic things, which it feels like this is what it would be, but we could discuss requirements & design for something along those lines. |
@adrianffletcher Moved to the Ergo repo. Hope you don't mind. |
No worries. I don't really use stateId so I would really like the smart clause to be initialised with empty state without me having to do anything. This doesn't seem like magic to me as I would expect state variables to be initialised to none unless otherwise stated. |
initialise to If your state says:
You need to invent atomic values (other wise how does the other clauses know what the balance is?). e.g.,
Another way to think about it is if those are not initialised during |
the "magic" part to me is: what if one contract wants the late field to be |
Note that if we do synthesize a default a developer could possibly change that default in a nicer way with e.g.,:
|
Could a default state instance be an optional part of the template definition? For example, something like If it exists, it is used during initialisation? |
How is that better than doing it inside the code? (which you will need anyway if you e.g., want to calculate something based on the contract values (e.g., |
I would like to define the standard default state when defining the state model. Then when I don't provide an init method I just get the default state defined in the model. |
That's interesting. Defining a default value with the type itself isn't a bad idea. A few observations:
|
I'll rephrase some of the questions raised by this issue with a bit of an analogy:
|
Data point: Concerto has already a notion of default.
|
Automatic creation of a value could be part of the editing experience. VSCode hot key or something else. |
Proposed resolution:
Note: a benefit of 3. is that it would work for all classes creation, not just for init. |
@adrianffletcher Let us know if the proposed resolution seems reasonable to you. |
@jeromesimeon That sounds great to me. I particularly like the idea of generating a .ergo file from a model.cto file, creating a default init method taking into account the default values and creating a default request clause. |
Time for your first Open Source contribution? I can walk you through the VS extension code... |
Sounds good. |
@adrianffletcher The first item below (removal of I think we can move this issue fo the VSCode extension?
|
I don't want to have to define a default init method when I have nothing special to define in the default state. I would like a default implementation to be provided in circumstances where I am not interested in specifying a stateId.
The text was updated successfully, but these errors were encountered: