Go Language Spec —2 min read
Predeclared types

Types The language predeclares certain type names. Others are introduced with type declarations or type parameter lists. Composite types—array, struct, pointer, function, interface, slice, map, and channel types—may be constructed using type literals. Type declarations, type parameter lists, and type aliases are coming up later, so today we’re focused on the predeclared types. The list of predclared types would appear near the beginning of most intro to Go books (I would know, I just read and reviewed 11 of them!

Go Language Spec —1 min read
Type literals

After a long-winded post yesterday, here’s a shorter one to breeze through… Types … A type may also be specified using a type literal, which composes a type from existing types. Type = TypeName [ TypeArgs ] | TypeLit | "(" Type ")" . TypeName = identifier | QualifiedIdent . TypeArgs = "[" TypeList [ "," ] "]" . TypeList = Type { "," Type } . TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType | SliceType | MapType | ChannelType .

Book Reviews —6 min read
Book Review: For the Love of Go

For the absolute beginner to programming, this book will get you started on the right foot.

Go Language Spec —2 min read
Types, named and unnamed

Types A type determines a set of values together with operations and methods specific to those values. A type may be denoted by a type name, if it has one, which must be followed by type arguments if the type is generic. (and jumping ahead a bit) Predeclared types, defined types, and type parameters are called named types. An alias denotes a named type if the type given in the alias declaration is a named type.

Book Reviews —6 min read
Book Review: Get Programming with Go

Written for the absolute beginner, this book will leave most wanting much more.

Go Language Spec —3 min read
Reader Question: Understanding (*T)(nil) syntax

I got a great email from a reader (I didn’t ask their permission to share, so keeping it anonymous) in response to last week’s message Interface variables, pointing out the somewhat essoteric syntax mentioned at the end of the example section: x = v // x has value (*T)(nil) and dynamic type *T The (*T)(nil) syntax is easily confusing. It has been for me, too. So let’s dig into that, and hopefully quell that confusion, once and for all!

Book Reviews —5 min read
Book Review: The Go Programming Language

A great book, but sorely outdated.

Go Language Spec —2 min read
Variables and zero values

Variables A variable’s value is retrieved by referring to the variable in an expression; it is the most recent value assigned to the variable. If a variable has not yet been assigned a value, its value is the zero value for its type. The zero value is covered in greater detail near the end of the spec, but it’s an important concept, so let’s discuss it a bit here.

Go Language Spec —2 min read
Interface variables

Variables … Variables of interface type also have a distinct dynamic type, which is the (non-interface) type of the value assigned to the variable at run time (unless the value is the predeclared identifier nil, which has no type). The dynamic type may vary during execution but values stored in interface variables are always assignable to the static type of the variable. We haven’t really talked about interfaces yet, as that’s coming up in the next section of the spec about types.

Go Language Spec —2 min read
Variable types

Variables The static type (or just type) of a variable is the type given in its declaration, the type provided in the new call or composite literal, or the type of an element of a structured variable. And here we are at one of the core features of Go, it’s static type system. Each variable has a specific static type, which is typically provided in the variable definition, although there are a few cases where the type can be inferred.

Go Language Spec —1 min read
Variables and struct fields

Variables Structured variables of array, slice, and struct types have elements and fields that may be addressed individually. Each such element acts like a variable. This is pretty straight forward. In most contexts, the elements of a struct, array, or slice, can be treated as variables. They can be assigned, or assigned to, using the same syntax. A few examples to illustrate: type Person struct { ID int Name string Age *int } var p Person // p is an instance of the Person struct, with each field initially // set to its zero value.