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

Rethink the setters paradigm #91

Open
xibz opened this issue Jul 31, 2024 · 0 comments
Open

Rethink the setters paradigm #91

xibz opened this issue Jul 31, 2024 · 0 comments

Comments

@xibz
Copy link

xibz commented Jul 31, 2024

Setters are not heavily used in Go, so we should revisit a more idiomatic approach either by setting things on the struct directly or using functions options which is pretty standard in Go

So instead of

event := cdevents.NewSomeCDEvent()
event.SetFoo("foo")

we'd have something more like

event := cdevents.NewSomeCDEvent(cdevent.SomeCDEventOptions.WithFields(func(e cdevents.SomeCDEvent) {
    e.Foo = "foo"
})

// or
event := cdevents.NewSomeCDEvent(cdevent.SomeCDEventOptions.WithFoo("foo"))

Or a combination of the two. So is one better than the other? Not necessarily. But one is more idiomatic, and that's crucial for SDKs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: No status
Development

No branches or pull requests

1 participant