170 Words

Stop Sleeping On First Class Functions In Go

Go has so many great features that draw us in: Channels, Goroutines, static compilation, a simple syntax, etc. But there is one feature that Go supports which needs more love: first class functions. This feature is not unique to Go, and with all the other shiny features to talk about, I think it is all too often overlooked and underutilized.

First class functions (functions as variables) and closures (capturing data in those functions) are two incredibly powerful features that are built right into Go. But even seasoned Go developers often forget these features. We need to fix this!

We are going to go over several cases where these two features massively improve code usability and readability:

  • Dependency Injection
  • Passing functions as arguments to make our code testable
  • Cleaning up Go templates
  • Reducing complexity in templates with closures
  • Hiding channel usage
  • Stop passing channels, pass functions
  • Building an execution pipeline
  • Making ordered operations easy and extensible

Where

Go West 2024

When

Watch it