on
Go Patterns?
I came across a repository on github that consolidated simple examples exhibiting design patterns in Go. In the beginning I thought that was a great resource, but after a while I got a bit confused. You will find a list of patterns like creational, structural, behavioural, synchronization, concurrency, messaging, stability, profiling, idioms and anti-patterns. You find patterns like Abstract Factory, Singleton, Bridge, Decorator, Mutex, Semaphore, Coroutines, and many more. My favourites are synchronization and concurrency.
I will start from the basics, first it seems that these patterns are based on an Wikipedia page regarding software design patterns, but mainly object oriented (OO) design patterns. Why do you want to take the concept of OO patterns and apply it to a procedural language like Go?
If you take a closer look on synchronization and concurrency patterns you will see a bunch of “patterns”, on how to implement low-level primitives and mechanisms. Such primitives and mechanisms already exist and actually they are first class citizens of the language. After all Go is famous for concurrency. So, implementing in high level code semaphores and mutexes is meaningless.
My question, is why do we need patterns for existing synchronization primitives?
Well, we don’t. It makes much more sense to call this repo go-examples
, since
you will find examples of Go code, on how to implement certain functionalities.
I hope people don’t follow them by the “book”, rather they apply some filtering (aka reasoning to them).