Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some typos in the CodeTour #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .tours/1-go-syntax-and-conventions.tour
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
{
"file": "async/main.go",
"line": 11,
"description": "## Importing packages\r\n🔶 ***Program Structure*** \r\n🔵 ***Language & Syntax*** \r\n\r\nThe \"import\" section specifies that packages that are used in this file. This is similar to \"using\" statements in C#.\r\n\r\nImporting a single package looks like the following:\r\n\r\n```go\r\n import \"fmt\"\r\n```\r\n\r\nTo import multiple packages, package names are surrounded by parentheses. Note that each package is on a separate line, and commas are not used for separators.\r\n\r\n```go\r\n import (\r\n \"encoding/json\"\r\n \"fmt\"\r\n \"io/ioutil\"\r\n )\r\n```\r\n\r\nThe packages listed here are all included when you install Go. Additional packages can be installed using \"go get [package]\" from the command line.\r\n\r\n**Go is opinionated** \r\nIf you list a package that is not used in the file, then you will get a compiler error. The good news is that if you are using an editor helper (such as the \"Go\" extension in Visual Studio Code), unused imports will automatically be removed when you save the file. These helpers will also add the import automatically when you reference a package in the code. So, its best to let the editor helper manage all of this for you.",
"description": "## Importing packages\r\n🔶 ***Program Structure*** \r\n🔵 ***Language & Syntax*** \r\n\r\nThe \"import\" section specifies the packages that are used in this file. This is similar to \"using\" statements in C#.\r\n\r\nImporting a single package looks like the following:\r\n\r\n```go\r\n import \"fmt\"\r\n```\r\n\r\nTo import multiple packages, package names are surrounded by parentheses. Note that each package is on a separate line, and commas are not used for separators.\r\n\r\n```go\r\n import (\r\n \"encoding/json\"\r\n \"fmt\"\r\n \"io/ioutil\"\r\n )\r\n```\r\n\r\nThe packages listed here are all included when you install Go. Additional packages can be installed using \"go get [package]\" from the command line.\r\n\r\n**Go is opinionated** \r\nIf you list a package that is not used in the file, then you will get a compiler error. The good news is that if you are using an editor helper (such as the \"Go\" extension in Visual Studio Code), unused imports will automatically be removed when you save the file. These helpers will also add the import automatically when you reference a package in the code. So, its best to let the editor helper manage all of this for you.",
"selection": {
"start": {
"line": 3,
Expand All @@ -120,7 +120,7 @@
{
"file": "async/main.go",
"line": 13,
"description": "## Capitalization is important\r\n🔵 ***Language & Syntax*** \r\n\r\nCapitalization is important in Go. A capitalized function name means that the function is exported (meaning, it is visible to other packages that import this) -- similar to a \"public\" item in C#. A function name that starts with a lower case letter means that the function is not visible outside of this package. This is similar to \"protected\" item in C#. \r\n\r\n**What this means to us** \r\nWhen we write **our own packages**, lower case functions (and types and other things) will be visible only within the package. If we want something to be visible outside of the package, we need to capitalize the name. \r\n\r\nWhen we use **external packages**, all of the functions that we call and types that we use will be capitalized.\r\n\r\nExamples from external packages:\r\n```go\r\n fmt.Println(\"Hello, World!\")\r\n http.Get(\"http://localhost:8000\")\r\n json.Unmarshal(body, &data)\r\n```\r\n\r\nThe function names are all capitalized (\"Println\", \"Get\", \"Unmarshal\") so that they can be accessed from outside the packages (\"fmt\", \"http\", \"json\")."
"description": "## Capitalization is important\r\n🔵 ***Language & Syntax*** \r\n\r\nCapitalization is important in Go. A capitalized function name means that the function is exported (meaning, it is visible to other packages that import this) -- similar to a \"public\" item in C#. A function name that starts with a lower case letter means that the function is not visible outside of this package. This is similar to a \"protected\" item in C#. \r\n\r\n**What this means to us** \r\nWhen we write **our own packages**, lower case functions (and types and other things) will be visible only within the package. If we want something to be visible outside of the package, we need to capitalize the name. \r\n\r\nWhen we use **external packages**, all of the functions that we call and types that we use will be capitalized.\r\n\r\nExamples from external packages:\r\n```go\r\n fmt.Println(\"Hello, World!\")\r\n http.Get(\"http://localhost:8000\")\r\n json.Unmarshal(body, &data)\r\n```\r\n\r\nThe function names are all capitalized (\"Println\", \"Get\", \"Unmarshal\") so that they can be accessed from outside the packages (\"fmt\", \"http\", \"json\")."
},
{
"file": "async/main.go",
Expand Down
6 changes: 3 additions & 3 deletions .tours/3-parallel-programming.tour
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"file": "async/main.go",
"line": 67,
"description": "## Channel overview \r\n\r\nA channel is go allows us to communicate between asynchronous functions. We can think of this as a thread-safe queue. One asynchronous function can add items to a channel and a different function can remove items from the channel. A channel can only hold one type.\r\n\r\n**make** \r\nThe built-in \"make\" function can be used to create a channel (as well as things like maps and slices). This function creates a channel to hold \"person\" items. The second parameter (\"10\") specifies the capacity of the channel. \r\n\r\n**Channel capacity** \r\nThe capacity of the channel is important. The capacity is the maximum number of items that can be held by the channel. If the channel reaches capacity, then any operations to add new items to the channel will block until there is space for the item.\r\n\r\nIf no capacity is specified, then the capacity is 1. This means that only 1 item can be added to the channel. A new item cannot be added to the channel until after the first item is read from the channel. \r\n\r\n**Writing to a channel** \r\nTo write to a channel, use the \"<-\" operator pointing **toward** the channel. We'll see this a little later. It may look like this: \r\n```go\r\n ch <- p\r\n```\r\nThis reads a value from the variable \"p\" and puts it onto the channel (\"ch\"). If the channel is already at capacity, this operation will **block** until there is space available.\r\n\r\n**Closing a channel** \r\nWhen we are done writing to a channel, we should close it. We'll see why this is important when looking a reading from a channel below. \r\n```go\r\n close(ch)\r\n```\r\nThis code closes the channel \"ch\".\r\n\r\n**Reading from a channel** \r\nTo read from a channel, use the \"<-\" operator pointing **away** from the channel. Here's a sample:\r\n```go\r\n p = <-ch\r\n```\r\nThis code will read a value from the channel (\"ch\") and assign it to the variable \"p\". In addition, we could use the \":=\" operator to declare and assign to a variable. \r\n\r\nIf we try to read from an empty channel, the operation will **block** until an item is available. If we try to read from a **closed** channel, the operation will not block. This is why it is important to close a channel once we are done writing to it. \r\n\r\nWe will look at some alternate ways to read from a channel a bit later."
"description": "## Channel overview \r\n\r\nA channel in go allows us to communicate between asynchronous functions. We can think of this as a thread-safe queue. One asynchronous function can add items to a channel and a different function can remove items from the channel. A channel can only hold one type.\r\n\r\n**make** \r\nThe built-in \"make\" function can be used to create a channel (as well as things like maps and slices). This function creates a channel to hold \"person\" items. The second parameter (\"10\") specifies the capacity of the channel. \r\n\r\n**Channel capacity** \r\nThe capacity of the channel is important. The capacity is the maximum number of items that can be held by the channel. If the channel reaches capacity, then any operations to add new items to the channel will block until there is space for the item.\r\n\r\nIf no capacity is specified, then the capacity is 1. This means that only 1 item can be added to the channel. A new item cannot be added to the channel until after the first item is read from the channel. \r\n\r\n**Writing to a channel** \r\nTo write to a channel, use the \"<-\" operator pointing **toward** the channel. We'll see this a little later. It may look like this: \r\n```go\r\n ch <- p\r\n```\r\nThis reads a value from the variable \"p\" and puts it onto the channel (\"ch\"). If the channel is already at capacity, this operation will **block** until there is space available.\r\n\r\n**Closing a channel** \r\nWhen we are done writing to a channel, we should close it. We'll see why this is important when looking at reading from a channel below. \r\n```go\r\n close(ch)\r\n```\r\nThis code closes the channel \"ch\".\r\n\r\n**Reading from a channel** \r\nTo read from a channel, use the \"<-\" operator pointing **away** from the channel. Here's a sample:\r\n```go\r\n p = <-ch\r\n```\r\nThis code will read a value from the channel (\"ch\") and assign it to the variable \"p\". In addition, we could use the \":=\" operator to declare and assign to a variable. \r\n\r\nIf we try to read from an empty channel, the operation will **block** until an item is available. If we try to read from a **closed** channel, the operation will not block. This is why it is important to close a channel once we are done writing to it. \r\n\r\nWe will look at some alternate ways to read from a channel a bit later."
},
{
"file": "async/main.go",
Expand Down Expand Up @@ -124,7 +124,7 @@
{
"file": "async/main.go",
"line": 82,
"description": "## Waiting for a WaitGroup\r\n\r\nThe call the \"Wait\" will block until the WaitGroup count is at 0. Above, we have a \"for\" loop that adds to the WaitGroup for each iteration (9 items for this example code). Inside the loop, we have goroutines that call a web service and then decrement the WaitGroup. \r\n\r\nThis means that this line of code will block until all of the inner goroutines of the \"for\" loop have completed."
"description": "## Waiting for a WaitGroup\r\n\r\nThe call to \"Wait\" will block until the WaitGroup count is at 0. Above, we have a \"for\" loop that adds to the WaitGroup for each iteration (9 items for this example code). Inside the loop, we have goroutines that call a web service and then decrement the WaitGroup. \r\n\r\nThis means that this line of code will block until all of the inner goroutines of the \"for\" loop have completed."
},
{
"file": "async/main.go",
Expand All @@ -144,7 +144,7 @@
{
"file": "async/main.go",
"line": 87,
"description": "## Using the channel value\r\n\r\nInside the \"for\" loop, we can use the value that was pulled off the channel. In this case, we use it to output the the console. \r\n\r\n**Output** \r\nThe output looks like the following:\r\n```\r\n5: Dave Lister\r\n9: Isaac Gampu\r\n1: John Koenig\r\n2: Dylan Hunt\r\n7: John Sheridan\r\n4: John Crichton\r\n8: Dante Montana\r\n3: Leela Turanga\r\n6: Laura Roslin\r\n```\r\n\r\n**Additional Information** \r\n* Printf: Tour #1 [fmt.Printf][1 - Go Syntax and Conventions#13]"
"description": "## Using the channel value\r\n\r\nInside the \"for\" loop, we can use the value that was pulled off the channel. In this case, we use it to output to the console. \r\n\r\n**Output** \r\nThe output looks like the following:\r\n```\r\n5: Dave Lister\r\n9: Isaac Gampu\r\n1: John Koenig\r\n2: Dylan Hunt\r\n7: John Sheridan\r\n4: John Crichton\r\n8: Dante Montana\r\n3: Leela Turanga\r\n6: Laura Roslin\r\n```\r\n\r\n**Additional Information** \r\n* Printf: Tour #1 [fmt.Printf][1 - Go Syntax and Conventions#13]"
},
{
"file": "async/main.go",
Expand Down