Skip to content
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

v4: Golang 1.18 Generics #309

Open
hi117 opened this issue Feb 6, 2022 · 4 comments
Open

v4: Golang 1.18 Generics #309

hi117 opened this issue Feb 6, 2022 · 4 comments
Milestone

Comments

@hi117
Copy link
Contributor

hi117 commented Feb 6, 2022

After reading the code quite a bit, reflection is used all over. It seems like with golang 1.18 coming out with generics, quite a bit of this could be replaced with generics. What areas would be best to replace reflection with generics?

@diamondburned
Copy link
Owner

Probably none.

Generics can help replace some of the code duplication, such as the discord.[T]Option types. Reflection is only used in AddHandler(v any), and the new additions won't add any type-safety to that.

@diamondburned
Copy link
Owner

If you can write a prototype of a handler.Handler using generics, I'd be more than happy to consider it. Though I would also want to wait a few months for 1.18 to come out before forcing v3 users to update their Go.

@hi117
Copy link
Contributor Author

hi117 commented Feb 7, 2022

1.18 should be coming out this month, but I understand if you want it to soak for a bit. Also I was thinking adding generics support would be enough to warrant going to v4 as it changes the way you interact with the interface quite a bit.

@diamondburned diamondburned changed the title Golang 1.18 Generics v4: Golang 1.18 Generics Oct 13, 2022
@diamondburned diamondburned added this to the v4 milestone Oct 13, 2022
@diamondburned
Copy link
Owner

This issue turned out to be more complicated than I thought. I expected [T1 any, T2 interface{ T1 }] to work, but it doesn't: https://go.dev/play/p/4s2dZxnNlEf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants