go: dealing with required props and nils #3438
Labels
feature-request
A feature should be added or improved.
needs-triage
This issue or PR still needs to be triaged.
馃殌 Feature Request
Affected Languages
TypeScript
orJavascript
Python
Java
C#
,F#
, ...)Go
General Information
Description
Just some general feedback on what I'm seeing with the conversion of Props like interfaces to Go. This was maybe already discussed but I couldn't find anything (sorry).
First item, the
jsii.{Type}
functions, EGjsii.String()
. I use these all the time with AWS SDK for Go and they're a real bummer to use. If you forget to call it, then you have to wrap your statement. Then if you don't know the type (was it int? int32? int64?) then you need to do some jumping around to figure it all out. I haven't found a good editor experience to make this "nice".The other problem is it seems like folks are having a hard time figuring out required vs optional properties, see:
Proposed Solution
For the first problem, I 100% understand why this is there and the nils are necessary. With Go 1.18, you can now provide this code:
I've been using this with AWS SDK Go code for a little while now and has been working nicely. No more trying to figure out the exact type. Rough usage would look something like this:
Also, an alternative to this is to provide setters so the setters deal with the references instead of the end user. Something like:
Lastly, to help with required/vs optional props, perhaps solve that with a
New
function?The UX isn't great though (cannot define inline), but combined with setters, maybe not as bad?
In the end, these are some random thoughts and I wanted to express them somewhere. 100% feel free to close 馃槃 馃憤
The text was updated successfully, but these errors were encountered: