TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Go refusing to make structs in maps mutable since 2012

2 pointsby ivorasalmost 3 years ago
I&#x27;ve recently asked if it&#x27;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:<p>https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;53857<p>Since arrays work fine, if a is a slice or an array:<p>a[10].field = 42<p>it seems bogus that maps don&#x27;t; this doesn&#x27;t compile in Go if m is a map:<p>m[10].field = 42<p>In both cases, the address of the struct is calculated at runtime, as it must be known to access the field.<p>Instead of leaving this as a rant, let&#x27;s make it a question: what&#x27;s your &quot;what is this insanity?&quot; peeve with your favourite language?

1 comment

0xjnmlalmost 3 years ago
&gt; it seems bogus that maps don&#x27;t; this doesn&#x27;t compile in Go if m is a map:<p>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.<p>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?