-
Notifications
You must be signed in to change notification settings - Fork 544
react: Investigate more type safety for input vs compute cells #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Initial investigation of what the code looks like present in https://github.com/petertseng/exercism-rust/commits/react-cell-ids . Note that I based it off a post-#434 and post-#464 state, since there would otherwise be too many merge conflicts that I'm not willing to write two versions of. Also note that as of this writing, now |
A somewhat more ergonomic API IMO would be to define a trait It adds complexity, but also makes this code somewhat more like real production code. For a difficulty-10 exercise, I believe this to be an appropriate tradeoff. |
Having now actually attempted to implement an example of my API suggestion, I see that:
I retain a suspicion that there exists an elegant API characterized by I therefore rescind my suggestion about using a |
One may see my original failed attempts to get |
A
Reactor
may issueCellID
s in response to either acreate_input
orcreate_compute
.A
Reactor
acceptsCellID
s in the following circumstances:create_compute
so that the caller specifies the dependencies of the compute cell to be created. These dependencies may be either input or compute cells.value
. May be either input or compute cell.set_value
. Only valid for an input cell.add_callback
/remove_callback
. Only valid for a compute cell. There is no technical barrier against an input cell having callbacks, but the specification does not call for it and it is never tested.I believe it is technically feasible to have slightly more safety, as follows:
create_input
issues onlyInputCellID
s.create_compute
issues onlyComputeCellID
sadd_callback
/remove_callback
acceptComputeCellID
only.set_value
acceptsInputCellID
only.create_compute
andvalue
need to acceptenum CellID { Input(InputCellID), Compute(ComputeCellID) }
Should this be done? Is this a reasonable API and/or any other reasons it's a good/bad idea?
If we do this, is it further possible to test at compile-time that
InputCellID
andComputeCellID
cannot be assigned to each other? Even if it is possible, should we do that? I encourage making them unassignable to each other for more safety, but I don't want students to feel too restricted.If I do not hear objections or think of any myself, I will investigate what the code looks like. I will not be offended if there were initially no objections but objections come to light after the seeing the code.
The text was updated successfully, but these errors were encountered: