From e5d8895c8e837ac8fd0b7272195d0d99afbf589b Mon Sep 17 00:00:00 2001 From: Sam Zaydel Date: Sun, 22 Jun 2014 06:20:12 -0700 Subject: Should have more detail about named return values. There was not a section about named return values, and it feels like it is a valuable and important enough thing to learn early on. If nothing else, when looking at someone else's code this may be a point of confusion. --- go.html.markdown | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index bb6b04eb..2e68a25c 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -116,6 +116,16 @@ can include line breaks.` // Same string type. learnFlowControl() // Back in the flow. } +// It is possible, unlike in many other languages for functions on go +// to have named return values. +// We just have to assign a name to the type being returned in the function +// declaration line. This allows us to easily return from multiple points +// in a function as well as to only use the return keyword, without anything further. +func learnNamedReturns(x, y int) (z int) { + z = x * y + return // z is implicit here, because we named it earlier. +} + // Go is fully garbage collected. It has pointers but no pointer arithmetic. // You can make a mistake with a nil pointer, but not by incrementing a pointer. func learnMemory() (p, q *int) { -- cgit v1.2.3 From ff49deb88608785f913aa0129bab21807b397cd9 Mon Sep 17 00:00:00 2001 From: Sam Zaydel Date: Sun, 22 Jun 2014 06:21:21 -0700 Subject: Fixed `on` to `in` in comment. --- go.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 2e68a25c..0f022541 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -116,7 +116,7 @@ can include line breaks.` // Same string type. learnFlowControl() // Back in the flow. } -// It is possible, unlike in many other languages for functions on go +// It is possible, unlike in many other languages for functions in go // to have named return values. // We just have to assign a name to the type being returned in the function // declaration line. This allows us to easily return from multiple points -- cgit v1.2.3 From 94484047091a18d4b2440650382b9ecbd7840044 Mon Sep 17 00:00:00 2001 From: Sam Zaydel Date: Sun, 22 Jun 2014 20:49:29 -0700 Subject: Slight language change per pull req. comment --- go.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 0f022541..0a0e6c53 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -118,9 +118,9 @@ can include line breaks.` // Same string type. // It is possible, unlike in many other languages for functions in go // to have named return values. -// We just have to assign a name to the type being returned in the function -// declaration line. This allows us to easily return from multiple points -// in a function as well as to only use the return keyword, without anything further. +// Giving a name to type being returned allows us to easily return from +// multiple points in a function as well as to only use the return keyword, +// without anything further. func learnNamedReturns(x, y int) (z int) { z = x * y return // z is implicit here, because we named it earlier. -- cgit v1.2.3 From e881ba74f302cc5cac7f21cd1e7da163ca774d78 Mon Sep 17 00:00:00 2001 From: Sam Zaydel Date: Mon, 23 Jun 2014 07:31:39 -0700 Subject: Hopefully slight language improvement over orig. --- go.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 0a0e6c53..c70f96bd 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -118,9 +118,9 @@ can include line breaks.` // Same string type. // It is possible, unlike in many other languages for functions in go // to have named return values. -// Giving a name to type being returned allows us to easily return from -// multiple points in a function as well as to only use the return keyword, -// without anything further. +// Assigning a name to the type being returned in the function declaration line +// allows us to easily return from multiple points in a function as well as to +// only use the return keyword, without anything further. func learnNamedReturns(x, y int) (z int) { z = x * y return // z is implicit here, because we named it earlier. -- cgit v1.2.3