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

data/binding: Use generics instead of generator script #5378

Closed
2 tasks done
Jacalz opened this issue Jan 8, 2025 · 6 comments
Closed
2 tasks done

data/binding: Use generics instead of generator script #5378

Jacalz opened this issue Jan 8, 2025 · 6 comments
Labels
data binding Issue related to bug or improvement of data binding refactor Issues related to refactoring code.

Comments

@Jacalz
Copy link
Member

Jacalz commented Jan 8, 2025

Checklist

  • I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
  • This issue only relates to a single feature. I will open new issues for any other features.

Is your feature request related to a problem?

With #5377 landed, there is only the code generation for data binding left. As there is quite a lot of code duplication between the binding types, this would be a wise place to apply generics and decrease our reliance on code generation. This should improve developer ergonomics and make the code easier to understand.

Is it possible to construct a solution with the existing API?

I think so. It might be possible to rewrite some internal types to use generics without impacting the public API but I think a nice change for v3.0.0 further down the line would be to have a public generic API for bindings (far into the future but anyway).

Describe the solution you'd like to see.

Clean up data binding using generics to try and remove code generation as much as possible.

@Jacalz Jacalz added enhancement New feature or request refactor Issues related to refactoring code. data binding Issue related to bug or improvement of data binding and removed enhancement New feature or request labels Jan 8, 2025
@andydotxyz
Copy link
Member

We need to pay attention to the possible need for comparators as well - the custom types in tree/list need to be able to do change detection which we are falling short on at the moment.

@Jacalz
Copy link
Member Author

Jacalz commented Jan 12, 2025

Indeed. The cmp package may be useful for that: https://pkg.go.dev/cmp

@Jacalz
Copy link
Member Author

Jacalz commented Jan 16, 2025

We might wish to add a generic alternative to Untyped instead and deprecate that one.

@andydotxyz
Copy link
Member

We might wish to add a generic alternative to Untyped instead and deprecate that one.

Add yes - but I don't think we need to deprecate just because there is a generic alternative. Unless there is a reason to remove the non-generic version?

@Jacalz
Copy link
Member Author

Jacalz commented Jan 17, 2025

Add yes - but I don't think we need to deprecate just because there is a generic alternative. Unless there is a reason to remove the non-generic version?

If the generic does basically the same thing and we avoid having to rely on slow (and in my opinion being a bad practice) reflect code was my idea. Type safety is always nicer in my opinion :)

@Jacalz Jacalz changed the title Rework data binding to use generic types data/binding: Use generics instead of generator script Feb 5, 2025
@Jacalz Jacalz added this to the "F" release, Early 2025 milestone Feb 5, 2025
@Jacalz
Copy link
Member Author

Jacalz commented Feb 5, 2025

Done :)

@Jacalz Jacalz closed this as completed Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data binding Issue related to bug or improvement of data binding refactor Issues related to refactoring code.
Projects
None yet
Development

No branches or pull requests

2 participants