提交 9e3d4124 编写于 作者: A Anchor

Fix additional typos and grammatical errors

上级 b824c209
......@@ -53,7 +53,7 @@ We usually use `gofmt -w` instead of `go fmt`, the latter will not rewrite your
## go get
This command is for getting remote packages, it supports BitBucket, Github, Google Code, Launchpad so far. There are actually two things that happen after we executed this command. The first thing is to download the source code, then execute `go install`. Before you use this command, make sure you have installed all the related tools.
This command is for getting remote packages. It supports BitBucket, Github, Google Code and Launchpad so far. There are actually two things that happen after we execute this command. The first thing is to download the source code, then execute `go install`. Before you use this command, make sure you have installed all the related tools.
BitBucket (Mercurial Git)
Github (git)
......
# 1.5 Summary
In this chapter, we talked about how to install Go through using three different methods: including from source code, standard package and via third-party tools. Then we showed you how to configure the Go development environment, mainly covering how to setup your `$GOPATH`. After that, we introduced the steps in compilation and deployment of Go programs. We then covered Go commands, including the compile, install, format and test commands. Finally, there are many powerful tools to develop Go programs such as LiteIDE, Sublime Text, Vim, Emacs, Eclipse, IntelliJ IDEA, etc. You can choose any one you like exploring the world of Go.
In this chapter, we talked about how to install Go using three different methods including from source code, the standard package and via third-party tools. Then we showed you how to configure the Go development environment, mainly covering how to setup your `$GOPATH`. After that, we introduced some steps for compiling and deploying Go programs. We then covered Go commands, including the compile, install, format and test commands. Finally, there are many powerful tools to develop Go programs such as LiteIDE, Sublime Text, Vim, Emacs, Eclipse, IntelliJ IDEA, etc. You can choose any one you like exploring the world of Go.
## Links
......
# 2 Go basic knowledge
Go is a compiled system programming language, and it belongs to the C-family. However, its compilation speed is much faster than other C-family languages. It has only 25 keywords..., even less than 26 English letters! Let's take a look at these keywords before we get started.
Go is a compiled system programming language, and it belongs to the C-family. However, its compilation speed is much faster than other C-family languages. It has only 25 keywords... even less than the 26 letters of the English alphabet! Let's take a look at these keywords before we get started.
break default func interface select
case defer go map struct
......
......@@ -4,7 +4,7 @@ In this section, we are going to teach you how to define constants, variables wi
## Define variables
There are many forms of syntax that can use to define variables in Go.
There are many forms of syntax that can be used to define variables in Go.
The keyword `var` is the basic form to define variables, notice that Go puts the variable type `after` the variable name.
......@@ -29,7 +29,7 @@ Define multiple variables with initial values.
*/
var vname1, vname2, vname3 type = v1, v2, v3
Do you think it's too tedious to define variables use the way above? Don't worry because the Go team has found this to be aproblem. Therefore if you want to define variables with initial values, we can just omit the variable type, so the code will look like this instead:
Do you think that it's too tedious to define variables use the way above? Don't worry, because the Go team has also found this to be a problem. Therefore if you want to define variables with initial values, we can just omit the variable type, so the code will look like this instead:
/*
Define three variables with type "type", and initialize their values.
......@@ -51,7 +51,7 @@ Now it looks much better. Use `:=` to replace `var` and `type`, this is called a
_, b := 34, 35
If you don't use any variable that you defined in the program, the compiler will give you compile errors. Try to compile following code, and see what happens.
If you don't use variables that you've defined in your program, the compiler will give you compilation errors. Try to compile the following code and see what happens.
package main
......@@ -93,7 +93,7 @@ In Go, we use `bool` to define a variable as boolean type, the value can only be
### Numerical types
Integer types includ both signed and unsigned integer types. Go has `int` and `uint` at the same time, they have same length, but specific length depends on your operating system. They use 32-bit in 32-bit operating systems, and 64-bit in 64-bit operating systems. Go also has types that have specific length including `rune`, `int8`, `int16`, `int32`, `int64`, `byte`, `uint8`, `uint16`, `uint32`, `uint64`. Note that `rune` is alias of `int32` and `byte` is alias of `uint8`.
Integer types include both signed and unsigned integer types. Go has `int` and `uint` at the same time, they have same length, but specific length depends on your operating system. They use 32-bit in 32-bit operating systems, and 64-bit in 64-bit operating systems. Go also has types that have specific length including `rune`, `int8`, `int16`, `int32`, `int64`, `byte`, `uint8`, `uint16`, `uint32`, `uint64`. Note that `rune` is alias of `int32` and `byte` is alias of `uint8`.
One important thing you should know that you cannot assign values between these types, this operation will cause compile errors.
......@@ -107,7 +107,7 @@ Although int has a longer length than uint8, and has the same length as int32, y
Float types have the `float32` and `float64` types and no type called `float`. The latter one is the default type if using brief statement.
That's all? No! Go support complex numbers as well. `complex128` (with a 64-bit real and 64-bit imaginary part) is the default type, if you need a smaller type, there is one called `complex64` (with a 32-bit real and 32-bit imaginary part). Its form is `RE+IMi`, where `RE` is real part and `IM` is imaginary part, the last `i` is imaginary number. There is a example of complex number.
That's all? No! Go supports complex numbers as well. `complex128` (with a 64-bit real and 64-bit imaginary part) is the default type, if you need a smaller type, there is one called `complex64` (with a 32-bit real and 32-bit imaginary part). Its form is `RE+IMi`, where `RE` is real part and `IM` is imaginary part, the last `i` is imaginary number. There is a example of complex number.
var c complex64 = 5+5i
//output: (5+5i)
......@@ -256,7 +256,7 @@ in `[n]type`, `n` is the length of the array, `type` is the type of its elements
fmt.Printf("The first element is %d\n", arr[0]) // get element value, it returns 42
fmt.Printf("The last element is %d\n", arr[9]) //it returns default value of 10th element in this array, which is 0 in this case.
Because length is a part of the array type, `[3]int` and `[4]int` are different types, so we cannot change the length of arrays. When you use arrays as arguments, functions get their copies instead of references! If you want to use reference, you may want to use `slice`, which we'll talk about later.
Because length is a part of the array type, `[3]int` and `[4]int` are different types, so we cannot change the length of arrays. When you use arrays as arguments, functions get their copies instead of references! If you want to use references, you may want to use `slice`. We'll talk about later.
It's possible to use `:=` when you define arrays.
......@@ -264,7 +264,7 @@ It's possible to use `:=` when you define arrays.
b := [10]int{1, 2, 3} // define a int array with 10 elements, of which the first three are assigned. The rest of them use the default value 0.
c := [...]int{4, 5, 6} // use `` to replace the length paramter and Go will calculate it for you.
c := [...]int{4, 5, 6} // use `` to replace the length parameter and Go will calculate it for you.
You may want to use arrays as arrays' elements. Let's see how to do this.
......
......@@ -187,7 +187,7 @@ Use the `func` keyword to define a function.
return value1, value2
}
We extrapolate the following information from the example above.
We can extrapolate the following information from the example above.
- Use keyword `func` to define a function `funcName`.
- Functions have zero, one or more than one arguments. The argument type comes after the argument name and arguments are separated by `,`.
......@@ -273,7 +273,7 @@ Go supports variable arguments, which means you can give an uncertain numbers of
When we pass an argument to the function that was called, that function actually gets the copy of our variables so any change will not affect to the original variable.
Let's see one example to prove what i'm saying.
Let's see one example in order to prove what i'm saying.
package main
import "fmt"
......
......@@ -88,7 +88,7 @@ Let's see a complete example.
### embedded fields in struct
I've just introduced to you how to define a struct with field names and type.s In fact, Go supports fields without names, but with types. We call these embedded fields.
I've just introduced to you how to define a struct with field names and type. In fact, Go supports fields without names, but with types. We call these embedded fields.
When the embedded field is a struct, all the fields in that struct will implicitly be the fields in the struct in which it has been embdedded.
......
......@@ -365,7 +365,7 @@ There are three steps involved when using reflect. First, we need to convert an
t := reflect.TypeOf(i) // get meta-data in type i, and use t to get all elements
v := reflect.ValueOf(i) // get actual value in type i, and use v to change its value
After that, we can convert the reflect types to get values that we need.
After that, we can convert the reflected types to get the values that we need.
var x float64 = 3.4
v := reflect.ValueOf(x)
......@@ -373,7 +373,7 @@ After that, we can convert the reflect types to get values that we need.
fmt.Println("kind is float64:", v.Kind() == reflect.Float64)
fmt.Println("value:", v.Float())
Finally, if we want to change values from reflect types, we need to make it modifiable. As discussed earlier, there is a difference between pass by value and pass by reference. The following code will not compile.
Finally, if we want to change the values of the reflected types, we need to make it modifiable. As discussed earlier, there is a difference between pass by value and pass by reference. The following code will not compile.
var x float64 = 3.4
v := reflect.ValueOf(x)
......
# 4 User form
A user form is something that is very commonly used when we develop web applications. It provides the ability to communicate between clients and servers. You must be very familiar with forms if you are a web developer; if you are a C/C++ programmer, you may want to ask: what is a user form?
A user form is something that is very commonly used when developping web applications. It provides the ability to communicate between clients and servers. You must be very familiar with forms if you are a web developer; if you are a C/C++ programmer, you may want to ask: what is a user form?
A form is an area that contains form elements. Users can input information into form elements like text boxes, drop down lists, radio buttons, check boxes, etc. We use the form tag `<form>` to define forms.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册