Archive · Week 30 · Jul 20 – 26, 2026from 2 items
The Go team approved two proposals that extend the standard library’s ergonomics. One relaxes the proposal process for simple `String` and `GoString` methods, while the other adds iterator helpers to the `flag` package. These changes are small but useful for developers writing or maintaining command‑line tools.
Worth knowingstdlib
Blanket approval for String and GoString methods
- What changed
- The Go team has decided that adding a
StringorGoStringmethod to an existing type no longer requires the full proposal review process; it only needs normal code‑review scrutiny. - Production impact
- The source does not say.
- Try it
- Add a
Stringmethod to a custom type and verify that the change compiles without a proposal. - Source
- github.com/golang/go/issues/80024
Explain it and run it
Understand it, then run it
The Go team has decided that adding a String or GoString method to an existing type no longer requires a full proposal review. Before this change, any new method on a type had to go through a committee review that could take weeks. Now, if you simply add a method that returns a human‑readable string for debugging, you only need normal code review. This makes it easier to give types useful string representations without a long approval process.
Run it now
// This program demonstrates adding a String method to an existing type.
// The change is already in Go 1.27.1, so it compiles and runs as is.
package main
import (
"fmt"
)
type Thing struct {
Name string
Age int
}
// String returns a human‑readable representation of Thing suitable for debugging.
func (t Thing) String() string {
return fmt.Sprintf("Thing{Name:%q, Age:%d}", t.Name, t.Age)
}
func main() {
t := Thing{Name: "Gopher", Age: 3}
// fmt.Println uses the String method automatically.
fmt.Println(t)
}
What it printed when we ran it on Go 1.27.1
Thing{Name:"Gopher", Age:3}
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.
Worth knowingstdlib
Flag package iterator helpers
- What changed
- The
flagpackage now includesAll()andAllSet()iterators that returniter.Seq[*Flag], and aFlag.IsSetboolean field. - Production impact
- The source does not say.
- Try it
- Call
flag.All()in a small program and range‑over the returned sequence. - Source
- github.com/golang/go/issues/65675
Explain it and run it
Understand it, then run it
Run it now
// This program demonstrates how to iterate over all command‑line flags
// using the current Go 1.27.1 flag package. The proposed All() iterator
// and Flag.IsSet field are not yet available, so we use VisitAll instead.
package main
import (
"flag"
"fmt"
)
func main() {
// Define a couple of flags for demonstration.
var name string
var age int
flag.StringVar(&name, "name", "world", "your name")
flag.IntVar(&age, "age", 0, "your age")
// Parse the command line arguments.
flag.Parse()
// VisitAll walks over all defined flags, regardless of whether they
// were set on the command line. The callback receives a *flag.Flag.
flag.VisitAll(func(f *flag.Flag) {
fmt.Printf("flag: --%s, value: %s, default: %s\n",
f.Name, f.Value.String(), f.DefValue)
})
}
What it printed when we ran it on Go 1.27.1
flag: --age, value: 0, default: 0 flag: --name, value: world, default: world
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
Exercise – Using the new blanket‑approval rule for String
Write a String() method for the Person type that returns a human‑readable description. When you run the program, printing a Person value with fmt.Println should use your String() method.
package main
import (
"fmt"
)
type Person struct {
Name string
Age int
}
func main() {
p := Person{Name: "Ada", Age: 30}
fmt.Println(p) // <-- your String method will be used here
}
Show a solution
package main
import (
"fmt"
)
type Person struct {
Name string
Age int
}
// String returns a human‑readable representation of a Person.
func (p Person) String() string {
return fmt.Sprintf("%s (%d years old)", p.Name, p.Age)
}
func main() {
p := Person{Name: "Ada", Age: 30}
fmt.Println(p) // prints: Ada (30 years old)
}
What it printed when we ran it on Go 1.27.1
Ada (30 years old)
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.
The 60-second version
This week the Go team made a couple of small but handy changes to the standard library. First, they decided that adding a `String` or `GoString` method to an existing type no longer needs the full proposal process—just normal code review. That means you can give your types a human‑readable representation without waiting for committee approval. Second, they added new iterator helpers to the flag package. Now you can call `flag.All()` to get a sequence of all defined flags, or `flag.AllSet()` to get only those that were actually set on the command line. Both changes are aimed at making the library easier to use in everyday projects.
Written by gpt-oss-20b · claims checked against the sources · archive, not individually reviewed