
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.

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.

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.
9 min read
Book Review: Go Fundamentals
Very thorough, perhaps to a fault, this book is probably a great second read for most Go newcomers.

2 min read
Variables
Last week Go 1.20 was released! It did include a few changes to the Go spec, but none of them affect the portions we’ve covered so far in this series, so we’ll just continue on our merry way… Variables A variable is a storage location for holding a value. The set of permissible values is determined by the variable’s type. A variable declaration or, for function parameters and results, the signature of a function declaration or function literal reserves storage for a named variable.
5 min read
Bonus Book Review: Learn Go with Pocket-Sized Projects
A bonus review of this early-access book, which I'm quite excited about.

3 min read
Constants, typed vs untyped
Constants … Constants may be typed or untyped. Now that’s interesting. And powerful. This is one of the features of Go I featured in my recent video 10 Reasons I Like Go. This feature really helps bridge the gap between the convenience of dynamically typed languages, and the safety of statically typed languages. Let’s look at the details… Literal constants, true, false, iota, and certain constant expressions containing only untyped constant operands are untyped.
Subscribe to Boldly Go: Daily
Every day I'll send you advice to improve your understanding of Go. Don't miss out! I will respect your inbox, and honor my privacy policy.
Unsure? Browse the archive.
7 min read
Book Review: Go For Beginners
This well-written, quick intro to Go for professional developers has some really strong points, but some important down sides, too.

3 min read
Constants don't overflow
Constants … Numeric constants represent exact values of arbitrary precision and do not overflow. Consequently, there are no constants denoting the IEEE-754 negative zero, infinity, and not-a-number values. Now this is a very interesting thing about constants in Go, and it’s something that confuses a lot of people. So let’s play around with this one a bit. If you’re experienced with compiled languages, you’re probably already familiar with numeric overflows.
7 min read
Book Review: Learning GO Programming
Very well organized, reasonable content, but the rampant grammatical errors are terribly distracting.

1 min read
Constants at compile time
Yesterday I made a passing comment in the last code example: Although x is not a constant, the result of len(x) is, because it is known at compile time. I want to dive into this aspect of constants in Go today. In Go (or at least most, if not all implementations of Go) a constant is logically replaced during compilation. This can be a useful mental shortcut when trying to determine whether a given expression can be a constant or not.