Hi, this has been discussed many times, e.g. https://groups.google.com/g/golang-nuts/c/5_8E9OblIho/m/b9O038mzBQAJ In short: The semantics of maps require them to be pointer-shaped. Currently, all zero values are a sequence of zero bytes (making it very cheap to initialize to them). That means the zero value of maps can't be made useful in that manner. It's unfortunate, but seems necessary.
On Wed, Oct 7, 2020 at 9:06 AM Amnon <amno...@gmail.com> wrote: > Go generally ensures that zero values are useful. > > So a zero slice allows us to append to it, without having to do any > special initialization. > > This approach also extends to the standard library. > > sync.Mutexs are unlocked and usable in the zero state. > > Even zero sync.Maps ready for use. > > So why are maps different? Why is it necessary to make a map, before it > can be assigned to? > Is there any use case where a zero map which can not be assigned to is > useful? > > -- > 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/14e25f79-8fab-4cec-8c00-fedd26488014n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/14e25f79-8fab-4cec-8c00-fedd26488014n%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/CAEkBMfGu4ax4U%2BUbGtuTfe7Tu1zsZZs_rySnn0Bgrt83KcyqUw%40mail.gmail.com.