Archive · Week 24 · Jun 9 – 15, 2025from 2 items
The Go project accepted two proposals that refine existing packages: one adds DNS record types to the `x/net/dns/dnsmessage` package, and the other documents how the `slices` package treats nil slices. No new language features or runtime changes were introduced.
Worth knowingecosystem
slices: document behavior w.r.t. nil
- What changed
- The proposal documents the current nil‑preserving behavior of all functions in the
slicespackage, includingClip,Clone, andConcat. - Production impact
- The source does not say.
- Try it
- Run
go teston theslicespackage to see the updated documentation. - Source
- github.com/golang/go/issues/73604
Explain it and run it
Understand it, then run it
The slices package in Go already keeps a slice’s nil status when it does not add any elements. For example, if you call slices.Clip or slices.Clone with a nil slice, the result is still nil. When you concatenate slices with slices.Concat, the result is nil only if every input slice is empty. The change simply documents these facts in the package’s documentation, so developers know what to expect.
Run it now
// This program demonstrates how Go’s slice operations preserve or change nilness.
// It uses only the standard library and runs in Go 1.27.1.
package main
import (
"fmt"
)
func main() {
// A nil slice of ints.
var nilSlice []int
// 1. Converting a nil slice to a typed nil slice.
fmt.Printf("[]int(nil) is nil: %v\n", nilSlice == nil)
// 2. Creating an empty slice with make.
empty := make([]int, 0)
fmt.Printf("make([]int, 0) is nil: %v\n", empty == nil)
// 3. Slicing a nil slice to length 0 preserves nilness.
sliced := nilSlice[:0]
fmt.Printf("nilSlice[:0] is nil: %v\n", sliced == nil)
// 4. Appending to a nil slice when the result is still empty.
appended := append(nilSlice, []int{}...)
fmt.Printf("append(nilSlice, []int{}...) is nil: %v\n", appended == nil)
// 5. Appending a non‑empty element to a nil slice creates a non‑nil slice.
appendedNonEmpty := append(nilSlice, 42)
fmt.Printf("append(nilSlice, 42) is nil: %v\n", appendedNonEmpty == nil)
}
What it printed when we ran it on Go 1.27.1
[]int(nil) is nil: true
make([]int, 0) is nil: false
nilSlice[:0] is nil: true
append(nilSlice, []int{}...) is nil: true
append(nilSlice, 42) is nil: false
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Exercise
Write a small program that uses the new slices.Clone function to duplicate a slice, then modifies the clone and shows that the original slice is unchanged.
The 60-second version
This week the Go team added support for two new DNS record types—SVCB and HTTPS—to the `x/net/dns/dnsmessage` package. Those records are now parseable and buildable through the new `SVCBResource` and `HTTPSResource` methods, expanding the package’s ability to handle modern DNS features. In parallel, the team clarified how the `slices` package treats nil slices. The documentation now explicitly states that functions like `Clip`, `Clone`, and `Concat` preserve nilness in the ways they already do, making the behavior clear for developers who rely on these utilities. These changes improve the expressiveness of DNS handling and bring consistency to slice operations, helping teams write more predictable code.
Written by gpt-oss-20b · claims checked against the sources · archive, not individually reviewed