Consider using generics with Go 1.18 #626
simar7
started this conversation in
Development
Replies: 1 comment
-
Converting into discussion.. this isn't very actionable as an issue |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Motivation
Tracee today accepts and works with raw
interface{}
types in some places. While this is acceptable to a certain extent to avoid duplication and reuse, it requires a lot of setup and checking code like this:tracee/tracee-rules/output.go
Lines 38 to 39 in 5dc1352
Full list of
interface{}
usage (some results may or may not be relevant): https://github.com/aquasecurity/tracee/search?l=Go&q=interface%7B%7DImprovement
With Go 1.18 generics are likely to be available as highlighted https://groups.google.com/g/golang-dev/c/U7eW9i0cqmo/m/ffs0tyIYBAAJ
Besides the obvious benefits of using a generic type of an interface type (less type conversions, etc.) It will also help to write stronger tests as type safety is a test in itself.
While Go 1.18 won't be out until 2022 it's something to consider so I'm documenting it.
References
A good primer on what this change brings to the table in terms of code changes and safety https://quii.gitbook.io/learn-go-with-tests/meta/intro-to-generics
Beta Was this translation helpful? Give feedback.
All reactions