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.

Fixing the other Go loop bug

62 pointsby dmartoover 1 year ago

3 comments

fifiluraover 1 year ago
This is typical of the bugs you have to worry about when working with a language that favors mutability.<p>With immutables you simply map on players list and continue working with the copy.<p>Bugs avoided. Performance concerns - maybe they exist - but show me them first.
评论 #38178764 未加载
评论 #38188333 未加载
tylerhouover 1 year ago
This is not really a bug -- it&#x27;s a natural consequence of supporting value semantics.<p>The Go code<p><pre><code> var player Player otherPlayer := player otherPlayer.score = 0 </code></pre> has the exact same &quot;bug.&quot;<p>This isn&#x27;t something that should be fixed by the language. Instead, a linter rule that detects that the write is never read would catch this.
评论 #38185714 未加载
评论 #38189193 未加载
评论 #38181466 未加载
rurbanover 1 year ago
Not a bug but a feature.<p>Go favors concurrency safety and concurrency efficiency. Therefore it has to copy loop values to be able to parallelize them. With a reference this would be unsafe to do.
评论 #38189676 未加载