When to use generics?
The decision to finally incorporate generics into the Go programming language was not a trivial one. As they are such a large change to the language, it is important to remember our roots as developers and not to allow support such as generics to change how we write our code. In other words, you should continue writing normal Go code and not overly design types right from the get-go. These are fundamental Go philosophies rooted in simplicity and readability, which are the core tenets of the language.
The following is a synopsis of insights to consider when incorporating Go generics into a code base:
- Write normal Go code, and don’t design types: Start with your typical concrete types and straightforward functions, leveraging Go’s strong static typing and simplicity. Generics were never meant to replace the fundamental principles guiding the use of the language but, rather, be a tool to be applied judiciously.
- Avoid boilerplate code...