2 min read
Declaring variable types
Today I’ll be love coding again. I hope you can join me! I’ll be working on the backlog for my open-source CouchDB SDK, https://kivik.io/. First some light refactoring, then adding a long-missing feature. Join me to see how many mistakes a senior Go dev makes while coding. We ended last week with a look at variable declarations. Today we continue that, with a look at how a variable’s type is determined.
2 min read
Variable declarations
I don’t know about you, but I feel like we’ve just spent a month trudging through a dense jungle of generics details… let’s talk about something a bit more applicable to all of our code: Variable declarations A variable declaration creates one or more https://go.dev/ref/spec#Variables, binds corresponding identifiers to them, and gives each a type and an initial value. VarDecl = "var" ( VarSpec | "(" { VarSpec ";" } ")" ) .
3 min read
Go 1.21 has been released!
I’m a couple days late with the news… so you hopefully didn’t hear it here first. But two days ago, Go 1.21 was released. This means the Go spec has changed! Today I’ll highlight the main changes introduced to the spec in Go 1.21. None of the changes substantially impacts topics we’ve already covered in the spec series, so I won’t be going back to re-explain changed parts of the spec we’ve already covered.
7 min read
Book Review: 100 Go Mistakes and How to Avoid Them by Teiva Harsanyi
Any Go developer, beginner or expert, would do well to read this book. Probably more than once.
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.
3 min read
Satisfying a type constraint
Satisfying a type constraint A type argument T satisfies a type constraint C if T is an element of the type set defined by C; i.e., if T implements C. As an exception, a strictly comparable type constraint may also be satisfied by a comparable (not necessarily strictly comparable) type argument. More precisely: A type T satisfies a constraint C if T implements C; or C can be written in the form interface{ comparable; E }, where E is a basic interface and T is comparable and implements E.
2 min read
The comparable interface
Are you as curious about Fuzzing in Go as I am? On today’s live stream, I’ll be live coding my way through John Arundel’s 4-part series on Go Fuzzing. I hope you’ll join me! Today we’re learning about the predeclared comparable interface. But before this discussion makes sense, we should jump ahead to one key definition. That of the concept of “strictly comparable”: A type is strictly comparable if it is comparable and not an interface type nor composed of interface types.
2 min read
Type constraints
Are you as curious about Fuzzing in Go as I am? On Monday’s live stream, I’ll be live coding my way through John Arundel’s 4-part series on Go Fuzzing. I hope you’ll [join me!](https://youtube.com/live/VKV-sFFeSQw Type constraints A type constraint is an interface that defines the set of permissible type arguments for the respective type parameter and controls the operations supported by values of that type parameter. TypeConstraint = TypeElem . If the constraint is an interface literal of the form interface{E} where E is an embedded type element (not a method), in a type parameter list the enclosing interface{ … } may be omitted for convenience:
2 min read
Final thoughs on type parameter declarations
Are you as curious about Fuzzing in Go as I am? On Monday’s live stream, I’ll be live coding my way through John Arundel’s 4-part series on Go Fuzzing. I hope you’ll join me! Two more small points before we move on from type parameter declarations… Type parameter declarations … Type parameters may also be declared by the receiver specification of a method declaration associated with a generic type. No surprises here.
2 min read
Resolving type parameter ambiguities
First today, one rather mundane sentence from the spec… Type parameter declarations … Just as each ordinary function parameter has a parameter type, each type parameter has a corresponding (meta-)type which is called its type constraint. Followed by a bit of WTF… A parsing ambiguity arises when the type parameter list for a generic type declares a single type parameter P with a constraint C such that the text P C forms a valid expression:
2 min read
Type parameter declarations
Type parameter declarations A type parameter list declares the type parameters of a generic function or type declaration. The type parameter list looks like an ordinary function parameter list except that the type parameter names must all be present and the list is enclosed in square brackets rather than parentheses. TypeParameters = "[" TypeParamList [ "," ] "]" . TypeParamList = TypeParamDecl { "," TypeParamDecl } . TypeParamDecl = IdentifierList TypeConstraint .