go-tour: tweaks to basics section
LGTM=campoy
R=campoy
CC=golang-codereviews
https://golang.org/cl/114920043
diff --git a/content/basics.article b/content/basics.article
index 06be3eb..c35973e 100644
--- a/content/basics.article
+++ b/content/basics.article
@@ -23,11 +23,15 @@
* Imports
-This code groups the imports into a parenthesized, "factored" import statement. You can also write multiple import statements, like:
+This code groups the imports into a parenthesized, "factored" import statement.
+
+You can also write multiple import statements, like:
import "fmt"
import "math"
+But it is good style to use the factored import statement.
+
.play prog/tour/imports.go
* Exported names
@@ -72,15 +76,19 @@
A function can return any number of results.
-This function returns two strings.
+The `swap` function returns two strings.
.play prog/tour/multiple-results.go
-* Named results
+* Named return values
-Functions take parameters. In Go, functions can return multiple "result parameters", not just a single value. They can be named and act just like variables.
+Go's return values may be named and act just like variables.
-If the result parameters are named, a `return` statement without arguments returns the current values of the results.
+These names should be used to document the meaning of the return values.
+
+A `return` statement without arguments returns the current values of the results. This is known as a "naked" return.
+
+Naked return statements should be used only in short function, as with the example shown here. They can harm readability in longer functions.
.play prog/tour/named-results.go
@@ -88,6 +96,8 @@
The `var` statement declares a list of variables; as in function argument lists, the type is last.
+A `var` statement can be at package or function level. We see both in this example.
+
.play prog/tour/variables.go
* Variables with initializers
@@ -102,7 +112,7 @@
Inside a function, the `:=` short assignment statement can be used in place of a `var` declaration with implicit type.
-Outside a function, every construct begins with a keyword (`var`, `func`, and so on) and the `:=` construct is not available.
+Outside a function, every statement begins with a keyword (`var`, `func`, and so on) and so the `:=` construct is not available.
.play prog/tour/short-variable-declarations.go
@@ -126,6 +136,10 @@
complex64 complex128
+The example shows variables of several types,
+and also that variable declarations may be "factored" into blocks,
+as with import statements.
+
.play prog/tour/basic-types.go
* Type conversions
@@ -174,4 +188,4 @@
You finished this lesson!
-You can go back to the list of [[/list][modules]] to find what to learn next, or continue with the [[javascript:click('.next-page')][next lesson]].
\ No newline at end of file
+You can go back to the list of [[/list][modules]] to find what to learn next, or continue with the [[javascript:click('.next-page')][next lesson]].
diff --git a/content/prog/tour/imports.go b/content/prog/tour/imports.go
index c886a3f..e259b9c 100644
--- a/content/prog/tour/imports.go
+++ b/content/prog/tour/imports.go
@@ -8,6 +8,5 @@
)
func main() {
- fmt.Printf("Now you have %g problems.",
- math.Nextafter(2, 3))
+ fmt.Printf("Now you have %g problems.", math.Nextafter(2, 3))
}
diff --git a/content/prog/tour/variables-with-initializers.go b/content/prog/tour/variables-with-initializers.go
index 361d149..d27f855 100644
--- a/content/prog/tour/variables-with-initializers.go
+++ b/content/prog/tour/variables-with-initializers.go
@@ -5,8 +5,8 @@
import "fmt"
var i, j int = 1, 2
-var c, python, java = true, false, "no!"
func main() {
+ var c, python, java = true, false, "no!"
fmt.Println(i, j, c, python, java)
}
diff --git a/content/prog/tour/variables.go b/content/prog/tour/variables.go
index 4ffb80d..cd4c26a 100644
--- a/content/prog/tour/variables.go
+++ b/content/prog/tour/variables.go
@@ -4,9 +4,9 @@
import "fmt"
-var i int
var c, python, java bool
func main() {
+ var i int
fmt.Println(i, c, python, java)
}