From: Rob Pike Date: Fri, 22 Mar 2013 21:51:22 +0000 (-0700) Subject: doc/go1.1.html: return requirements X-Git-Tag: go1.1rc2~371 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7191ef7199cae4753dd7f06e66d9b82d760136aa;p=gostls13.git doc/go1.1.html: return requirements R=golang-dev, rsc, jeremyjackins, gri CC=golang-dev https://golang.org/cl/7838045 --- diff --git a/doc/go1.1.html b/doc/go1.1.html index 6542b19b4c..a02298f71e 100644 --- a/doc/go1.1.html +++ b/doc/go1.1.html @@ -54,7 +54,36 @@ TODO

Return requirements

-TODO +Before Go 1.1, a function that returned a value needed an explicit "return" +or call to panic at +the end of the function; this was a simple way to make the programmer +be explicit about the meaning of the function. But there are many cases +where a final "return" is clearly unnecessary, such as a function with +only an infinite "for" loop. +

+ +

+In Go 1.1, the rule about final "return" statements is more permissive. +It introduces the concept of a +terminating statement, +a statement that is guaranteed to be the last one a function executes. +Examples include +"for" loops with no condition and "if-else" +statements in which each half ends in a "return". +If the final statement of a function can be shown syntactically to +be a terminating statement, no final "return" statement is needed. +

+ +

+Note that the rule is purely syntactic: it pays no attention to the values in the +code and therefore requires no complex analysis. +

+ +

+Updating: The change is backward-compatible, but existing code +with superfluous "return" statements and calls to panic may +be simplified manually. +Such code can be identified by go vet.

Changes to the implementations and tools

@@ -338,7 +367,7 @@ The reflect package has several signifi

-It is now possible to run a select statement using +It is now possible to run a "select" statement using the reflect package; see the description of Select and