Update Go track to Go 1.20

tl;dr

The Exercism’s Go test runner now runs on Go 1.20 and we’ve updated the go.mod for exercises to define Go 1.18 as a minimum. This means that you can use Go 1.18 generics in Exercism by default, you don’t need to update + submit your go.mod as part of the solution anymore for that. It also means you can use features in Go 1.19 and 1.20 in Exercism, but in that case you do need to update + submit your go.mod as part of the solution.


Update to Go 1.20

Previously, the Go test runner was running on Go 1.18 and now it runs on Go 1.20. This means that is now possible to use features in Go 1.19 and Go 1.20 in your solutions, and the Go test runner will be able to compile and run them. Since the go.mod on the exercises is set to Go 1.18 (more on that later), this means to use features in Go 1.19 and Go 1.20 in Exercism, you should update your go.mod go’s directive to state go 1.20 and upload the updated go.mod as part of the solution. To upload you go.mod as part of the solution, use the Exercism CLI’s submit command.

Relevant 1.19 and 1.20 features for Exercism

For the full release notes see:

Below are some of the features listed in the release notes that I think might have some impact on Exercism. Feel free to comment below on what your favorite features are and if I’m missing something important.

  • Starting with Go 1.20, the global Seed function of math/rand has been deprecated. If you are using this function in your randomness exercises (e.g Animal Magic) and want to make your exercises future-proof, consider addressing this deprecation!
  • Starting with Go 1.20, the time package now has more constant layouts for common formats. Some of these constants can be used in Booking up for Beauty
  • Starting in Go 1.19, the compile uses a jump table to implement large integer and string switch statements. In Exercism we do have some exercises with medium-sized switch statements, so it might still be worth doing some benchmark experiments on those.
  • Both Go 1.19 and Go 1.20 slightly improve compile and runtime performance, so there’s a potential for slightly faster test runs.
  • The go race detector performance was greatly improved. This benefits exercises like Bank Account where we run the tests with the race detector enabled.

Update go.mod’s go directive to 1.18

As part of the update of the track to Go 1.20, we also decided to update the go directive in the exercises’ go.mod to 1.18. It previously was set to go 1.16. This directive effectively states the set of language features that can be used in the source code of the module.

Go’s generics were introduced in Go 1.18 and having the go.mod’s go directive set to 1.18 means that you can now use generics (and everything else up to Go 1.18) in Exercism’s solutions without the need to manually update and submit your go.mod. If you want to use features in Go 1.19 and Go 1.20, you can, but in that case you still need to bump the go directive to 1.19 or 1.20 and submit the go.mod file as part of your solution.

Setting the baseline to go 1.18 on all exercises will allow us to incorporate generics in the exercises more confidently since you no longer need to do anything special to use them.

Outdated exercises

An unfortunate (but necessary) consequence of us updating the go.mod is that all exercises you have previously done or started are now marked as outdated. Depending on how much of the Go track you did, we know updating all of them can be a chore. If anyone has some script that uses the API to update all the exercises, we’d love to hear about it.

After updating the exercises, the tests should still pass without needing code changes from your side.

External packages update

The Go track supports some external packages other than the stdlib to be used (more info here).

Due to GO-2022-1059 vulnerability, we also updated the version of golang.org/x/text to v0.7.0. If you use this dependency on your solutions, please update it to this version too.

The full list of supported external dependencies and their versions can be seen here.

Pull Requests

Pull requests related with this update:

3 Likes