From 5cff1903ea07f0f7087be72379dded4a987ca589 Mon Sep 17 00:00:00 2001
From: Rob Pike image
packages generate compressed
image files. All these ideas stem from a single interface
(io.Writer
) representing a single method
(Write
). And that's only scratching the surface.
+Go's interfaces have a profound influence on how programs are structured.
@@ -840,12 +841,12 @@ there are multiple considerations involving shallow vs. deep comparison, pointer value comparison, how to deal with recursive types, and so on. We may revisit this issue—and implementing equality for slices will not invalidate any existing programs—but without a clear idea of what -equality of structs and arrays should mean, it was simpler to leave it out for now. +equality of slices should mean, it was simpler to leave it out for now.
-In Go 1, equality is defined for structs and arrays, so such -types can be used as map keys, but slices still do not have a definition of equality. +In Go 1, unlike prior releases, equality is defined for structs and arrays, so such +types can be used as map keys. Slices still do not have a definition of equality, though.
s
in the above
-example) behaves exactly as if it were an argument to the method.
+examples) behaves exactly as if it were an argument to the method.
Whether to define the receiver as a value or as a pointer is the same
question, then, as whether a function argument should be a value or
a pointer.
@@ -1082,15 +1083,15 @@ See the Share Memory By Communicating code
Why doesn't my multi-goroutine program use multiple CPUs?
-You must set GOMAXPROCS
to allow the
+You must set the GOMAXPROCS
shell environment variable
+or use the similarly-named function
+of the runtime package to allow the
run-time support to utilize more than one OS thread.
Programs that perform parallel computation should benefit from an increase in
-GOMAXPROCS
. (See the runtime
package's
-documentation.)
+GOMAXPROCS
.
-If not for this restriction, this code: +Even in cases where the compiler could take the address of a value +to pass to the method, if the method modifies the value the changes +will be lost in the caller. +As a common example, this code:
@@ -1174,7 +1178,7 @@ Consider the following program: func main() { done := make(chan bool) - values := []string{ "a", "b", "c" } + values := []string{"a", "b", "c"} for _, v := range values { go func() { fmt.Println(v) @@ -1268,18 +1272,21 @@ func TestFoo(t *testing.T) {
-Run gotest
in that directory.
+Run go test
in that directory.
That script finds the Test
functions,
builds a test binary, and runs it.
See the How to Write Go Code document for more details.
+See the How to Write Go Code document,
+the testing
package
+and the go test
subcommand for more details.
+
-Go's standard testing
package makes it easy to write unit tests, but it lacks
+Go's standard testing
package makes it easy to write unit tests, but it lacks
features provided in other language's testing frameworks such as assertion functions.
An earlier section of this document explained why Go
doesn't have assertions, and
@@ -1371,9 +1378,9 @@ type checks, reflection, and even panic-time stack traces.
A trivial C "hello, world" program compiled and linked statically using gcc
-on Linux is around 750 kB. An equivalent Go program is around 1.1 MB, but
-that includes more powerful run-time support. We believe that with some effort
-the size of Go binaries can be reduced.
+on Linux is around 750 kB. An equivalent Go program using fmt.Printf
+is around 1.3 MB, but
+that includes more powerful run-time support.
One of Go's design goals is to approach the performance of C for comparable programs, yet on some benchmarks it does quite poorly, including several -in test/bench. The slowest depend on libraries +in test/bench/shootout. The slowest depend on libraries for which versions of comparable performance are not available in Go. For instance, pidigits.go depends on a multi-precision math package, and the C @@ -1467,7 +1474,10 @@ garbage can have a huge effect.)
-In any case, Go can often be very competitive. See the blog post about +In any case, Go can often be very competitive. +There has been significant improvement in the performance of many programs +as the language and tools have developed. +See the blog post about profiling Go programs for an informative example.