On Tue, Jun 8, 2021 at 6:36 AM Marvin Renich <m...@renich.org> wrote:
> You say that test cases of Log work fine, but they are only fine in a > non-concurrent environment. The instant you test Log (without > interfaces) in a concurrent program it fails in an obvious manner. > nit: I don't think concurrency has anything to do with it either. The failure mode is making a copy and expecting the copy and the original to share memory. If anything, concurrency (in a test) would make it more likely to get hidden, by increasing the likelihood that a closure is used, which implicitly shares a pointer: https://play.golang.org/p/Gwj9GScjQBJ Of course, concurrency then also makes the failure easy to see, as long as you remember to run your tests with `-race`. FWIW I agree with Robert that it's relatively easy to write a test for this that never copies the value (though even then, if you think about using atomics you definitely should think about writing a concurrent test and running it with `-race` enabled, which should show the problem). I disagree with him, however, that interfaces make it more likely to run into the problem when *using* the code. Any even remotely realistic usage of that code is broken. Even if you failed to write tests which surface that breakage. > Interfaces, and their ability to potentially be satisfied by either a > non-pointer type or a pointer type, depending on the type, is not the > problem here. > > ...Marvin > > -- > 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/20210608043609.gguu3t3hqbsziema%40basil.wdw > . > -- 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/CAEkBMfGa5B99OO8oTxJOWFSuJPinPF3b1QJWEuqMD4ZPAiCi%3DQ%40mail.gmail.com.