You're unable to read via this Friend Link since it's expired. Learn more
Member-only story
Golang 1.18: What You Need To Know
There are two major things coming in Go 1.18 that you need to know: Type Parameters (generics) and Fuzz Testing, but why are they so important?

The Golang team is hard at work on Golang 1.18, which will be released in February 2022, and it looks like it’s going to be a big one. Golang 1.18 will introduce generics (called type parameters) as well as fuzzy testing, which has the potential to change how we develop and test Golang programs for good! We’ll take a look at both of these new features below.
Type Parameters (aka Generics)
Type parameters (also known as generics in other languages) will allow Go programmers to define functions and methods with a placeholder type name. This will allow developers to write code that can be reused throughout different parts of the project but still work generically for all the types of data they expect it to support.
Let’s take a look at a normal Go function (before 1.18), which returns the lowest number of two inputs:
As you can see, we take two integers as parameters. min(1,2)
and min(2,1)
will both return 1
. So far so good, but what happens when you want to get the lowest number of two float values? We would have to write a new function, which takes two float values as parameters, and we wouldn’t be able to reuse the code from our first one. The body of the function would still be the exact same code. If we want to get the minimum of two float64 values, we would have to introduce the same function again with float64 as parameters.
Now let’s take a look at generics in Go:
The biggest change that generics bring is that you can now define functions with an arbitrary placeholder type name which will later serve as a parameter for other types. In Go, generics are written in the form of type T
.
This means that you can define a function with any placeholder type name, which will be…