From 801484a23b3a65b7813929a390684b9f965729eb Mon Sep 17 00:00:00 2001 From: gondo Date: Sun, 2 Jul 2017 20:38:55 +0800 Subject: more clear explanation for interface (#2779) more clear explanation why interface is consider defined without specifically declaring it (like in other languages `pair implement Stringer`) --- 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 f097caeb..1e121b0f 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -295,7 +295,7 @@ type pair struct { x, y int } -// Define a method on type pair. Pair now implements Stringer. +// Define a method on type pair. Pair now implements Stringer because Pair has defined all the methods in the interface. func (p pair) String() string { // p is called the "receiver" // Sprintf is another public function in package fmt. // Dot syntax references fields of p. -- cgit v1.2.3 From 88e1938994d0c55a03851e8c561dc0c30b745401 Mon Sep 17 00:00:00 2001 From: ven Date: Tue, 4 Jul 2017 13:34:50 +0200 Subject: fix #2700 --- go.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 1e121b0f..50692f9c 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -99,12 +99,12 @@ can include line breaks.` // Same string type. // Arrays have size fixed at compile time. var a4 [4]int // An array of 4 ints, initialized to all 0. - a3 := [...]int{3, 1, 5} // An array initialized with a fixed size of three - // elements, with values 3, 1, and 5. + a5 := [...]int{3, 1, 5, 10, 100} // An array initialized with a fixed size of fize + // elements, with values 3, 1, 5, 10, and 100. // Slices have dynamic size. Arrays and slices each have advantages // but use cases for slices are much more common. - s3 := []int{4, 5, 9} // Compare to a3. No ellipsis here. + s3 := []int{4, 5, 9} // Compare to a5. No ellipsis here. s4 := make([]int, 4) // Allocates slice of 4 ints, initialized to all 0. var d2 [][]float64 // Declaration only, nothing allocated here. bs := []byte("a slice") // Type conversion syntax. @@ -134,7 +134,7 @@ can include line breaks.` // Same string type. // Unused variables are an error in Go. // The underscore lets you "use" a variable but discard its value. - _, _, _, _, _, _, _, _, _, _ = str, s2, g, f, u, pi, n, a3, s4, bs + _, _, _, _, _, _, _, _, _, _ = str, s2, g, f, u, pi, n, a5, s4, bs // Usually you use it to ignore one of the return values of a function // For example, in a quick and dirty script you might ignore the // error value returned from os.Create, and expect that the file -- cgit v1.2.3 From cf976f3fa7d3863a3cc9cd8726379ec20319002d Mon Sep 17 00:00:00 2001 From: Alexsander Akers Date: Fri, 4 Aug 2017 15:40:52 +0200 Subject: Fix typo in Go 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 50692f9c..e5263cf6 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -99,7 +99,7 @@ can include line breaks.` // Same string type. // Arrays have size fixed at compile time. var a4 [4]int // An array of 4 ints, initialized to all 0. - a5 := [...]int{3, 1, 5, 10, 100} // An array initialized with a fixed size of fize + a5 := [...]int{3, 1, 5, 10, 100} // An array initialized with a fixed size of five // elements, with values 3, 1, 5, 10, and 100. // Slices have dynamic size. Arrays and slices each have advantages -- cgit v1.2.3 From c90ee7202e5bb3a00fa4c7159b57586c3aef8ea8 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 15 Feb 2018 10:57:27 +0700 Subject: [go/en] Small typo Small typo in command line commad --- 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 e5263cf6..47d9c234 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -180,7 +180,7 @@ func learnFlowControl() { if true { fmt.Println("told ya") } - // Formatting is standardized by the command line command "go fmt." + // Formatting is standardized by the command line command "go fmt". if false { // Pout. } else { -- cgit v1.2.3 From a78942e8f3e2c8b728bdf0ba5e4f8117027b85a2 Mon Sep 17 00:00:00 2001 From: i Date: Fri, 6 Jul 2018 11:41:46 -0400 Subject: clear up wording --- go.html.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 47d9c234..df677894 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -15,15 +15,15 @@ contributors: --- Go was created out of the need to get work done. It's not the latest trend -in computer science, but it is the newest fastest way to solve real-world +in programming language theory, but it is a way to solve real-world problems. -It has familiar concepts of imperative languages with static typing. +It draws concepts from imperative languages with static typing. It's fast to compile and fast to execute, it adds easy-to-understand -concurrency to leverage today's multi-core CPUs, and has features to -help with large-scale programming. +concurrency because multi-core CPUs are now common, and it's used successfully +in large codebases (~100 million loc at Google, Inc.). -Go comes with a great standard library and an enthusiastic community. +Go comes with a good standard library and a sizeable community. ```go // Single line comment @@ -48,7 +48,7 @@ import ( // executable program. Love it or hate it, Go uses brace brackets. func main() { // Println outputs a line to stdout. - // Qualify it with the package name, fmt. + // It comes from the package fmt. fmt.Println("Hello world!") // Call another function within this package. -- cgit v1.2.3 From ff06f9cf993c79b843008a641abb92e183cff285 Mon Sep 17 00:00:00 2001 From: Divay Prakash Date: Tue, 9 Oct 2018 22:59:19 +0530 Subject: Fix defer wording, closes #2673 --- go.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index df677894..ae99535b 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -277,7 +277,8 @@ func sentenceFactory(mystring string) func(before, after string) string { } func learnDefer() (ok bool) { - // Deferred statements are executed just before the function returns. + // A defer statement pushes a function call onto a list. The list of saved + // calls is executed AFTER the surrounding function returns. defer fmt.Println("deferred statements execute in reverse (LIFO) order.") defer fmt.Println("\nThis line is being printed first because") // Defer is commonly used to close a file, so the function closing the -- cgit v1.2.3 From 18b796972639303e472c8f5d1575061d8c8da2ac Mon Sep 17 00:00:00 2001 From: Flo Date: Tue, 22 Oct 2019 23:11:23 +0100 Subject: add go build tags --- go.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index ae99535b..4fc155b5 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -30,6 +30,12 @@ Go comes with a good standard library and a sizeable community. /* Multi- line comment */ + /* A build tag is a line comment starting with // +build + and can be execute by go build -tags="foo bar" command. + Build tags are placed before the package clause near or at the top of the file + followed by a blank line or other line comments. */ +// +build prod, dev, test + // A package clause starts every source file. // Main is a special name declaring an executable rather than a library. package main -- cgit v1.2.3 From a7242df7d7f49ee2a7440a5a10f203d64e481f24 Mon Sep 17 00:00:00 2001 From: Michael Graf Date: Thu, 30 Jan 2020 15:29:06 -0800 Subject: go/en: add type switch and multiple cases --- go.html.markdown | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 4fc155b5..49f1ade4 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -12,6 +12,7 @@ contributors: - ["Alexej Friesen", "https://github.com/heyalexej"] - ["Clayton Walker", "https://github.com/cwalk"] - ["Leonid Shevtsov", "https://github.com/leonid-shevtsov"] + - ["Michael Graf", "https://github.com/maerf0x0"] --- Go was created out of the need to get work done. It's not the latest trend @@ -196,7 +197,7 @@ func learnFlowControl() { x := 42.0 switch x { case 0: - case 1: + case 1, 2: // Can have multiple matches on one case case 42: // Cases don't "fall through". /* @@ -208,6 +209,19 @@ func learnFlowControl() { default: // Default case is optional. } + + // Type switch allows switching on the type of something instead of value + var data interface{} + data = "" + switch c := data.(type) { + case string: + fmt.Println(c, "is a string") + case int64: + fmt.Printf("%d is an int64\n", c) + default: + // all other cases + } + // Like if, for doesn't use parens either. // Variables declared in for and if are local to their scope. for x := 0; x < 3; x++ { // ++ is a statement. -- cgit v1.2.3 From 3869472f749e74f554eda136654ec9d098cf0fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hou=C5=A1ka?= Date: Sat, 8 Feb 2020 22:57:43 +0100 Subject: [go/en] Clarify safety of local variable address taking. --- go.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 49f1ade4..ec812f20 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -168,10 +168,11 @@ func learnNamedReturns(x, y int) (z int) { // 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. +// Unlike in C/Cpp taking and returning an address of a local varible is also safe. func learnMemory() (p, q *int) { // Named return values p and q have type pointer to int. p = new(int) // Built-in function new allocates memory. - // The allocated int is initialized to 0, p is no longer nil. + // The allocated int slice is initialized to 0, p is no longer nil. s := make([]int, 20) // Allocate 20 ints as a single block of memory. s[3] = 7 // Assign one of them. r := -2 // Declare another local variable. -- cgit v1.2.3 From cd631729a89faaf1cd77d7659e86c00be18e0309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hou=C5=A1ka?= Date: Sat, 8 Feb 2020 23:11:33 +0100 Subject: [go/en] Add value/reference semantics information for arr/slices. --- 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 49f1ade4..0c9082c6 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -109,6 +109,11 @@ can include line breaks.` // Same string type. a5 := [...]int{3, 1, 5, 10, 100} // An array initialized with a fixed size of five // elements, with values 3, 1, 5, 10, and 100. + // Arrays have value semantics. + a4_cpy := a4 // a4_cpy is a copy of a4, two separate instances. + a4_cpy[0] = 25 // Only a4_cpy is changed, a4 stays the same. + fmt.Println(a4_cpy[0] == a4[0]) // false + // Slices have dynamic size. Arrays and slices each have advantages // but use cases for slices are much more common. s3 := []int{4, 5, 9} // Compare to a5. No ellipsis here. @@ -116,6 +121,11 @@ can include line breaks.` // Same string type. var d2 [][]float64 // Declaration only, nothing allocated here. bs := []byte("a slice") // Type conversion syntax. + // Slices (as well as maps and channels) have reference semantics. + s3_cpy := s3 // Both variables point to the same instance. + s3_cpy[0] = 0 // Which means both are updated. + fmt.Println(s3_cpy[0] == s3[0]) // true + // Because they are dynamic, slices can be appended to on-demand. // To append elements to a slice, the built-in append() function is used. // First argument is a slice to which we are appending. Commonly, -- cgit v1.2.3 From 131d536f40ee0e28f6b88b157408835740c434f5 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Sun, 23 Feb 2020 12:44:28 +0000 Subject: Add Golang University playlist links --- go.html.markdown | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 739ec05d..3c0c8e18 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -13,6 +13,7 @@ contributors: - ["Clayton Walker", "https://github.com/cwalk"] - ["Leonid Shevtsov", "https://github.com/leonid-shevtsov"] - ["Michael Graf", "https://github.com/maerf0x0"] + - ["John Arundel", "https://bitfieldconsulting.com/golang"] --- Go was created out of the need to get work done. It's not the latest trend @@ -459,7 +460,7 @@ 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 +The [Go language specification](https://golang.org/ref/spec) itself is highly recommended. It's easy to read and amazingly short (as language definitions go these days.) You can play around with the code on [Go playground](https://play.golang.org/p/tnWMjr16Mm). Try to change it and run it from your browser! Note that you can use [https://play.golang.org](https://play.golang.org) as a [REPL](https://en.wikipedia.org/wiki/Read-eval-print_loop) to test things and code in your browser, without even installing Go. @@ -472,4 +473,9 @@ documentation](http://golang.org/pkg/) and the source code comes up! Another great resource to learn Go is [Go by example](https://gobyexample.com/). +There are many excellent conference talks and video tutorials on Go available on YouTube, and Go trainer [John Arundel](https://bitfieldconsulting.com/golang) has put together three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: +* [Golang University 101](https://www.youtube.com/playlist?list=PLEcwzBXTPUE9V1o8mZdC9tNnRZaTgI-1P) introduces fundamental Go concepts and shows you how to use the Go tools to create and manage Go code +* [Golang University 201](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) steps it up a notch, explaining important techniques like testing, web services, and APIs +* [Golang University 301](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) dives into more advanced topics like the Go scheduler, implementation of maps and channels, and optimisation techniques + 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. -- cgit v1.2.3 From e3c1b63e555733f81d5bdd41b5e1332afb088c7b Mon Sep 17 00:00:00 2001 From: John Arundel Date: Tue, 25 Feb 2020 18:16:47 +0000 Subject: Fix playlist link --- 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 3c0c8e18..0866fcae 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -476,6 +476,6 @@ Another great resource to learn Go is [Go by example](https://gobyexample.com/). There are many excellent conference talks and video tutorials on Go available on YouTube, and Go trainer [John Arundel](https://bitfieldconsulting.com/golang) has put together three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: * [Golang University 101](https://www.youtube.com/playlist?list=PLEcwzBXTPUE9V1o8mZdC9tNnRZaTgI-1P) introduces fundamental Go concepts and shows you how to use the Go tools to create and manage Go code * [Golang University 201](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) steps it up a notch, explaining important techniques like testing, web services, and APIs -* [Golang University 301](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) dives into more advanced topics like the Go scheduler, implementation of maps and channels, and optimisation techniques +* [Golang University 301](https://www.youtube.com/watch?v=YHRO5WQGh0k&list=PLEcwzBXTPUE8KvXRFmmfPEUmKoy9LfmAf) dives into more advanced topics like the Go scheduler, implementation of maps and channels, and optimisation techniques 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. -- cgit v1.2.3 From 32f3ec1880a15db2ab37955612631609e2400698 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Wed, 26 Feb 2020 15:23:37 +0000 Subject: Update go.html.markdown Remove link in body --- 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 0866fcae..726bb134 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -473,7 +473,7 @@ documentation](http://golang.org/pkg/) and the source code comes up! Another great resource to learn Go is [Go by example](https://gobyexample.com/). -There are many excellent conference talks and video tutorials on Go available on YouTube, and Go trainer [John Arundel](https://bitfieldconsulting.com/golang) has put together three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: +There are many excellent conference talks and video tutorials on Go available on YouTube, and Go trainer John Arundel of Bitfield Consulting has put together three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: * [Golang University 101](https://www.youtube.com/playlist?list=PLEcwzBXTPUE9V1o8mZdC9tNnRZaTgI-1P) introduces fundamental Go concepts and shows you how to use the Go tools to create and manage Go code * [Golang University 201](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) steps it up a notch, explaining important techniques like testing, web services, and APIs * [Golang University 301](https://www.youtube.com/watch?v=YHRO5WQGh0k&list=PLEcwzBXTPUE8KvXRFmmfPEUmKoy9LfmAf) dives into more advanced topics like the Go scheduler, implementation of maps and channels, and optimisation techniques -- cgit v1.2.3 From 2643d9f2f05a2162e39d281b47d4986e82b36ff8 Mon Sep 17 00:00:00 2001 From: John Arundel Date: Thu, 27 Feb 2020 11:50:39 +0000 Subject: Remove links/source mention --- go.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 726bb134..b727e59d 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -13,7 +13,7 @@ contributors: - ["Clayton Walker", "https://github.com/cwalk"] - ["Leonid Shevtsov", "https://github.com/leonid-shevtsov"] - ["Michael Graf", "https://github.com/maerf0x0"] - - ["John Arundel", "https://bitfieldconsulting.com/golang"] + - ["John Arundel", "https://github.com/bitfield"] --- Go was created out of the need to get work done. It's not the latest trend @@ -473,7 +473,7 @@ documentation](http://golang.org/pkg/) and the source code comes up! Another great resource to learn Go is [Go by example](https://gobyexample.com/). -There are many excellent conference talks and video tutorials on Go available on YouTube, and Go trainer John Arundel of Bitfield Consulting has put together three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: +There are many excellent conference talks and video tutorials on Go available on YouTube, and here are three playlists of the very best, tailored for beginners, intermediate, and advanced Gophers respectively: * [Golang University 101](https://www.youtube.com/playlist?list=PLEcwzBXTPUE9V1o8mZdC9tNnRZaTgI-1P) introduces fundamental Go concepts and shows you how to use the Go tools to create and manage Go code * [Golang University 201](https://www.youtube.com/playlist?list=PLEcwzBXTPUE_5m_JaMXmGEFgduH8EsuTs) steps it up a notch, explaining important techniques like testing, web services, and APIs * [Golang University 301](https://www.youtube.com/watch?v=YHRO5WQGh0k&list=PLEcwzBXTPUE8KvXRFmmfPEUmKoy9LfmAf) dives into more advanced topics like the Go scheduler, implementation of maps and channels, and optimisation techniques -- cgit v1.2.3 From 09f41ab74c901875c19d95e938f9aa3120200b4a Mon Sep 17 00:00:00 2001 From: Ben Davis Date: Thu, 3 Dec 2020 13:16:43 -0700 Subject: Fix typo in build tag description --- 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 b727e59d..5a9214b0 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -33,7 +33,7 @@ Go comes with a good standard library and a sizeable community. line comment */ /* A build tag is a line comment starting with // +build - and can be execute by go build -tags="foo bar" command. + and can be executed by go build -tags="foo bar" command. Build tags are placed before the package clause near or at the top of the file followed by a blank line or other line comments. */ // +build prod, dev, test -- cgit v1.2.3