News for hackers. Stuff that matters.
Re:Decorators in Go using embedded structs by ljm on Wednesday October 23, 2019 @03:09PM (#21337790)
There’s probably more but the singular best use-case I’ve found for embedding a struct is when you want a mutex.

That is elegant.

This example looks nice, but I think the naming of the structure and interfaces makes it hard to follow and a cache doesn’t necessarily benefit from it. In fact, it’s worse if your cache isn’t in-memory, and you’re not sharing an instance or a connection pool. If you are, this is just indirection and you can live with `Cache.get` just as well.

Re:Decorators in Go using embedded structs by sethammons on Wednesday October 23, 2019 @03:22PM (#21337912)
I'd recommend only embedding a mutex on private structs - you likely don't want to expose Lock and Unlock.