Tiny abstractions with functions in Go.

Mat Ryer · 7 Dec 2020

Tiny abstractions with functions in Go.

Mat Ryer · 7 Dec 2020

Abstractions are one of the most useful tools in a programmer’s belt, but early abstraction (carving them out before you should, when you don’t have enough information) remains one of our biggest sins.

Since Go functions and methods are values, we can write small, low-commitment abstractions which can not be too complicated, while still providing flexibility and improved testability.

Functions are values

This is valid Go code:

greet := func(name string) string {
	return "Hello, " + name
}
fmt.Println(greet("Mat"))
// Output: Hello, Mat

We create a variable called greet (which has the type func(string) string) and assign it to an actual Go function.

We can call it like we would any other function, greet("Mat").

This works because functions in Go are values.

We can pass functions into other functions, and store them in structs, and even return them from other functions.

Tiny abstractions


Learn more about what we're doing at Pace.

A lot of our blog posts come out of the technical work behind a project we're working on called Pace.

We were frustrated by communication and project management tools that interrupt your flow and overly complicated workflows turn simple tasks, hard. So we decided to build Pace.

Pace is a new minimalist project management tool for tech teams. We promote asynchronous communication by default, while allowing for those times when you really need to chat.

We shift the way work is assigned by allowing only self-assignment, creating a more empowered team and protecting the attention and focus of devs.

We're currently live and would love you to try it and share your opinions on what project management tools should and shouldn't do.

What next? Start your 14 day free trial to see if Pace is right for your team


First published on 7 Dec 2020 by Mat Ryer
#golang #concepts #coding #patterns

or you can share the URL directly:

https://pace.dev/blog/2020/12/07/tiny-function-abstractions.html

Thank you, we don't do ads so we rely on you to spread the word.

https://pace.dev/blog/2020/12/07/tiny-function-abstractions.html


You might also like:

The tech stack at Pace #Tech #Golang #Svelte

Respond to Ctrl+C interrupt signals gracefully #Golang #Patterns

Programatically generate gorgeous social media images in Go #Golang #SocialMedia #Graphics

Subscribe:
Atom RSS JSON