←back to thread

Go subtleties

(harrisoncramer.me)
235 points darccio | 2 comments | | HN request time: 0s | source
Show context
furyofantares ◴[] No.45670487[source]
I balked a little when the article refers to format strings as "string interpolation" but there's multiple comments here running with it. Am I out of date and we just call that string interpolation these days?

I also found this very confusing:

> When updating a map inside of a loop there’s no guarantee that the update will be made during that iteration. The only guarantee is that by the time the loop finishes, the map contains your updates.

That's totally wrong, right? It makes it sound magical. There's a light explainer but I think it would be a lot more clear to say that of course the update is made immediately, but the "range" iterator may not see it.

replies(3): >>45670749 #>>45671865 #>>45672599 #
1. gethly ◴[] No.45672599[source]
Mutating maps during iteration is a big red flag.
replies(1): >>45673179 #
2. furyofantares ◴[] No.45673179[source]
Yep. Which is part of why I'd much rather talk accurately about it being the iterator that may or may not encounter newly added values.

That makes it a lot clearer where the problem is, which is also where the solution is: get the list of keys you want to work on ahead of time and iterate over those while modifying the map.