From the course: Deep Dive Into Go Lang Interfaces

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Using generics to avoid the empty interface

Using generics to avoid the empty interface

From the course: Deep Dive Into Go Lang Interfaces

Using generics to avoid the empty interface

- [Instructor] In Go 1.18, we got generics, which means that interfaces are now not just a set of methods, but also can be a set of types, and generics helps us avoid using the empty interface. And the nice thing about generics is that they work in compile time, versus reflection that works at runtime. Why is it important? NASA did the research on the cost of fixing an error in a project, not just NASA projects, but projects in general. And they didn't give a cost in hours or days. They just said that finding an error during requirement is the price of one. During design, it's eight. During build, it's 36. In testing, it's 177, and in operations, it is 1600 and change. So what we're trying to do is we're trying to shift the detection of errors to the left. And as we move them from the operations, which is runtime or maybe even testing, into the building state, this is much, much more effective to find and fix them. By the way, another takeout from this slide is that you should really…

Contents