From a97a7c5eb6e0bca13076c3ce40c8c1f1f020cca6 Mon Sep 17 00:00:00 2001
From: Rob Pike
+A list of significant changes in Go 1.2, with instructions for updating your +code where necessary. +
+What Go 1 defines and the backwards-compatibility guarantees one can expect as diff --git a/doc/go1.2.html b/doc/go1.2.html index c3d5466cbc..8d513997ee 100644 --- a/doc/go1.2.html +++ b/doc/go1.2.html @@ -163,7 +163,7 @@ no client code depends on the godoc sources and no updating is required.
-The binary distributions available from golang.org include a godoc binary, so users of these distributions are unaffected.
@@ -269,83 +269,176 @@ to list them all here, but the following major changes are worth noting:
-TODO: choose which to call out
-
-The various routines to scan textual input in the
-bufio
-package,
-ReadBytes,
-ReadString
-and particularly
-ReadLine,
-are needlessly complex to use for simple purposes.
-In Go 1.1, a new type,
-Scanner,
-has been added to make it easier to do simple tasks such as
-read the input as a sequence of lines or space-delimited words.
-It simplifies the problem by terminating the scan on problematic
-input such as pathologically long lines, and having a simple
-default: line-oriented input, with each line stripped of its terminator.
-Here is code to reproduce the input a line at a time:
-
+Breaking change: TODO
+archive/tar,archive/zip: fix os.FileInfo implementation to provide base name only (CL 13118043).
+
-
-Updating:
-To correct breakage caused by the new struct field,
-go fix will rewrite code to add tags for these types.
-More generally, go vet will identify composite literals that
-should be revised to use field tags.
-
+encoding: TODO new package defining generic encoding interfaces (CL 12541051).
+The fmt package's formatted print
+routines such as Printf
+now allow the data items to be printed to be accessed in arbitrary order
+by using an indexing operation in the formatting specifications.
+Wherever an argument is to be fetched from the argument list for formatting,
+either as the value to be formatted or as a width or specification integer,
+a new optional indexing notation [n]
+fetches argument n instead.
+The value of n is 1-indexed.
+After such an indexing operating, the next argument to be fetched by normal
+processing will be n+1.
+
+For example, the normal Printf call
+
+fmt.Sprintf("%c %c %c\n", 'a', 'b', 'c')
+
-
+would create the string "a b c", but with indexing operations like this,
+
+fmt.Sprintf("%[3]c %[1]c %c\n", 'a', 'b', 'c')
+
+
+
+the result is ""c a b". The [3] index accesses the third formatting
+argument, whch is 'c', [1] accesses the first, 'a',
+and then the next fetch accesses the argument following that one, 'b'.
+
+The motivation for this feature is programmable format statements to access +the arguments in different order for localization, but it has other uses: +
+ +
+log.Printf("trace: value %v of type %[1]T\n", expensiveFunction(a.b[c]))
+
+
++Updating: The change to the syntax of format specifications +is strictly backwards compatible, so it affects no working programs. +
+ +
+The
+text/template package
+has a couple of changes in Go 1.2, both of which are also mirrored in the
+html/template package.
+
+First, there are new default functions for comparing basic types. +The functions are listed in this table, which shows their names and +the associated familiar comparison operator. +
+ +| Name | Operator | +|
|---|---|---|
eq | == |
+|
ne | != |
+|
lt | < |
+|
le | <= |
+|
gt | > |
+|
ge | >= |
+
+These functions behave slightly differently from the corresponding Go operators.
+First, they operate only on basic types (bool, int,
+float64, string, etc.).
+(Go allows comparison of arrays and structs as well, under some circumstances.)
+Second, values can be compared as long as they are the same sort of value:
+any signed integer value can be compared to any other signed integer value for example. (Go
+does not permit comparing an int8 and an int16).
+Finally, the eq function (only) allows comparison of the first
+argument with one or more following arguments. The template in this example,
+
+{{"{{"}}if eq .A 1 2 3 {{"}}"}} equal {{"{{"}}else{{"}}"}} not equal {{"{{"}}end{{"}}"}}
+
+
+
+reports "equal" if .A is equal to any of 1, 2, or 3.
+
+The second change is that a small addition to the grammar makes "if else if" chains easier to write. +Instead of writing, +
+ +
+{{"{{"}}if eq .A 1{{"}}"}} X {{"{{"}}else{{"}}"}} {{"{{"}}if eq .A 2{{"}}"}} Y {{"{{"}}end{{"}}"}} {{"{{"}}end{{"}}"}}
+
+
++one can fold the second "if" into the "else" and have only one "end", like this: +
+ +
+{{"{{"}}if eq .A 1{{"}}"}} X {{"{{"}}else if eq .A 2{{"}}"}} Y {{"{{"}}end{{"}}"}}
+
+
++The two forms are identical in effect; the difference is just in the syntax. +
+ +
+Updating: Neither change affects existing programs. Those that
+already define functions called eq and so on through a function
+map are unaffected because the associated function map will override the new
+default function definitions.
+
IndexByte
function for consistency with the bytes package.
sync/atomic package
+adds a new set of swap functions that atomically exchange the argument with the
+value stored in the pointer, returning the old value.
+The functions are
+SwapInt32,
+SwapInt64,
+SwapUint32,
+SwapUint64,
+SwapUintptr,
+and
+SwapPointer,
+which swaps an unsafe.Pointer.
+