exercism / go

Exercism exercises in Go.
https://exercism.org/tracks/go
MIT License
991 stars 654 forks source link

Remove suggestion of `sync.Map` from Parallel Letter Frequency #2257

Closed andrerfcsantos closed 2 years ago

andrerfcsantos commented 2 years ago

In instructions.append.md for parallel-letter-frequency, we have a link for the docs of sync.Map.

Some students actually read this and get the idea they should use a sync.Map. This is terrible advice for this exercise because:

  1. Even the docs discourage the use of this map, and mention that when types for the map are known, a regular and properly typed map + mutex is better:

The Map type is specialized. Most code should use a plain Go map instead, with separate locking or coordination, for better type safety and to make it easier to maintain other invariants along with the map content. Source: sync.Map

  1. Using a map and protecting it with locks (either by using sync.Map or a regular map + mutexes) is not the best way to solve the exercise. It's best to avoid lock contention altogether by letting each goroutine have its own map and communicate these maps through channels.

My suggestions here are:

Jasstkn commented 2 years ago

That's true. Firstly, I was trying to use sync.Map but it wasn't obvious how to do it and I failed. For me also several articles were helpful:

Jasstkn commented 2 years ago

@andrerfcsantos hey. do you mind if I work on it? Let me know if you think any of the links that I posted may be useful for students as well.

andrerfcsantos commented 2 years ago

Sure! Thanks for taking interest in the issue. Yeah, I think those links are good, feel free to include them.