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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(go) - research using generics for improved UX #3276
Comments
I extensively prototyped in the https://github.com/aws/jsii/tree/rmuller/explore/go1.18-generics branch. Here are some of the high-level findings (pending a more comprehensive writeup):
|
These definitely look like some significant improvements that at first glance appear to make the Go experience easier to get started with and understand. We should work towards providing a working experience for users to try and provide feedback on though if possible without rewriting too much of our current implementation, if only to provide further validation without committing to an entirely new approach. |
Additional notes in aws/aws-cdk-rfcs#397 |
|
馃殌 Feature Request
Affected Languages
TypeScript
orJavascript
Python
Java
C#
,F#
, ...)Go
General Information
JSII Version: 1.49.0
Platform: *
This feature might incur a breaking change
Description
Go 1.18 is scheduled to release as stable in Feb 2022 with support for generic types. This new feature allows us to potentially take an alternative approach to supporting
optional values
, enabling type casting, and various runtime improvements.Proposed Solution
Optional Types
Definition of some wrapper type like:
Would allow code generating
Optional[Type]
instead of*Type
everywhere. This largely would have similar semantics to the user as all types, regardless of whether they are optional or required in typescript, would have to be this wrapper type in order to uphold backwards compatibility guarantees as detailed in the RFC. It may however emerge as the more idiomatic solution once generics are commonly used in Go, and they can be defined inline instead of using a utility function likejsii.String
or needing to allocate a variable previously.Additionally this could simplify reflection code within the Go runtime where currently some relatively complicated logic exists around inspecting and dereferencing pointers during reflection.
Type Casting
We may be able to define a function, returning a generic type representing a parent or child class (in typescript) to support downcasting as needed for escape hatches.
Runtime Improvements
Changing JSII runtime functionality to use generics:
Could potentially give stronger compile time guarantees for the runtime library and generated code and reduce the usage of unsafe pointer manipulation.
The text was updated successfully, but these errors were encountered: