Nils Kasseckert
Go Generics
#1about 1 minute
Understanding the basics of generic programming in Go
Generic programming allows you to write type-independent code, which was introduced in Go 1.18 with type parameters, type sets, and type inference.
#2about 4 minutes
Using type parameters to write type-independent functions
Type parameters, declared in square brackets, allow a single function to operate on multiple numeric types, eliminating code duplication.
#3about 1 minute
Simplifying functions with predefined type constraints
Go provides built-in constraints like `constraints.Integer` and `constraints.Float` to easily define what types a generic function can accept.
#4about 5 minutes
Defining custom type constraints using interfaces and typesets
Interfaces now define a set of types, not just methods, and the tilde (~) operator can be used to include a type's underlying types in a constraint.
#5about 3 minutes
Nesting and simplifying constraints with the 'any' keyword
Type constraints can be restricted by other constraints, and the `any` keyword serves as a convenient alias for an empty interface to simplify declarations.
#6about 6 minutes
How Go uses function argument and constraint type inference
The compiler can infer type arguments from function parameters, but they must be specified explicitly for types used only in return values.
#7about 3 minutes
A practical example of loading YAML files with generics
A generic function can load YAML data into any struct, but using the `any` constraint sacrifices compile-time type safety.
#8about 1 minute
Using marker interfaces to enforce type safety with generics
A marker interface with a unique method can be used as a type constraint to ensure only intended structs are passed to a generic function.
#9about 1 minute
Key takeaways and summary of Go generics
Generics in Go 1.18 use type parameters and constraints to create flexible functions, supported by type inference to simplify calls.
#10about 1 minute
Q&A: The trade-offs of losing type safety
Using generics without proper constraints can lead to a loss of type safety, but the benefit is often less and more readable code.
Related jobs
Jobs that call for the skills explored in this talk.
Matching moments
04:07 MIN
An overview of the Go programming language
Concurrency with Go
Unlock Moments
Create a free account to watch a limited number of Moments each month.
Upgrade to PRO for unlimited access to the full archive.
Upgrade to PRO for unlimited access to the full archive.
You have an account? Log in
10:34 MIN
Evolving the type system for generic programming with concepts
The Design and Evolution of C++
Unlock Moments
Create a free account to watch a limited number of Moments each month.
Upgrade to PRO for unlimited access to the full archive.
Upgrade to PRO for unlimited access to the full archive.
You have an account? Log in
02:36 MIN
Creating generic components with `$$Generic`
Svelte ♥ TypeScript and so will you
Unlock Moments
Create a free account to watch a limited number of Moments each month.
Upgrade to PRO for unlimited access to the full archive.
Upgrade to PRO for unlimited access to the full archive.
You have an account? Log in
02:06 MIN
Allowing ref struct types in generic parameters
C# 13 Unleashed: Live Demos of my Top 10 Cutting-Edge Features!
Unlock Moments
Create a free account to watch a limited number of Moments each month.
Upgrade to PRO for unlimited access to the full archive.
Upgrade to PRO for unlimited access to the full archive.
You have an account? Log in
05:03 MIN
Using generics and keyof to enforce message contracts
Where we're going we don't need JavaScript - Programming with Type Annotations
Unlock Moments
Create a free account to watch a limited number of Moments each month.
Upgrade to PRO for unlimited access to the full archive.
Upgrade to PRO for unlimited access to the full archive.
You have an account? Log in
04:10 MIN
The benefits of data-oriented programming over custom types
Java with a Clojure mindset
Unlock Moments
Create a free account to watch a limited number of Moments each month.
Upgrade to PRO for unlimited access to the full archive.
Upgrade to PRO for unlimited access to the full archive.
You have an account? Log in
01:05 MIN
Adopting a generic-first mindset to improve code quality
Hello generics, goodbye boilerplate!
Unlock Moments
Create a free account to watch a limited number of Moments each month.
Upgrade to PRO for unlimited access to the full archive.
Upgrade to PRO for unlimited access to the full archive.
You have an account? Log in
06:45 MIN
Writing reusable code with generic programming and templates
101 brilliant things of C++
Unlock Moments
Create a free account to watch a limited number of Moments each month.
Upgrade to PRO for unlimited access to the full archive.
Upgrade to PRO for unlimited access to the full archive.
You have an account? Log in
Featured Partners
Related Videos
Concurrency with Go
Frank Müller
Lies we Tell Ourselves As Developers
Stefan Baumgartner
C++ Features You Might Not Know
Jonathan Müller
Advanced Typing in TypeScript
Lars Hupel
Where we're going we don't need JavaScript - Programming with Type Annotations
Peter Kröner
Don't compromise on speedy delivery nor type-safety by choosing TypeScript
Jens Claes
101 brilliant things of C++
Andreas Fertig
Hello generics, goodbye boilerplate!
Miroslav Jonaš
Related Articles
View all articles



From learning to earning
Jobs that call for the skills explored in this talk.




SMG Swiss Marketplace Group
Canton de Valbonne, France
Senior


Silbury Deutschland GmbH
Intermediate
NoSQL
Docker
Node.js
Kubernetes
Microservices
+1


