Go refusing to make structs in maps mutable since 2012

2 points by ivoras ↗ HN
I've recently asked if it's time to revisit the decision to make structs in maps in Go mutable, and was politely declined, with a reference to this being a refusted proposal since 2012:

https://github.com/golang/go/issues/53857

Since arrays work fine, if a is a slice or an array:

a[10].field = 42

it seems bogus that maps don't; this doesn't compile in Go if m is a map:

m[10].field = 42

In both cases, the address of the struct is calculated at runtime, as it must be known to access the field.

Instead of leaving this as a rant, let's make it a question: what's your "what is this insanity?" peeve with your favourite language?

1 comment

[ 5.1 ms ] story [ 15.3 ms ] thread
> it seems bogus that maps don't; this doesn't compile in Go if m is a map:

It does not seem bogus to me. Values in a map are not addressable for a good reasons. It allows more freedom in implementing a map. Arrays, on the other hand, are specified to be continuous in memory, hence the implementation is set in stone.

Also, non-existent items of a map return the zero value as specified. Now assume the map items are addressable. What exactly should happen if you refer to a field of a map item that is not in the map? Is there a possibility that is not surprising?