aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHana Kim <hyangah@gmail.com>2026-04-08 22:54:29 +0000
committerGopher Robot <gobot@golang.org>2026-04-09 04:56:48 -0700
commit52749b6d9f44f5c99e9b209ce5399b5da6157e3c (patch)
treec43c30e41175e3bea7b0c6fcbb30e22dd899b78e
parent63dcef0e5930d44e843773b7dca360d3b80d001f (diff)
downloadgo-x-website-52749b6d9f44f5c99e9b209ce5399b5da6157e3c.tar.xz
_content/doc/effective_go: update for Go 1.26 and concise warning
Move warning note to top, make it concise and include release notes link. Update 'new' section for Go 1.26 expression arguments - strictly speaking, this doc is frozen so we don't need to update it. But since `new` is a language builtin so mention it. Change-Id: I3e857f5842d859b534726f2d639b6eea670f8dca Reviewed-on: https://go-review.googlesource.com/c/website/+/764340 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--_content/doc/effective_go.html41
1 files changed, 21 insertions, 20 deletions
diff --git a/_content/doc/effective_go.html b/_content/doc/effective_go.html
index 0b7389a8..e13f48b0 100644
--- a/_content/doc/effective_go.html
+++ b/_content/doc/effective_go.html
@@ -4,11 +4,21 @@
"Breadcrumb": true
}-->
+<div class="Note">
+<strong>Note:</strong> This document was written for Go's release in 2009 and
+is not actively updated. While it remains a good guide for using the core language,
+it does not cover significant changes to the language (generics), ecosystem (modules),
+or libraries added since. See <a href="/issue/28782">issue 28782</a> for context.
+For a complete list of changes,
+see the <a href="/doc/devel/release">release notes</a>.
+</div>
+
<h2 id="introduction">Introduction</h2>
<p>
-Go is a new language. Although it borrows ideas from
-existing languages,
+Go is an open-source programming language that focuses on simplicity, reliability,
+and efficiency, specifically designed to make it easy to build software at scale.
+Although it borrows ideas from existing languages,
it has unusual properties that make effective Go programs
different in character from programs written in its relatives.
A straightforward translation of a C++ or Java program into Go
@@ -35,23 +45,7 @@ all of which you
should read first.
</p>
-<p>
-Note added January, 2022:
-This document was written for Go's
-release in 2009, and has not been updated significantly since.
-Although it is a good guide to understand how to use the language
-itself, thanks to the stability of the language, it says little
-about the libraries and nothing about significant changes to the
-Go ecosystem since it was written, such as the build system, testing,
-modules, and polymorphism.
-There are no plans to update it, as so much has happened and a large
-and growing set of documents, blogs, and books do a fine job of
-describing modern Go usage.
-Effective Go continues to be useful, but the reader should
-understand it is far from a complete guide.
-See <a href="/issue/28782">issue
-28782</a> for context.
-</p>
+
<h3 id="examples">Examples</h3>
@@ -1006,13 +1000,20 @@ It's a built-in function that allocates memory, but unlike its namesakes
in some other languages it does not <em>initialize</em> the memory,
it only <em>zeros</em> it.
That is,
-<code>new(T)</code> allocates zeroed storage for a new item of type
+<code>new(T)</code> allocates zeroed storage for a new variable of type
<code>T</code> and returns its address, a value of type <code>*T</code>.
In Go terminology, it returns a pointer to a newly allocated zero value of type
<code>T</code>.
</p>
<p>
+Starting with Go 1.26, <code>new</code> also accepts an (value) expression as
+an argument, which specifies the initial value of the variable.
+For example, <code>new(int64(300))</code> allocates a new variable of type <code>int64</code>,
+initialized to 300, and returns its address.
+</p>
+
+<p>
Since the memory returned by <code>new</code> is zeroed, it's helpful to arrange
when designing your data structures that the
zero value of each type can be used without further initialization. This means a user of