Replies: 4 comments 1 reply
-
I believe it's due to the functional roots from the Elm Architecture where immutability is preferred. Personally I will have functions that use pointer receivers in a |
Beta Was this translation helpful? Give feedback.
-
but it also works with pointers, thus i'm curious about the thoughts behind this |
Beta Was this translation helpful? Give feedback.
-
I wondered about this as well, until I learned more about both Go and Bubbletea and realized two things:
In all but the most trivial examples, I find it clearer to satisfy
More on all that at https://google.github.io/styleguide/go/decisions#receiver-type I think of the the |
Beta Was this translation helpful? Give feedback.
-
I'm a long time Go programmer but have only been using bubbletea for a little while now, it's pretty cool to write nice UI's with Go! Who needs Flutter when you can write TUIs!? 😀 However, this is one of the things in bubbletea that frustrates me a little bit. The design feels inconsistent as there are two ways of writing and using Take for example: func (m myModel) Update(msg tea.Msg) (myModel, tea.Cmd) {
switch msg := msg.(type) {
case someThing:
m.answer = 42 // seems ineffective, linters will warn about this. (1)
m.table.SetWidth(10) // fine to do
}
var cmd tea.Cmd
m.table, cmd = m.table.Update(msg) // not idiomatic Go? (2)
return m, cmd
}
I think it would be best if the tea.Model return value would be dropped from Update(), and pointer receivers used for all models. I understand that changing this will be breaking, but the migration is fairly straightforward. It changes the framework to a single way of writing and using Resulting example: func (m *myModel) Update(msg tea.Msg) (tea.Cmd) {
switch msg := msg.(type) {
case someThing:
m.answer = 42
m.table.SetWidth(10)
}
cmd := m.table.Update(msg)
return cmd
} |
Beta Was this translation helpful? Give feedback.
-
i was wondering why all
tea.Model
's have theirInit
,Update
andView
methods as value receivers instead of pointer receivers (which leads to returning thetea.Model
after each call toUpdate
). any particular reason behind this design choice?PS: sorry if i've not spotted any obvious reasons.
Beta Was this translation helpful? Give feedback.
All reactions