February 2022 Online: Go 1.18 New Features

Meetup #74 on February 17 Please RSVP at Meetup.

We will be meeting online using this Online Meeting at 6:30pm MST.

Agenda

Go 1.18 New Feature: Generics

Peter Preeper gave an introduction to Go 1.18 generics, the long-awaited feature that lets algorithms be written in terms of types specified later. He contrasted the boilerplate of pre-generics code — separate SumInts/SumFloats and EqualInt/EqualString functions — with the new generic versions, explaining type parameters, constraints, and unions. The talk covered comparable and any, defining constraint interfaces such as a numeric union, and using an interface as a constraint. A bubble-sort example showed the non-generic version shrinking from 106 lines to 26 with a single generic function, and benchmarks showed generics carried essentially no performance penalty.

Key points:

  • Generic programming writes algorithms against types specified later.
  • Type parameters and constraints define what a type argument may be.
  • comparable allows ==/!=; any is roughly equivalent to interface{}.
  • Unions like int64 | float64 list allowed types and can live in an interface.
  • Generics cut duplication — the sort example went from 106 lines to 26.
  • Benchmarks showed generic and non-generic code performed about the same.

(source)

Future Topics Discussion

Open discussion on topic for future talks, workshops, activities.

News

Articles & Resources

Events

  • Edmonton Go Meetup - March