There are not many ways to write the Go language, and the writing style is fixed to some extent, so it can be implemented simply. It's relatively easy to understand the language specifications for yesterday.
A compilation language is a language that ** compiles (translates) all code into machine language or intermediate language at once ** before execution. The compiled language has the characteristic that the description method is strict **, but it has the characteristic that ** processing is fast ** because it is converted into machine language at once and processed by the computer. The Go language is said to be ** fast to compile **.
In Go language, you must specify the type in advance when writing a program **. By compiling static typing in advance, there is no need to check the type biosynthesis when the program is executed, which speeds up the process. It also checks for types at compile time, so you can check for ** type matching errors **. Java and C have this feature.
On the other hand, there are dynamically typed languages that do not type when writing programs. JavaScript, Ruby, Python, etc. are dynamically typed languages. These are not fast, but the amount of writing in the program is small and the learning cost of the sentence is low, so you can write the code intuitively.
It is a function to start processing in a virtual thread, and it is an image of a lightweight thread. This can be achieved by calling the function with the go keyword.
func main() {
go f() //Calling a go-routine
}
func f() {
// some task
}
You cannot set a return value for a function in Goroutine. In the go routine, it is discarded when the process is completed.
Since it is not possible to detect whether a work is being performed or abandoned using only the go routine, error handling cannot be performed when unintended behavior occurs. Also, since there is no return value, you cannot receive the processed value as a result of the work. Therefore, a function called a channel enables ** data exchange between go-routines **. By describing the reception of the channel, ** it will wait until the value is sent **. A channel can also have a ** buffer **, and specifying a buffer at creation determines the number of data a channel can have. (Default is 0) Sending a value beyond the buffer causes send blocking.
The Go language has a large collection of standard libraries.
The Go language allows you to create binaries for different operating systems and architectures. This can be achieved by specifying the environment variables GOOS and GOARCH as shown below.
# Windows(32bit)For
$ GOOS=windows GOARCH=386 go build
# Linux(For 64bit)
$ GOOS=linux GOARCH=amd64 go build
Programs written in Go language are basically generated as single binaries that can be executed independently. Once compiled, there is no need to manage the runtime and dependencies required for LL language (a language that can realize processing with a short description), and there is no need to prepare an operating environment.
Recommended Posts