I wonder what is the most down to earth explanation of this famous quote:
Don\'t communicate by sharing memory; share memory by communicating. (R. Pik
This famous quote can be a little bit confusing if taken too litterally. Let's break it down to its more basic components, and define them properly:
Don't communicate by sharing memory; share memory by communicating
---- 1 ---- ------ 2 ----- ---- 3 ----- ----- 4 -----
int or a complicated data structure like a map, and give away ownership by sending the value or a pointer to the value to a different goroutine via the channel mechanism. So ideally, there is no shared space, each goroutine only sees the portion of memory it owns.In conclusion, what the quote means can be summed up like this:
Don't overengineer inter-thread communication by using shared memory and complicated, error-prone synchronisation primitives, but instead use message-passing between goroutines (green threads) so variables and data can be used in sequence between those.
The use of the word sequence here is noteworthy, because it describes the philosophy that inspired the concept of goroutines and channels: Communicating Sequential Processes.