Skip to content

Typed extensions experiment - #52

Closed
alexykot wants to merge 3 commits into
EliCDavis:mainfrom
alexykot:experiment/typed-extensions
Closed

Typed extensions experiment#52
alexykot wants to merge 3 commits into
EliCDavis:mainfrom
alexykot:experiment/typed-extensions

Conversation

@alexykot

@alexykot alexykot commented Dec 18, 2024

Copy link
Copy Markdown
Contributor

just an example, not to be merged

Here's how extensions can be typed enough to be explicitly comparable, and still permit arbitrary custom extensions.

@EliCDavis EliCDavis left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is overall a good refactor to have. You're welcome to include it in your other PR or keep it in this one. your choice!


type Extension interface {
ExtensionID() ExtensionID
Equal(other Extension) bool

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For people who are creating a bunch of extensions, this Equal might become annoying to implement.

In the past I've been thrown weird extension I need to support for one off engagements that end up having a bunch of random extensions (see OWT WFF GLTF extensions).

I think it might be worth moving this into it's own interface. Then the GLTF writer checks if the extension implements this interface, and if so, use the equals function. Else it only uses the pointer equivalence

type EquatableExtension interface {
	Extension
	Equal(other Extension) bool
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this could be an option. Although this becomes quite an obscure feature that is non-trivial to even find. Clarity and self-explanation of the API is valuable as well, and what would be the right tradeoff here is unclear to me.

Maybe adding comments around this interface explaining what it does would be sufficient.
Or the user could always do something like if they're in a rush 🙂:

func (my MyExt) Equal(other Extension) bool {
    return my == other
}

Either way - I don't feel informed enough to suggest the right tradeoff here. I have only one case - my own, and that's not enough to decide the interface for all users, at least not in the situation where no obvious optimal solution exists.

@alexykot

Copy link
Copy Markdown
Contributor Author

Nah, thanks, I'll pass on this one 🙂

I have no direct need for this one at the moment, and my concerns are solved with #51. This is just a suggestion.
Maybe some other time when I'll have a need in this kind of thing on my end.

@alexykot

Copy link
Copy Markdown
Contributor Author

I mean - I didn't intend to actually implement this one, this was more of a talking point than an design draft.

I've closed it now.

@alexykot alexykot closed this Dec 18, 2024
@alexykot
alexykot deleted the experiment/typed-extensions branch December 18, 2024 17:07
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

Successfully merging this pull request may close these issues.

2 participants