Go Generics in 2 Hours
Published by O'Reilly Media, Inc.
Using the latest language features and syntax to remove complexity from your code
Go 1.18 introduces the ability to write generic behavior where you declare and use functions or types that are written to work with any of a set of types provided when you invoke them. Go developers can remove complexity from their code and avoid the risks associated with using the empty interface (interface{}) or reflection to achieve what Go now offers out of the box with generics.
Generics in Go brings a much-requested update to the language but also the need to understand how the type system has evolved to support the capability. This training will introduce you to the new syntax you must understand before using generics and important concepts such as type parameters, type constraints, type approximations, built-in constraints, and more.
What you’ll learn and how you can apply it
By the end of this live, hands-on online course, you’ll understand:
- How to use type parameters
- How to declare and use type constraints
- How to invoke type-constrained functions
- How to use the built-in constraints the standard library makes available
And you’ll be able to:
- Refactor code that once used interface{} and reflection to be simpler with generics
- Explore slices, maps, and channels, whichwhat generics now make possible with other areas of the language, including slices, maps, and channels
This live event is for you because...
- You’re an existing user of Go or are at least comfortable with it
- You want to understand what generics bring to the table
- You want to know when and when not to use generics
Prerequisites
- Intermediate understanding of Go syntax
Recommended preparation:
Recommended follow-up:
- Watch Robert Griesemer and Ian Lance Taylor: Generics AMA (video)
Schedule
The time frames are only estimates and may vary according to how the class is progressing.
Getting to know Go Generics (60 minutes)
- Presentation: Introducing type parameters
- Presentation: Introducing type constraints
- Exercise: Writing generic functions
- Q&A: 5 minutes
- Break (5 minutes)
Working with Constraints (45 minutes)
- Presentation: Custom type constraints
- Presentation: Built-in type constraints
- Exercise: Working with type constraints
- Q&A (5 mins)
What’s Next for Generics (15 minutes)
- Presentation: How language elements like slices, maps, and channels might benefit from generics
- Q&A
Your Instructor
Johnny Boursiquot
Johnny Boursiquot is a site reliability engineer at Salesforce Heroku. A multidisciplined software and cloud engineer with over two decades of industry experience, he enjoys training developers and is the mind behind the well-liked Go Standard Library Solutions video course. His love for technology is matched only by his passion for community service, especially within the Go community. He’s a GoBridge core member, the founder and organizer of the Baltimore Go User Group, and a previous organizer of both the Boston Ruby User Group and the Boston Go User Group. He’s a regular speaker and trainer at GopherCon, where he’s also a program chair.