-
Notifications
You must be signed in to change notification settings - Fork 50
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
schema: make optional and nullable SpawnFoo parameters a bit safer #225
Comments
@warpfork and I spoke about this a few weeks ago - it might not even be worthwhile trying to make the Accumulate/Spawn APIs nicer to use if practically all users will move to the schema parser and compiler. It's also worth noting that the current Spawn APIs lack features or are outright outdated. For example, support for So I see two paths forward:
I'd prefer if we went with option 1 instead of 2, in which case sharp edges in the API aren't really a worry, because they will be internal APIs. I imagine that most users of Accumulate+Spawn could transition to |
Sounds good , probably should move this ticket to backlog? |
Indeed. My bad for not adding the extra context. When I filed this issue, I thought the schema package was complete, and I just wanted to polish its rough edges a bit. |
Closing for the same reasons as #208 (comment): long term, we expect everyone to load a schema either in DSL or DMT form. The only place that would need to manually "spawn" a schema is the bootstrapping of the schema-schema itself, in the DMT package. Once the "dsl parse" and "dmt compile" packages support all schema features, then I think we could move the "spawn" APIs so they are hidden from external users, but still available to the dmt package. |
I should add: even for an internal "schema spawner" API, we'll likely want to tweak and improve the API somewhat. But it's not a priority, and we won't need to worry about end-user UX for a private API, which is what this issue was about. |
Right now we have:
Nothing wrong with it per se, and it works. The code then looks like:
Can a reader quickly tell what each
true
andfalse
means? I definitely can't. Every time, I have to go check theSpawnStructField
definition to remind myself ifoptional
ornullable
are first.Other APIs have similar issues;
SpawnList
takes a boolean, and unless you're very used to this API, it's not evident that it means "nullable".Another kind of unfortunate mistake is that one can mistakenly pass variables in the wrong places, and it won't be evident or caught by the typechecker:
I propose to make code using Spawn funcs easier to use by making them take named boolean parameters, like:
Now, the problematic lines from above can be much clearer:
The text was updated successfully, but these errors were encountered: