2 min read
What good are nil channels?
I’ll be live streaming again today! But this time it’s a bit different. I found a bug in the Go standard library! 😲 So on today’s live stream, I’ll be coming up with a minimal reproducible case, and filing a bug report. And hopefully also submitting a patch to fix the bug! Join me I recently asked you if you knew of any practical uses of a nil channel in Go.
1 min read
Assignability in Assignments
It hardly needs to be stated that in an assignment, a value must be assignable, but here we are… Assignment statements … In assignments, each value must be assignable to the type of the operand to which it is assigned… We’ve already talked about assignability, so we won’t go into those details here. But there are some special cases to discuss: … with the following special cases: Any typed value may be assigned to the blank identifier.
1 min read
Wanted: Your Go code to review
In next week’s live stream, I’m going to be reviewing Go code from you, the Boldy Go community. I’ll be looking at three or four projects, which I have never seen before, and offering my feedback. And that’s where you come in. I’d love to review your code! Do you have a Go project on GitHub that you’d like to have reviewed? Maybe it’s a take-home coding assignment you did as part of an interview process, and you’d like some more constructive feedback than you got from the recruiter who ghosted you.
7 min read
Book Review: Test-Driven Development in Go by Adelina Simion
A broad introduction to a wide variety of testing concepts in Go, anchored around the test-first mentality.
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.
1 min read
Expressions
There are a number of terms that get thrown around, often semi-interchangeably by the less initiated (such as myself). “Declaration”, “definition”, “statement”, … and today’s topic “expressions”, just to name a few. But, at least within the context of the Go spec, most such terms have very specific meanings. Expressions An expression specifies the computation of a value by applying operators and functions to operands. So: type foo int and var foo int are not an expressions.
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.
2 min read
Underlying types
We’ve made it through the complete list of types in Go. Now we’re going to dig into some of the fundamentals, with a tour of general “Properties of types and values”. Properties of types and values Underlying types Each type T has an underlying type: If T is one of the predeclared boolean, numeric, or string types, or a type literal, the corresponding underlying type is T itself. Otherwise, T’s underlying type is the underlying type of the type to which T refers in its declaration.
1 min read
Restrictions on underlying type terms
General interfaces … In a term of the form ~T, the underlying type of T must be itself, and T cannot be an interface. type MyInt int interface { ~[]byte // the underlying type of []byte is itself ~MyInt // illegal: the underlying type of MyInt is not MyInt ~error // illegal: error is an interface } Once again, the spec examples are pretty well explained. TL;DR; the ~ prefix must always be associated with an underlying data type.
2 min read
Interface examples with type elements
Let’s look at some interface examples from the spec: General interfaces … // An interface representing only the type int. interface { int } // An interface representing all types with underlying type int. interface { ~int } // An interface representing all types with underlying type int that implement the String method. interface { ~int String() string } // An interface representing an empty type set: there is no type that is both an int and a string.
1 min read
Interfaces don't contain interfaces
As we learned recently, Go interface elements may contain a type term of a non-interface type. It’s worth re-iterating that these are non-interface types. In particular, as the spec states: General interfaces … By construction, an interface’s type set never contains an interface type. That is to say, that the following is invalid: type interface foo { /* some interface elements */ } type interface bar { foo } Actually, I lied.