diff options
author | C. Bess <cbess@company.com> | 2015-11-09 17:55:53 -0600 |
---|---|---|
committer | C. Bess <cbess@company.com> | 2015-11-09 17:55:53 -0600 |
commit | df0992d72c2a28f140e6ff9681c505f36e19249a (patch) | |
tree | 508aa3abe4c25b957dca442560d9c95c9b1fc97a /go.html.markdown | |
parent | afc5ea14654e0e9cd11c7ef1b672639d12418bad (diff) | |
parent | c460e1fafa0e9b4edc6a5cb35b970bb5cc030a81 (diff) |
Merge remote-tracking branch 'adambard/master'
Conflicts:
swift.html.markdown
Diffstat (limited to 'go.html.markdown')
-rw-r--r-- | go.html.markdown | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/go.html.markdown b/go.html.markdown index 17f10bd9..dc684227 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -10,6 +10,7 @@ contributors: - ["Quint Guvernator", "https://github.com/qguv"] - ["Jose Donizetti", "https://github.com/josedonizetti"] - ["Alexej Friesen", "https://github.com/heyalexej"] + - ["Clayton Walker", "https://github.com/cwalk"] --- Go was created out of the need to get work done. It's not the latest trend @@ -64,7 +65,11 @@ func beyondHello() { learnTypes() // < y minutes, learn more! } -// Functions can have parameters and (multiple!) return values. +/* <- multiline comment +Functions can have parameters and (multiple!) return values. +Here `x`, `y` are the arguments and `sum`, `prod` is the signature (what's returned). +Note that `x` and `sum` receive the type `int`. +*/ func learnMultiple(x, y int) (sum, prod int) { return x + y, x * y // Return two values. } @@ -83,7 +88,7 @@ can include line breaks.` // Same string type. f := 3.14195 // float64, an IEEE-754 64-bit floating point number. c := 3 + 4i // complex128, represented internally with two float64's. - // Var syntax with an initializers. + // var syntax with initializers. var u uint = 7 // Unsigned, but implementation dependent size as with int. var pi float32 = 22. / 7 @@ -103,15 +108,16 @@ can include line breaks.` // Same string type. bs := []byte("a slice") // Type conversion syntax. // Because they are dynamic, slices can be appended to on-demand. - // To append elements to a slice, built-in append() function is used. + // To append elements to a slice, the built-in append() function is used. // First argument is a slice to which we are appending. Commonly, // the array variable is updated in place, as in example below. s := []int{1, 2, 3} // Result is a slice of length 3. s = append(s, 4, 5, 6) // Added 3 elements. Slice now has length of 6. fmt.Println(s) // Updated slice is now [1 2 3 4 5 6] + // To append another slice, instead of list of atomic elements we can // pass a reference to a slice or a slice literal like this, with a - // trailing elipsis, meaning take a slice and unpack its elements, + // trailing ellipsis, meaning take a slice and unpack its elements, // appending them to slice s. s = append(s, []int{7, 8, 9}...) // Second argument is a slice literal. fmt.Println(s) // Updated slice is now [1 2 3 4 5 6 7 8 9] @@ -125,7 +131,7 @@ can include line breaks.` // Same string type. m["one"] = 1 // Unused variables are an error in Go. - // The underbar lets you "use" a variable but discard its value. + // The underscore lets you "use" a variable but discard its value. _, _, _, _, _, _, _, _, _, _ = str, s2, g, f, u, pi, n, a3, s4, bs // Output of course counts as using a variable. fmt.Println(s, c, a4, s3, d2, m) @@ -160,7 +166,7 @@ func expensiveComputation() float64 { } func learnFlowControl() { - // If statements require brace brackets, and do not require parens. + // If statements require brace brackets, and do not require parentheses. if true { fmt.Println("told ya") } @@ -177,8 +183,14 @@ func learnFlowControl() { case 1: case 42: // Cases don't "fall through". + /* + There is a `fallthrough` keyword however, see: + https://github.com/golang/go/wiki/Switch#fall-through + */ case 43: // Unreached. + default: + // Default case is optional. } // Like if, for doesn't use parens either. // Variables declared in for and if are local to their scope. @@ -397,6 +409,8 @@ func requestServer() { The root of all things Go is the [official Go web site](http://golang.org/). There you can follow the tutorial, play interactively, and read lots. +Aside from a tour, [the docs](https://golang.org/doc/) contain information on +how to write clean and effective Go code, package and command docs, and release history. The language definition itself is highly recommended. It's easy to read and amazingly short (as language definitions go these days.) @@ -410,3 +424,5 @@ idioms. Or you can click on a function name in [the documentation](http://golang.org/pkg/) and the source code comes up! Another great resource to learn Go is [Go by example](https://gobyexample.com/). + +Go Mobile adds support for mobile platforms (Android and iOS). You can write all-Go native mobile apps or write a library that contains bindings from a Go package, which can be invoked via Java (Android) and Objective-C (iOS). Check out the [Go Mobile page](https://github.com/golang/go/wiki/Mobile) for more information. |