From 77fc27972a2333c1e3a43cfa406276775ac0c579 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 22 Oct 2025 17:56:32 -0400 Subject: [PATCH] doc/next: improve new(expr) release note One reader pointed out that the example isn't compelling because &age would have worked just as well. This CL changes the example to use a nontrivial expression. Don't nitpick the arithmetic. For #45624 Change-Id: Icc745f5ee7000c1d3559da1388c6a5596c4d1f46 Reviewed-on: https://go-review.googlesource.com/c/go/+/714040 LUCI-TryBot-Result: Go LUCI Auto-Submit: Alan Donovan Reviewed-by: Robert Griesemer --- doc/next/2-language.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/next/2-language.md b/doc/next/2-language.md index ded7becf01..71da62f59e 100644 --- a/doc/next/2-language.md +++ b/doc/next/2-language.md @@ -19,10 +19,14 @@ type Person struct { Age *int `json:"age"` // age if known; nil otherwise } -func personJSON(name string, age int) ([]byte, error) { +func personJSON(name string, born time.Time) ([]byte, error) { return json.Marshal(Person{ Name: name, - Age: new(age), + Age: new(yearsSince(born)), }) } + +func yearsSince(t time.Time) int { + return int(time.Since(t).Hours() / (365.25 * 24)) // approximately +} ``` -- 2.52.0