~/devreads

#go

165 posts

18 Dec 2025

Dave Cheney 1 min read

Here’s a small quiz derived from some incorrect advice from an AI coding assistant. This program prints two timestamps; will they be a. Roughly the same time (ie, the same second)b. Roughly 10 seconds apartc. Something else Answer after the fold

go

27 Nov 2025

Dave Cheney 1 min read

Here’s a silly example extracted from real code. Does this program print true or false?

go

27 Feb 2024

21 Feb 2024

Dave Cheney 1 min read

This morning a one line change had several of us tearing up the fabric of reality trying to understand why a failing test wasn’t failing, or, in fact, being run at all. Increasingly frantic efforts to upgrade/downgrade Go, run the tests on another machine, run the tests in CI, all served to only unnerve us […]

gotesting

13 Feb 2024

Rob 2 min read

One nice thing about Go is that it can cross-compile which allows me to use my Mac to build binaries for different operating systems. This is increibly useful for providing binaries for Rodeo, my command line Flickr uploader. To do this we set the GOOS and GOARCH environment variables before calling go build. For example to build for x64 on…

developmentgorodeo flickr uploader

6 Feb 2024

10 Nov 2023

Luciano Mammino 7 min read

The software industry sees an interesting tension between generative AI capturing the software lifecycle and low-level languages aiming for better performance. As developers we must understand these trends and find a strategy. Learn one or both?

opinionjavascriptrustgoai

7 Apr 2023

Emmanuel Joubaud 12 min read

When it comes to the communication between microservices, there are 2 possible extremes: All-sync: whenever a service needs data from another service, it fetches it via a synchronous API call (REST, gRPC, GraphQL). Service calls service calls service… which tends to evolve into layers of APIs, where each layer has dependencies on the next. All-async: no sync calls between services,…

microservicesgosoftware-engineeringsoftware-architectureruby

31 Mar 2023

Emmanuel Joubaud 8 min read

This is an introduction to how we’ve implemented microservices at a mid-size scale-up called Jobteaser , with a mix of Go and Ruby service chassis, gRPC APIs and data replication via Kafka. Foundation: The service chassis Back in early 2019, when Jobteaser decided to get serious about breaking up its decade-old Rails monolith into microservices, we assembled a Foundation team…

microservicesgosoftware-architecturerubysoftware-engineering

11 Dec 2022

Henrik Warne 5 min read

A few months ago I switched to working in Go. Before that, my main language was Python for many years. The change to Go has been very smooth, without any major surprises or stumbling blocks. This may partly be because … Continue reading →

programminggogolang

5 Jan 2021

Dave Cheney 6 min read

Today’s post comes from a recent Go pop quiz. Consider this benchmark fragment. A convenience wrapper around sort.Sort(sort.StringSlice(s)), sort.Strings sorts the input in place, so it isn’t expected to allocate (or at least that’s what 43% of the tweeps who responded thought). However it turns out that, at least in recent versions of Go, each […]

goprogramming

19 Jun 2020

Dave Cheney 1 min read

The Go compiler’s SSA backend contains a facility to produce HTML debugging output of the compilation phases. This post covers how to print the SSA output for function and methods. Let’s start with a sample program which contains a function, a value method, and a pointer method: Control of the SSA debugging output is via […]

goprogrammingcompilergossafuncssa

24 May 2020

Dave Cheney 2 min read

Per the overlapping interfaces proposal, Go 1.14 now permits embedding of interfaces with overlapping method sets. This is a brief post explain what this change means: Let’s start with the definition of the three key interfaces from the io package; io.Reader, io.Writer, and io.Closer: Just as embedding a type inside a struct allows the embedded type’s […]

goprogrammingcompilerinterfaces

16 May 2020

Dave Cheney 5 min read

A few days ago Fatih posted this question on twitter. I’m going to attempt to give my answer, however to do that I need to apply some simplifications as my previous attempts to answer it involved a lot of phrases like a pointer to a pointer, and other unhelpful waffling. Hopefully my simplified answer can […]

goprogrammingjson

9 May 2020

Dave Cheney 5 min read

Conventional wisdom dictates that the larger the number of types declared in a Go program, the larger the resulting binary. Intuitively this makes sense, after all, what’s the point in defining a bunch of types if you’re not going to write code that operates on them. However, part of the job of a linker is […]

goprogramming

2 May 2020

Dave Cheney 6 min read

In the previous post I discussed how leaf inlining allows the Go compiler to reduce the overhead of function calls and extend optimisation opportunities across function boundaries. In this post I’ll discuss the limits of inlining and leaf vs mid-stack inlining. The limits of inlining Inlining a function into its caller removes the call’s overhead […]

goprogramminginliningoptimisationperformance

25 Apr 2020

Dave Cheney 6 min read

This is a post about how the Go compiler implements inlining and how this optimisation affects your Go code. n.b. This article focuses on gc, the de facto Go compiler from golang.org. The concepts discussed apply broadly to other Go compilers like gccgo and tinygo but may differ in implementation and efficacy. What is inlining? […]

goprogramminginliningoptimisationperformance

10 Mar 2020

Dave Cheney 1 min read

The testing package is one of my favourite packages in the Go standard library, not just because of its low noise approach to unit testing, but, over the lifetime of Go, it has received a steady stream of quality of life improvements driven by real world usage. The most recent example of this is, in […]

goprogrammingtestingunit test

1 Mar 2020

Dave Cheney 1 min read

Programmers have a tendency to be superstitious. Particularly, when a programmer hears that copies are expensive, they start to see them everywhere, especially when they learn that, in Go, every assignment is a copy. Consider this code; x is three orders of magnitude larger than y, is the assignment of x to a more expensive […]

goperformanceslices

23 Feb 2020

Dave Cheney 22 min read

This article was derived from my GopherCon Israel 2020 presentation. It’s also quite long. If you’d prefer a shorter version, head over to the-zen-of-go.netlify.com. A recording of the presentation is available on YouTube. How should I write good code? Something that I’ve been thinking about a lot recently, when reflecting on the body of my […]

gosmall ideasdesign

8 Dec 2019

Dave Cheney 5 min read

This is a thought experiment in API design. It starts with the classic Go unit testing idiom: func TestOpenFile(t *testing.T) { f, err := os.Open("notfound") if err != nil { t.Fatal(err) } // ... } What’s the problem with this code? The assertion. if err != nil { ... } is repetitive and in the […]

gosmall ideastesting

6 Oct 2019

Dave Cheney 2 min read

In the beginning, before the go tool, before Go 1.0, the Go distribution stored the standard library in a subdirectory called pkg/ and the commands which built upon it in cmd/. This wasn’t so much a deliberate taxonomy but a by product of the original make based build system. In September 2014, the Go distribution […]

goprogrammingpkgproject layout

24 Sept 2019

Dave Cheney 1 min read

APIs should be easy to use and hard to misuse. — Josh Bloch A good example of a simple looking, but hard to use correctly, API is one which takes two or more parameters of the same type. Let’s compare two function signatures: What’s the difference between these functions? Obviously one returns the maximum of […]

goprogramming

5 Sept 2019

Dave Cheney 3 min read

This is a post about performance. Most of the time when worrying about the performance of a piece of code the overwhelming advice should be (with apologies to Brendan Gregg) don’t worry about it, yet. However there is one area where I counsel developers to think about the performance implications of a design, and that […]

goprogrammingperformance

20 Aug 2019

Dave Cheney 6 min read

Go allows authors to write functions in assembly if required. This is called a stub or forward declaration. package asm // Add returns the sum of a and b. func Add(a int64, b int64) int64 Here we’re declaring Add, a function which takes two int64‘s and returns their sum.Add is a normal Go function declaration, […]

go

8 Jul 2019

Dave Cheney 11 min read

This article is based on my GopherCon Singapore 2019 presentation. In the presentation I referenced material from my post on declaring variables and my GolangUK 2017 presentation on SOLID design. For brevity those parts of the talk have been elided from this article. If you prefer, you can watch the recording of the talk. Readability […]

goprogrammingsmall ideas

5 Jul 2019

Dave Cheney 1 min read

On the 17th of July I’ll be giving a version of my High Performance Go workshop updated for the upcoming changes in Go 1.13. The event is free, as in puppy, however numbers are limited due to the venue size. The event will be held in the Sydney CBD, the address will be provided to […]

gohigh performance gotrainingworkshop

10 Jun 2019

Dave Cheney 9 min read

This essay is a derived from my dotGo 2019 presentation about my favourite feature in Go. Many years ago Rob Pike remarked, “Numbers are just numbers, you’ll never see 0x80ULL in a .go source file”. —Rob Pike, The Go Programming Language Beyond this pithy observation lies the fascinating world of Go’s constants. Something that is […]

goprogrammingsmall ideasconstantserror handling

7 May 2019

Dave Cheney 11 min read

I’m a big fan of testing, specifically unit testing and TDD (done correctly, of course). A practice that has grown around Go projects is the idea of a table driven test. This post explores the how and why of writing a table driven test. Let’s say we have a function that splits strings: // Split […]

goprogrammingtestingunit test

3 Apr 2019

Dave Cheney 1 min read

A short talk about unit testing that I gave at the Go London User Group last month. Links: Slides Playlist of videos from the March meetup

go

29 Jan 2019

Dave Cheney 2 min read

The name of a variable should describe its contents, not the type of the contents. Consider this example: var usersMap map[string]*User What are some good properties of this declaration? We can see that it’s a map, and it has something to do with the *User type, so that’s probably good. But usersMapis a map and Go, being a statically typed…

gonames

27 Jan 2019

Dave Cheney 5 min read

Go 2 aims to improve the overhead of error handling, but do you know what is better than an improved syntax for handling errors? Not needing to handle errors at all. Now, I’m not saying “delete your error handling code”, instead I’m suggesting changing your code so you don’t have as many errors to handle. […]

goerror handlingerrors

8 Jan 2019

Dave Cheney 2 min read

Writing a good Go package starts with its name. Think of your package’s name as an elevator pitch, you have to describe what it does using just one word. A common cause of poor package names are utility packages. These are packages where helpers and utility code congeal. These packages contain an assortment of unrelated functions, […]

go

27 Dec 2018

Dave Cheney 3 min read

Garbage collection is a field with its own terminology. Concepts like like mutators, card marking, and write barriers create a hurdle to understanding how garbage collectors work. Here’s an analogy to explain the operations of a concurrent garbage collector using everyday items found in the workplace. Before we discuss the operation of concurrent garbage collection, let’s introduce […]

gosmall ideasgarbage collectiongc

15 Oct 2018

3 Sept 2018

Dave Cheney 3 min read

This is a short response to the recently announced Go 2 generics draft proposals Update: This proposal is incomplete. It cannot replace two common use cases. The first is ensuring that several formal parameters are of the same type: contract comparable(t T) { t > t}func max(type T comparable)(a, b T) T Here a, and […]

goprogramminggenerics

16 Jul 2018

Dave Cheney 3 min read

In my previous post I converted httpstat to use Go 1.11’s upcoming module support. In this post I continue to explore integrating Go modules into a continuous integration workflow via Travis CI. Life in mixed mode The first scenario is probably the most likely for existing Go projects, a library or application targeting Go 1.10 […]

goprogrammingdependancy managementmodulestravis ci

14 Jul 2018

Dave Cheney 4 min read

Update: Since this post was written, Go 1.11beta2 has been released. I’ve updated the setup section to reflect this. Russ Cox kindly wrote to me to explain the reasoning behind storing the Go module cache in $GOPATH. I’ve included his response inline. This weekend I wanted to play with Ubuntu 18.04 on a spare machine. […]

goprogrammingdependancy managementmodulesvgo

12 Jul 2018

Dave Cheney 5 min read

This blog post was inspired by a conversation with a co-worker about using a slice as a stack. The conversation turned into a wider discussion on the way slices work in Go, so I thought it would be useful to write it up. Arrays Every discussion of Go’s slice type starts by talking about something […]

goprogrammingslices

29 May 2018

8 Jan 2018

Dave Cheney 16 min read

This is an article about compiler directives; or as they are commonly known, pragmas. It’s derived from a talk of a similar name that I gave last year at GopherChina in Shanghai. But first, a history lesson Before we talk about Go, let’s talk a little about pragmas, and their history. Many languages have the notion […]

goprogrammingpragma

6 Jan 2018

23 Aug 2017

Dave Cheney 3 min read

In September i’ll be speaking about Go at events in Russia and Taiwan. DevFest Siberia 2017, September 23rd and 24th I’ve been accepted to give two presentations at the GDG Novosibirsk DevFest Siberia 2017 event in Russia. High performance servers without the event loop Conventional wisdom suggests that the key to high performance servers are native threads, […]

goprogramming

20 Aug 2017

Dave Cheney 3 min read

This is an experience report about the use of, and difficulties with, the context.Context facility in Go. Many authors, including myself, have written about the use of, misuse of, and how they would change, context.Context in a future iteration of Go. While opinions differs on many aspects of context.Context, one thing is clear–there is almost unanimous agreement that […]

goprogrammingcontextgo2.0

9 Aug 2017

Dave Cheney 3 min read

This is an experience report about a gotcha in Go that catches every Go programmer at least once. The following program is extracted from a larger version that caused my co-workers to lose several hours today. package mainimport "fmt"type T struct{}func (t T) F() {}type P interface { F()}func newT() *T { return new(T) }type […]

goprogrammingexperience reportgo2.0

22 Jul 2017

Dave Cheney 3 min read

A long time ago, someone–I normally attribute this to David Symonds, but I can’t be sure he was the first to say it–said that the reason for adding generics to Go would be the reason for calling it Go 2.0. That is to say, adding generics to the language would be half baked if they […]

goprogramminggenericsgo2.0

20 Jun 2017

Dave Cheney 2 min read

This is a short post describing the procedure for discovering which version of Go was used to compile a Go binary. This procedure relies on the fact that each Go program includes a copy of the version string reported by runtime.Version() . Linker magic ensures that this value will be present in the final binary irrespective […]

goprogramminggdbldbllvm

18 Jun 2017

Dave Cheney 7 min read

In my previous post I discussed my concerns the additional complexity adding generics or immutability would bring to a future Go 2.0. As it was an opinion piece, I tried to keep it around 500 words. This post is an exploration of the most important (and possibly overlooked) point of that post. Indeed, the addition of […]

goprogramminggenericsimmutability

14 Jun 2017

Dave Cheney 2 min read

Fifteen years ago Python’s GIL wasn’t a big issue. Concurrency was something dismissed as probably unnecessary. What people really was needed was a faster interpreter, after all, who had more than one CPU? But, slowly, as the requirement for concurrency increased, the problems with the GIL increased. By the time this decade rolled around, Node.js and […]

goprogrammingsmall ideasgenericsgo2.0

11 Jun 2017

Dave Cheney 7 min read

This is a thought experiment, what would Go look like if we could no longer declare variables at the package level? What would be the impact of removing package scoped variable declarations, and what could we learn about the design of Go programs? I’m only talking about expunging var, the other five top level declarations would […]

goprogrammingsmall ideas

30 Apr 2017

Dave Cheney 3 min read

In my previous post I showed that Go maps are not reference variables, and are not passed by reference. This leaves the question, if maps are not references variables, what are they? For the impatient, the answer is: A map value is a pointer to a runtime.hmap structure. If you’re not satisfied with this explanation, read on. What […]

goprogrammingmaps

29 Apr 2017

Dave Cheney 2 min read

My post on pointers provoked a lot of debate about maps and pass by reference semantics. This post is a response to those debates. To be clear, Go does not have reference variables, so Go does not have pass-by-reference function call semantics. What is a reference variable? In languages like C++ you can declare an alias, […]

goprogrammingpass by referencepass by valuereferences

26 Apr 2017

20 Mar 2017

Dave Cheney 3 min read

A few weeks ago I was asked by a friend, “why should I care about Go”? They knew that I was passionate about Go, but wanted to know why I thought other people should care. This article contains three salient reasons why I think Go is an important programming language. Safety As individuals, you and I may be […]

goprogrammingconcurrencyproductivitysecurity

9 Feb 2017

Dave Cheney 2 min read

In April and May I’ll be speaking at GopherChina and GopherCon Singapore, respectively. This post is a teaser for the talks that were selected by the organisers. If you’re in the area, I hope you’ll come and hear me speak. GopherChina GopherChina is the third event in this conference series and this year will return to Shanghai. I was […]

goprogramminggopherchinagophercon sg

25 Jan 2017

Dave Cheney 2 min read

In my previous post I suggested that the best way to break the compile time coupling between the logger and the loggee was passing in a logger interface when constructing each major type in your program. The suggestion has been floated several times that logging is context specific, so maybe a logger can be passed around via […]

goprogrammingdesignlogging

23 Jan 2017

Dave Cheney 2 min read

This post is a spin-off from various conversations around improving (I’m trying not to say standardising, otherwise I’ll have to link to XKCD) the way logging is performed in Go projects. Consider this familiar pattern for establishing a package level log variable. package foo import “mylogger” var log = mylogger.GetLogger(“github.com/project/foo”) What’s wrong with this pattern? The first problem […]

goprogrammingdesignlogging

22 Dec 2016

Dave Cheney 1 min read

In Go, goroutines are cheap to create and efficient to schedule. The Go runtime has been written for programs with tens of thousands of goroutines as the norm, hundreds of thousands are not unexpected. But goroutines do have a finite cost in terms of memory footprint; you cannot create an infinite number of them. Every time you […]

goprogramminggoroutinesleak

20 Dec 2016

Dave Cheney 4 min read

This is a short blog post about my thoughts on using Go in anger through several workplaces, as a developer and an advocate. What is $GOPATH? Back when Go was first announced we used Makefiles to compile Go code. These Makefiles referenced some shared logic stored in the Go distribution. This is where $GOROOT comes from. […]

goprogrammingsmall ideasdependency managementgopath

15 Dec 2016

Dave Cheney 1 min read

This post is about declaration scopes and shadowing in Go. package main import "fmt" func f(x int) { for x := 0; x < 10; x++ { fmt.Println(x) } } var x int func main() { var x = 200 f(x) } This program declares x four times. All four are different variables because they exist […]

goprogrammingscope

19 Nov 2016

Dave Cheney 7 min read

This is a progress report on the Go toolchain improvements during the 1.8 development cycle. Now we’re well into November, the 1.8 development window is closing fast on the few remaining in fly change lists, with the remainder being told to wait until the 1.9 development season opens when Go 1.8 ships in February 2017. […]

goprogrammingarmarm64performance

12 Nov 2016

Dave Cheney 14 min read

This is the text of my dotGo 2016 presentation. A recording and slide deck are also available. Hello, welcome to dotGo. Two years ago I stood on a stage, not unlike this one, and told you my opinion for how configuration options should be handled in Go. The cornerstone of my presentation was Rob Pike’s blog post, […]

gosmall ideas

24 Oct 2016

Dave Cheney 4 min read

Just so we’re clear, this post is a thought experiment, not any form of commitment to deliver Go 2.0 in any time frame. While I personally believe there will be a Go 2.0 in the future, I’m in no position to influence its creation; hence, this post is mere speculation. Why introduce a new major version […]

goprogrammingsmall ideasgo2.0

17 Sept 2016

Dave Cheney 5 min read

Sunday September the 18th marks a month since the Go 1.8 cycle opened officially. I’m passionate about the performance of Go programs, and of the compiler itself. This post is a brief look at the state of play, roughly 1/2 way into the development cycle for Go 1.81. Note: these results are of course preliminary […]

goprogrammingperformance

20 Aug 2016

Dave Cheney 16 min read

This post is based on the text of my GolangUK keynote delivered on the 18th of August 2016. A recording of the talk is available on YouTube. This post has been translated into Simplified Chinese by Haohao Tian. Thanks Haohao! This post has been translated to Russian by Artem Zinoviev. Thanks Artem! How many Go programmers […]

goprogramminggolanguksolid

26 Jun 2016

24 Jun 2016

Dave Cheney 3 min read

What do we want? Version management for Go packages! When do we want it? Yesterday! What does everyone want? We want our Go build tool of choice to fetch the latest stable version when you start using the package in your project. We want them to grab security updates and bug fixes automatically, but not upgrade […]

goprogrammingdependency management

12 Jun 2016

Dave Cheney 5 min read

A few months ago I gave a presentation on my philosophy for error handling. In the talk I introduced a small errors package designed to support the ideas presented in the talk. This post is an update to my previous blog post which reflects the changes in the errors package as I’ve put it into service […]

goprogrammingerror handlingerrorsstacktrace

10 May 2016

Dave Cheney 1 min read

This is a quick post to describe how you can use test fixtures, data files on disk, with the Go testing package. Using fixtures with the Go testing package is quite straight forward because of two convenience features built into the go tool. First, when you run go test, for each package in scope, the […]

goprogrammingfixturestesting

26 Apr 2016

7 Apr 2016

Dave Cheney 2 min read

This is a thought experiment about sentinel error values in Go. Sentinel errors are bad, they introduce strong source and run time coupling, but are sometimes necessary. io.EOF is one of these sentinel values. Ideally a sentinel value should behave as a constant, that is it should be immutable and fungible. The first problem is […]

goprogrammingerror handlingerrors

2 Apr 2016

Dave Cheney 3 min read

This is a progress report on the Go toolchain improvements during the 1.7 development cycle. All measurements were taken using a Thinkpad x220, Core i5-2520M, running Ubuntu 14.04 linux. Faster compilation Since Go 1.5, when the compiler itself was translated from C to Go, compile times are slower than they used to be. Everyone knows it, nobody […]

goprogrammingcompilerperformance

25 Mar 2016

Dave Cheney 3 min read

In December 2014 the Go project moved from Google Code to GitHub. Along with the move to GitHub, the Go project moved from Mercurial to Git, which necessitated a move away from Rietveld to Gerrit for code review. A healthy open source project lives and dies by its contributors. People come and people go as time, circumstance, their […]

gocontributingopen source

18 Mar 2016

29 Feb 2016

6 Feb 2016

Dave Cheney 2 min read

Sandi Metz’s post on abstraction struck a chord with me recently. I was working with a piece of code which looked like this (in pseudo code): func Start() { const filename = "..." createOuputFile(filename) go run(filename) } It turned out that createOutputFile was written in an obscure way which first caused me to look at […]

goprogrammingabstractiondesign

18 Jan 2016

Dave Cheney 7 min read

To steal a quote from JWZ, Some people, when confronted with a problem, think “I know, I’ll use cgo.” Now they have two problems. Recently the use of cgo came up on the Gophers’ slack channel and I voiced my concerns that using cgo, especially on a project that is intended to showcase Go inside […]

goprogrammingcgo

7 Dec 2015

Dave Cheney 2 min read

Panic messages from unexpected program crashes are often reported on the Go issue tracker. An overwhelming number of these panics are caused by data races, and an overwhelming number of those reports centre around Go’s built in map type. unexpected fault address 0x0 fatal error: fault [signal 0x7 code=0x80 addr=0x0 pc=0x40873b] goroutine 97699 [running]: runtime.throw(0x17f5cc0, 0x5) […]

goprogrammingdata racerace detector

29 Nov 2015

Dave Cheney 7 min read

Introduction The Go runtime, in addition to providing the usual services of garbage collection, goroutine scheduling, timers, network polling and so forth, contains facilities to enable extra debugging output and even alter the behaviour of the runtime itself. These facilities are controlled by environment variables passed to the Go program. This post describes the function of […]

goprogramminggodebuggogcgomaxprocs

18 Nov 2015

Dave Cheney 1 min read

The following program contains a data race package main import ( "fmt" "time" ) type RPC struct { result int done chan struct{} } func (rpc *RPC) compute() { time.Sleep(time.Second) // strenuous computation intensifies rpc.result = 42 close(rpc.done) } func (RPC) version() int { return 1 // never going to need to change this } […]

goprogrammingpop quiz

14 Nov 2015

Dave Cheney 12 min read

In October this year I had the privilege of speaking at the GothamGo conference in New York City. As I talk quite softly, and there were a few problems with the recording, I decided to write up my slide notes and present them here. If you want to see the video of this presentation, you […]

gohistorygothamgo

5 Nov 2015

Dave Cheney 5 min read

This is a post inspired by a thread that Nate Finch started on the Go Forum. This post focuses on Go, but if you can see your way past that, I think the ideas presented here are widely applicable. Why no love ? Go’s log package doesn’t have leveled logs, you have to manually add prefixes like […]

goprogrammingsmall ideasdesignlogging

15 Oct 2015

Dave Cheney 3 min read

This post is a continuation of my previous post on bootstrapping Go 1.5 on the Raspberry Pi. Now that Go 1.5 is written entirely in Go there is a bootstrapping problem — you need Go to build Go. For most people running Windows, Mac or Linux, this isn’t a big issue as the Go project […]

goprogrammingarm64bootstrappingppc64

9 Oct 2015

Dave Cheney 8 min read

We all know that the empty struct consumes no storage, right ? Here is a curious case where this turns out to not be true. This is a story about trying to speed up the Go compiler. Since Go 1.5 we’ve had the great concurrent GC, which reduces the cost of garbage collection, but no […]

goprogrammingalignmentpadding

4 Sept 2015

Dave Cheney 2 min read

This is a short post to describe my recommended method for building Go on the Raspberry Pi. This method has been tested on the Raspberry Pi 2 Model B (900Mhz, 1Gb ram) and the older Raspberry Pi 1 Model B+ (700Mhz, 512Mb ram). This method will build Go 1.5 into you home directory, $HOME/go. As […]

goprogrammingraspberrypi

22 Aug 2015

Dave Cheney 3 min read

Now that Go 1.5 is out, lots of gophers are excited to try the much improved cross compilation support. For some background on the changes to the cross compilation story you can read my previous post, or Rakyll’s excellent follow up piece. I’ll assume that you are using the binary version of Go 1.5, as distributed from […]

goprogrammingcross compilation

19 Aug 2015

Dave Cheney 1 min read

For the longest time I had this alias in my .bashrc alias gb='go install -v' as an homage to John Asmuth’s gb tool which I was very fond of way back before we had the go tool. Once gb was written, I had to remove that alias and live in a world where I used […]

goprogramminggb

8 Aug 2015

Dave Cheney 11 min read

This article is also available in Japanese, イベントループなしでのハイパフォーマンス – C10K問題へのGoの回答 This article is based on a presentation I gave earlier this year at OSCON. It has been edited for brevity and to address some of the points of feedback I received after the talk. A common refrain when talking about Go is it’s a language […]

goprogramming

2 Jul 2015

Dave Cheney 3 min read

This is a short blog post explaining why I believe that Go and Rust are not competitors. Why people think Rust and Go are competitors To explain why I think Rust and Go are not competitors, I want to to lay out the reasons why I think the question is being asked in the first place. Rust […]

goprogrammingrust

8 Jun 2015

Dave Cheney 11 min read

A few months ago I introduced gb as a proof of concept to the audience at GDG Berlin. Since then, together with a small band of contributors and an enthusiastic cabal of early adopters, gb has moved from proof of concept, written mostly on trains during a trip through Europe, to something approaching a usable […]

goprogramminggbreproducible builds

5 Jun 2015

Dave Cheney 3 min read

bytes.Buffer is a tremendously useful type, but it’s a bit large1. % sizeof -p bytes Buffer Buffer 112 … and that is just the overhead, we haven’t put any data into the buffer yet. This Friday’s2 challenge is to write a replacement for bytes.Buffer that implements io.ReadWriter and allows the caller to discover the length and capacity of the […]

goprogramminguseless trivia

30 May 2015

Dave Cheney 2 min read

I’m going to be speaking at OSCON this year about Go performance. The title of the talk is High performance servers without the event loop and will focus on the features of the language and its runtime that transparently let Go programmers write high performance network servers without resorting to event loops and callback spaghetti. As the […]

goprogrammingoscon

22 May 2015

Dave Cheney 2 min read

This is a quick Friday blog post to talk about a recent experience I had working on a piece Juju code that needed to capture the data being sent over a net.Conn. Most Gophers know that the net package provides a net.Pipe function which returns a pair of net.Conns representing an in memory network connection. net.Pipe […]

goprogrammingmockingreaderstesting

11 May 2015

28 Mar 2015

Dave Cheney 2 min read

Update: Two months after making this post, it’s already out of date, 2015 will feature ten Go conferences. Last month, during my concluding remarks at Gophercon India, I threw out a statistic: In 2014 there were five international Go conferences. In 2015 there will be seven. Barely a month on from this statement I must […]

go

26 Mar 2015

Dave Cheney 2 min read

When I was younger, I wanted to learn to play the guitar (this was the 90’s after all). So I cracked open my piggy bank, bought a decent beginners guitar and took some lessons. I regularly bought the guitar magazines that appeared in the local newsagent and practised along to my favourite songs. I noodled […]

gosmall ideassimplicity

7 Mar 2015

Dave Cheney 19 min read

This is the text of my closing keynote from Gophercon India. It has been slightly altered for readability from my original speaking notes. I am indebted to the organisers of Gophercon India for inviting me to speak, and to Canonical for giving me the time off to attend the conference. If you want to see me […]

goprogrammingsmall ideasgophercon india

2 Mar 2015

26 Feb 2015

Dave Cheney 1 min read

I have updated my unofficial ARM tarball distributions page with prebuilt Go 1.4.2 tarballs. You can find them by following the link in the main header of this page. As these were the first tarballs produced since the move to git, please let me know if you encounter any issues.

goprogramming

25 Feb 2015

Dave Cheney 1 min read

Over the last year I have had the privilege of travelling to meet Go communities in Japan, Korea and India. In every instance I have met experienced, passionate, pragmatic programmers ready to accept Go for what it can do for them. At the same time the message from each of these communities was the same; […]

goprogrammingsmall ideas

13 Feb 2015

Dave Cheney 1 min read

This is a short post to recognise the incredible contribution Alex Brainman has made to the Go project. Alex was responsible for the port of Go to Windows way back before Go 1 was even released. Since that time he has virtually single-handedly supported Go and Go users on Windows. It’s no wonder that he is […]

go

25 Jan 2015

Dave Cheney 5 min read

In my previous post, I doubled down on my claim that Go’s error handling strategy is, on balance, the best. In this post, I wanted to take this a bit further, and prove that multiple returns and error values are the best, When I say best, I obviously mean, of the set of choices available […]

goprogrammingerrorsexceptionsmonads

23 Dec 2014

Dave Cheney 2 min read

The common contract for functions which return a value of the interface type error, is the caller should not presume anything about the state of the other values returned from that call without first checking the error. In the majority of cases, error values returned from functions should be opaque to the caller. That is […]

goprogrammingerrorsinterfaces

13 Dec 2014

11 Dec 2014

Dave Cheney 1 min read

In this program, the size of variables of type x and y in memory varies by platform. package main func main() { const n = 4 type x [n]uint type y [n]int } By changing only one line can you ensure that variables of type x, and y always consume 16 bytes on all platforms […]

goprogramminguseless trivia

5 Dec 2014

Dave Cheney 1 min read

It’s a little unfair to announce winners in some kind of order as I did post the quiz at an unfriendly hour of the day for most of the planet. With that said, Tim and William came up with a great map based solution at roughly the same time. You’ll have to split the winnings […]

gouseless trivia

Dave Cheney 1 min read

This program is incorrect package main import "fmt" func f(a, b int) { var min = 0 fmt.Printf("The min of %d and %d is %d\n", a, b, min) } func main() { f(9000, 314) } By adding only one line can you make it print the correct answer ? The code must continue to be […]

gouseless trivia

30 Nov 2014

Dave Cheney 6 min read

The question of how to set up a new Go project appears commonly on the golang-nuts mailing list. Normally the advice for how to structure Go code centres around “read the standard library”, but the standard library is not a great deal of use to newcomers in the respect as: You don’t go get packages […]

goprogrammingrepository layout

21 Nov 2014

Dave Cheney 5 min read

Juju is a pretty large project. Some of our core packages have large complex dependency graphs and this is undesirable because the packages which import those core packages inherit these dependencies raising the spectre of an inadvertent import loop. Reducing the coupling between our core packages has been a side project for some time for me. […]

goprogrammingdependency managementvisualisation

3 Nov 2014

Dave Cheney 2 min read

Revisiting my post about error handling and exceptions, written well before Go hit 1.0, I’m pleased that it stands the test of time. Java has comprehensively demonstrated that checked exceptions (actually having both checked and unchecked exceptions) has been a disaster for the evolution of the language. Checked exceptions have placed a suffocating yoke of backward compatibility on […]

goprogrammingerror handlingexceptions

26 Oct 2014

Dave Cheney 1 min read

A topic that has weighed on my mind recently is the dichotomy of frameworks vs. libraries in the Go community. Is the prevailing stance against complex frameworks a rejection of this purported labour saving automation, or an enlightened position that has weighed the pro’s and cons and found the costs of a framework based approached outweighs the benefits ? […]

goprogrammingframeworks

22 Oct 2014

Dave Cheney 2 min read

As part of preparing for my dotGo talk I updated a few of my packages to use the functional options pattern. I only had time to show one of those packages on stage, pkg/term. This is a post about one that was left on the cutting room floor. Last year I wrote a simple package […]

goprogrammingfunctional options

16 Oct 2014

Dave Cheney 9 min read

What follows is the text of my presentation, Functional options for friendly APIs that I gave at dotGo this year. It has been edited slightly for readability. I want to thank Kelsey Hightower, Bill Kennedy, Jeremy Saenz, and Brian Ketelsen, for their assistance in preparing this talk. I want to begin my talk with a […]

goprogrammingdotgofunctional options

3 Oct 2014

Dave Cheney 1 min read

When initialising a variable with a composite literal, Go requires that each line of the composite literal end with a comma, even the last line of your declaration. This is the result of the semicolon rule. Although possibly an unintended consequence, this means that when proposing a one line change, it really is a one line change. The […]

goprogramming

28 Sept 2014

Dave Cheney 1 min read

Build tags are part of the conditional compilation system provided by the go tool. This is a quick post to discuss using build tags to selectively enable debug printing in a package. This afternoon I merged a contribution to pkg/sftp which improved the packet encoding performance but introduced a bug where some packet types were incorrectly encoded. % […]

goprogrammingdebugging

14 Sept 2014

Dave Cheney 3 min read

During my day job I’ve been working on re-factoring some the internals of Juju to reverse the trend of a growing number of dependencies in our core packages. In this post I’ll show how I used go list to help me in this task. The basics Let’s start with the basics of go list. The default invocation of go […]

gogo list

13 Sept 2014

Dave Cheney 1 min read

Here is a short recipe I use for installing multiple versions of Go from source. In this example I’m going to install the release (currently Go 1.3.1) and trunk versions of Go. Step 1. Checkout Checkout two copies of the Go source code into independent paths. % hg clone https://code.google.com/p/go -r release $HOME/go.release % hg […]

go

1 Sept 2014

Dave Cheney 1 min read

The start of September brings a close to the Go 1.4 merge window. From now until the release in December, only bug fixes and tweaks will be accepted. A major piece of work that landed in Go 1.4 cycle was the rewrite of parts of the Go runtime from C to Go. What may not […]

go

17 Aug 2014

Dave Cheney 3 min read

This is a post about Go’s built in make and new functions. As Rob Pike noted at Gophercon this year, Go has many ways of initialising variables. Among them is the ability to take the address of a struct literal which leads to serveral ways to do the same thing. s := &SomeStruct{} v := SomeStruct{} […]

goprogrammingmakenew

3 Aug 2014

11 Jul 2014

Dave Cheney 3 min read

Update this post is also available in Japanese. This is a post about an experimental tool that I have been working on. gcvis is a simple way of visualising the operation of the garbage collector within a Go process. Here is a screenshot of it in operation. The rest of this article explores how gcvis […]

goprogramminggcgcvisperformance

8 Jul 2014

29 Jun 2014

Luciano Mammino 9 min read

By writing a Dockerfile we can containerize a simple Go echo server app. The Dockerfile installs Go, copies the server code, exposes the port, and defines the command to run the app. Building the Dockerfile produces an image that can be run as a container. The containerized Go app can then be easily distributed and run anywhere Docker is installed.

servergodocker

27 Jun 2014

Dave Cheney 3 min read

This is a post about data races. The code for this post lives on Github, github.com/davecheney/benandjerry. The example program simulates two Ice cream makers, Ben and Jerry, who greet their customers randomly. package main import "fmt" type IceCreamMaker interface { // Hello greets a customer Hello() } type Ben struct { name string } func (b *Ben) […]

goprogrammingdata racerace detector

7 Jun 2014

Dave Cheney 13 min read

Anthony Starks has remixed my original Google Present based slides using his fantastic Deck presentation tool. You can check out his remix over on his blog, mindchunk.blogspot.com.au/2014/06/remixing-with-deck. I was recently invited to give a talk at Gocon, a fantastic Go conference held semi-annually in Tokyo, Japan. Gocon 2014 was an entirely community-run one day event combining […]

goprogramminggoconperformance

4 Jun 2014

Dave Cheney 1 min read

For packages go build builds your package then discards the results. go install builds then installs the package in your $GOPATH/pkg directory. For commands go build builds the command and leaves the result the current working directory. go install builds the command in a temporary directory then moves it to $GOPATH/bin. If you liked this […]

goprogramming

24 May 2014

Dave Cheney 1 min read

Go has several ways to declare a variable. Possibly there are more ways than are strictly required but with the Go 1 contract in effect it’s not going to change. This short post gives examples of how I decide which variable declaration syntax to use. These are just suggestions, they make sense to me, but […]

goprogramminguseless triviatop tip

22 May 2014

Dave Cheney 5 min read

Go obtains much of its compilation speed from the Plan 9 compiler, of which it is a direct descendant. The Plan 9 toolchain deferred much of the work traditionally performed by a compiler to the linking stage and its performance was summarised in section 8 of this paper The new compilers compile quickly, load slowly, […]

goprogramminglinker speed

19 May 2014

Dave Cheney 1 min read

This is a quick post to discuss an interesting bug that was recently unearthed by go vet. The following code is a simplified reduction of a larger piece of code. In the original code the if statement was much larger, encompassing several complicated conditions, making the bug hard to spot visually. package main import "fmt" […]

goprogramming

9 May 2014

7 May 2014

Dave Cheney 1 min read

I have several projects on the hop at the moment which require control over a serial port, actually a serial port emulated over USB. So for the last few days I’ve let myself be distracted by writing yet another serial package for Go. github.com/pkg/term term is built on a lower level package, called termios which provides […]

goprogrammingarduinofirmataftdi

4 May 2014

Dave Cheney 1 min read

Now that go1.3beta1 has been released I’ve updated the autobench-next branch to track Go 1.2 vs tip (go1.3beta1). Using autobench is very simple, clone the repository and run make to produce a benchmark on your machine. % cd devel % git clone -b autobench-next https://github.com/davecheney/autobench.git % cd autobench % make You can stay up to date with […]

goprogrammingautobenchbenchmarkperformance

20 Apr 2014

Dave Cheney 2 min read

Introduction This post presents one technique for installing and using multiple versions of Go on a machine. This is a technique I use often as we have standardised on Go 1.2.1 for developing Juju, but develop on the tip of Go itself. You may find this technique useful for do comparisons between various Go versions for […]

goprogramming

29 Mar 2014

Dave Cheney 1 min read

This post is a follow up to Friday’s post on comments in Go. Keith Rarick and Nate Finch pointed out that I had neglected to include two important practical use cases. Build tags I’ve previously written about how to use // +build tags to perform conditional compilation. In light of the previous post it’s probably […]

goprogrammingbuild constraintscomments

28 Mar 2014

Dave Cheney 2 min read

This is a quick post to discuss the rules of comments in Go. To quickly recap, Go comments come in two forms // everything from the double slash to the end of line is a comment /* everything from the opening slash star, to the closing one is a comment */ As the first form […]

goprogrammingcgocomments

24 Mar 2014

Dave Cheney 4 min read

Introduction This post explores the properties of my favourite Go data type, the empty struct. The empty struct is a struct type that has no fields. Here are a few examples in named and anonymous forms type Q struct{} var q struct{} So, if an empty struct contains no fields, contains no data, what use […]

goprogrammingempty structstruct

22 Mar 2014

Dave Cheney 1 min read

It has been roughly six months since I wrote about the problems I saw with package management in Go. In the intervening months there has been lots of discussion; the issue continues to be one of the two most continually and hotly debated on the golang-nuts and go-pm mailing lists. No prizes for guessing what […]

goprogramminggo-pmpackage managementvendoring

19 Mar 2014

Dave Cheney 3 min read

Most new Go programmers quickly grasp the idea of a channel as a queue of values and are comfortable with the notion that channel operations may block when full or empty. This post explores four of the less common properties of channels: A send to a nil channel blocks forever A receive from a nil […]

goprogrammingchannels

16 Mar 2014

Dave Cheney 2 min read

This blog post was originally a comment on a Google Plus page, but apparently one cannot create a href to a comment so it was suggested I rewrite it as a blog post. Go pointers, like C pointers, are values that, uh, point to other values. This is a tremendously important concept and shouldn’t be […]

goprogrammingpointers

8 Mar 2014

Dave Cheney 1 min read

In addition to developing avr11, a software simulation of a PDP-11/40, I also wrote a Go version of the simulator. I recently had an opportunity to talk about the Go based version at the Sydney and Melbourne Go meetups. The link to the slides are Sydney Melbourne The code itself is not really ready for […]

goprogramming

21 Jan 2014

Dave Cheney 1 min read

With one exception, the go command takes arguments in the form of packages. You can pass the package name(s) explicitly, eg. go test github.com/hoisie/mustache or implicitly cd $GOPATH/src/github.com/hoisie/mustache go test . By default, if no arguments are provided go test treats the current directory as a package, so in the second example, go test . […]

goprogramminggo buildgo installgo test

28 Dec 2013

Dave Cheney 1 min read

I have updated my unofficial ARM tarball distributions page with prebuilt Go 1.2 tarballs. You can find them by following the link in the main header of this page. If you are interested in the potential performance improvements in Go 1.2, I wrote a post about it on the Gopher Academy blog as part of this year’s Go Advent […]

goprogrammingarm

2 Dec 2013

Dave Cheney 1 min read

If you’re interested in the performance improvements delivered in Go 1.2, I’ve written about it as part of this years Go Advent project. You can find the post on the Gopher Academy blog, blog.gopheracademy.com/day-02-go-1.2-performance-improvements.

goprogramming

20 Nov 2013

Dave Cheney 1 min read

Over the last few weeks I had the opportunity of working with the Joyent folks on the port of Go to Solaris1. As part of this work I noted that the Joyeurs were using their rather spiffy Manta service for sharing code snippets and build logs. This made the rest of us using Pastebin services […]

goprogrammingjoyentmantasunos

19 Nov 2013

Dave Cheney 1 min read

I’ve been doing a lot of work with gccgo recently and with the upcoming release of Go 1.2 I’ve also been collecting benchmark results for that release. Presented below, using a very unscientific method, are the results of comparing the go1 benchmark results for the two compilers. Buried among that see of red are a few […]

goprogramminggccgo

15 Nov 2013

Dave Cheney 1 min read

At Canonical we’re increasingly invested in gccgo. While testing various packages built with gccgo we ran across test failures which we traced to an innocent looking piece of code. package main import "fmt" type T struct { i int } func (t *T) readInt32() int32 { t.i += 4 return 42 // not important } […]

goprogramminguseless trivia

14 Nov 2013

Dave Cheney 1 min read

In a previous post I blogged about the cover tool coming in Go 1.2 and a bash helper function I use to make the tool a little easier to use. Since then I’ve extended these helpers so I wanted to blog about the improvements. Passing arguments to the testing tool cover () { t=$(tempfile) go […]

goprogrammingcovercoverage

13 Nov 2013

Dave Cheney 1 min read

This is a brief post highlighting a curious aspect of the declaration syntax in Go. Most Go programmers know that the following of import declarations are equivalent import "fmt" import "math/big" // same as import ( "fmt" "math/big" ) The same applies to const declarations const FORTYTWO = 42 const TRUE = 1 // same […]

goprogramminguseless trivia

7 Nov 2013

Dave Cheney 1 min read

A few days ago I was working on an example program for the sftp package and found I needed to implement subcommand handling. https://twitter.com/davecheney/status/397686194462396416 The response was fantastic, no less than 12 different packages. I haven’t had the chance to review any of the packages in detail, but I wanted to list them here as […]

goprogramming

4 Nov 2013

Dave Cheney 1 min read

With the release of go1.2rc3 last week I have now merged the autobench-next branch into master in the autobench repository. Go 1.2 is not expected to bring performance improvements of the same magnitude of Go 1.1, but moderate improvements are expected due to improvements in code generation, the runtime, the garbage collector, and the standard […]

goprogrammingautobenchbenchmark

15 Oct 2013

Dave Cheney 5 min read

This post explains how the Go build process works using examples from Go’s standard library. The gc toolchain This article focuses on the gc toolchain. The gc toolchain takes its name for the Go compiler frontend, cmd/gc, and is mainly used to distinguish it from the gccgo toolchain. When people talk about the Go compilers, they […]

goprogrammingcompilertoolchain

12 Oct 2013

Dave Cheney 5 min read

When developing Go packages that rely on specific features of the underlying platform or processor it is often necessary to provide a specialised implementation. Go does not have a preprocessor, a macro system, or a #define declaration to control the inclusion of platform specific code. Instead a system of tags and naming convention defined in the go/build […]

gophotographybuild constraintsbuild tagsgo build

10 Oct 2013

7 Oct 2013

Dave Cheney 2 min read

Did you know that Go 1.2 will ship with a built in test coverage tool ? The tool is integrated into go test and works similarly to the profiling tool, producing an output file which is interpreted by a second command. If you have Go 1.2rc2 or tip installed, you can use this short shell […]

goprogrammingcoveragego test

21 Sept 2013

Dave Cheney 1 min read

Clearly I’m biased when it comes to the popularity of Go, so here is another data point. [line_chart title=”#golang tweets per month” v_title=”tweets” width=”600px” height=”400px” scale_button=”true”] [‘Month’, ‘Tweets’], [ ‘2009-11’ , 60 ], [ ‘2009-12’ , 31 ], [ ‘2010-01’ , 14 ], [ ‘2010-02’ , 36 ], [ ‘2010-03’ , 56 ], [ ‘2010-04’ […]

go

Dave Cheney 1 min read

Go 1.2 is on target for a December release and the Go team have just cut their first release candidate. You can find the draft (no twitterverse, Go 1.2 isn’t released yet) release notes for Go 1.2 online here. I have updated my unofficial ARM tarball distributions page with prebuilt go1.2rc1 tarballs. You can find them by following the link…

goprogramminggo1.2release candidate

18 Sept 2013

7 Sept 2013

Dave Cheney 4 min read

It looks like Go 1.4 will remove support for Go packages containing C code (as described below, don’t confuse this with CGO), so enjoy it while it lasts. This is a short post designed to illustrate how Go package authors can write package level functions in C and call them from Go code without using […]

goprogrammingc++cgo

26 Aug 2013

Dave Cheney 1 min read

Earlier this year I wrote a small harness to compare the relative performance of Go 1.0 and the then just released Go 1.1. You can read the posts about the Go 1.1 performance improvements: amd64, 386 and arm. As the Go 1.2 cycle is entering feature freeze next week, I’ve taken the opportunity to create a […]

goprogrammingbenchmarkperformance

6 Aug 2013

Dave Cheney 1 min read

Thanks to Little Bird Electronics I just picked up the recently released Cubieboard 2. For less than 90 bucks Australian you get the case, 4Gb of onboard NAND flash, a USB to serial adapter, USB to power adapter (althought you should use a real wall wart), and an adapter for the onboard SATA port which […]

gohardware hackingcubieboardcubieboard 2

8 Jul 2013

Dave Cheney 3 min read

This post is a compliment to one I wrote in August of last year, updating it for Go 1.1. Since last year tools such as goxc have appeared which go a beyond a simple shell wrapper to provide a complete build and distribution solution. Introduction Go provides excellent support for producing binaries for foreign platforms […]

goprogrammingcgocross compilationcross compile

7 Jul 2013

2 Jul 2013

30 Jun 2013

Dave Cheney 4 min read

This post continues a series on the testing package I started a few weeks back. You can read the previous article on writing table driven tests here. You can find the code mentioned below in the https://github.com/davecheney/fib repository. Introduction The Go testing package contains a benchmarking facility that can be used to examine the performance […]

goprogrammingbenchmarktesting