On Wed, 9 Oct 2024 at 10:42, 'Brian Candler' via golang-nuts < golang-nuts@googlegroups.com> wrote:
> On Tuesday 8 October 2024 at 07:37:25 UTC+1 Axel Wagner wrote: > > the only one on the "mixing receiver kinds is sometimes necessary, so we > shouldn't caution against it" side of the table > > > To me this sounds like a false dichotomy. It can be good general > good-practice advice to avoid mixing pointer and value receivers (for > various reasons including those raised by Robert Engels), and at the same > time, in cases where it is necessary to do so, then clearly it has to be > done (by definition of "necessary") as long as it's done with care > ("caution"). > Sure. The reason I brought this up in the first place, is that I have not really seen anyone qualifying that advice, anywhere. Not to belabour that point, but before you, no one in this thread acknowledged that there *are* exceptions. And one of the first responses I got was that one of the most popular Go IDEs has a linter enabled by default, that seems to complain about that (I can't confirm that, as I don't use it). So it seemed to me, that a lot of people *do* take it as a pretty hard rule. Not as hard as a compilation error or a vet failure, but still in a way that they think it is generally agreed that it should never be done. I've just come across this topic a couple of times and even had discussions in code reviews, that linked to the Code Review Comments page. So I felt it's important to qualify it, when it came up here. > The advice quoted is given under "Some useful guidelines" at > https://go.dev/wiki/CodeReviewComments#receiver-type - it's not a > hard-and-fast rule - and is aimed "especially to new Go programmers". If > you know what you need and why, then that's fine. > > As another example: it's general good practice advice to accept interfaces > and return concrete types. But for error values, it's necessary to return > an interface value. That is an exception to the general rule, but doesn't > invalidate it. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/f5be82e4-dd89-40c2-9603-f240748e23dcn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/f5be82e4-dd89-40c2-9603-f240748e23dcn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfEir_gjAF-uBVZxZVEFka%3DPuFmOJzWbumWYoUqSdnhaXg%40mail.gmail.com.