The Laws of Reflection

Rob Pike Reflection in computing is the ability of a program to examine its own structure, particularly through types; it’s a form of metaprogramming. It’s also a great source of confusion. In this article we attempt to clarify things by explaining how reflection works in Go. Each language’s reflection model is different (and many languages don’t support it at all), but this article is about Go, so for the rest of this article the word “reflection” should be taken to mean “reflection in Go”.

Read more →

Testable Examples in Go

Andrew Gerrand Godoc [[http://golang.org/pkg/testing/#hdr-Examples][examples]] are snippets of Go code that are displayed as package documentation and that are verified by running them as tests. They can also be run by a user visiting the godoc web page for the package and clicking the associated “Run” button. Having executable documentation for a package guarantees that the information will not go out of date as the API changes. The standard library includes many such examples (see the [[http://golang.

Read more →

First Class Functions in Go

Andrew Gerrand **Andrew Gerrand Programmers new to Go are often surprised by its support for function types, functions as values, and closures. The [[http://golang.org/doc/codewalk/functions/][First Class Functions in Go]] code walk demonstrates these features with a simulation of the dice game [[http://en.wikipedia.org/wiki/Pig_(dice)][Pig]]. It is a pretty program that uses the language to great effect, and a fun read for Go beginners and veterans alike. More resources are available at [[http://golang.org/doc/docs.html][golang.org]].

Read more →