Errors, runes, and delete in the Go 1 preview
I migrated a small text indexer to the Go 1 preview this week. Three changes looked cosmetic in the notes: the predeclared error interface, rune, and the delete operation for maps. Together they made the programme say what it was doing rather more clearly.
The resulting loop is simple:
for _, r := range text {
counts[r]++
}
if counts['x'] == 0 {
delete(counts, 'x')
}
r is a rune, which names the Unicode code point represented by the value. It is not a character object and it does not make every byte valid UTF-8. The range loop decodes the string and yields code points; indexing the same string still yields bytes. That distinction is now easier to see in a declaration.
My surprise was how much the word rune changed a code review. An int32 says how wide a number is. A rune says why the number exists. The underlying representation remains integer-sized and comparisons remain ordinary comparisons, but the intent no longer has to live in a nearby comment.
The predeclared error type has a similarly small definition: a value satisfying an interface with an Error() string method can be returned as an error. The important convention is that a nil error means success. Packages can expose useful concrete error values while callers that only need the message and success state depend on the common interface.
Map removal is now direct as well. delete(m, key) removes the entry if present and does nothing dramatic if it is absent. Assigning a zero value is not equivalent; the key would still be present. That matters when using the two-result map lookup to distinguish “missing” from “present with zero value.”
I prefer all three changes because they give common operations common names without introducing a class hierarchy or a collection method catalogue. The caveat is that names do not remove semantic work. Text code must still decide what invalid UTF-8 means, errors still need context, and deleting while iterating deserves a deliberate test rather than confidence by punctuation.
This is still a preview, so I am treating the migration as rehearsal rather than declaring the platform finished. Even so, these modest additions feel like the language settling into its vocabulary instead of shopping for a thesaurus.