Interesting things in Go language
I am learning the Go language now and I found something are interesting in Go, and I’d like to summarize them in this article.
“:=”
In go, we can see lots of “:=”, how to understand it? See my this article.
Go doesn’t support the Automatic Type Conversion or Implicit Type Conversion[1]
// Go program to find the
// average of numbers
package mainimport "fmt"func main() {// taking the required
// data into variables
var totalsum int = 846
var number int = 19
var avg float32// explicit type conversion
avg = float32(totalsum) / float32(number)// Displaying the result
fmt.Printf("Average = %f\n", avg)
}
Type inference
Type inference is not new for python. I’m glad that Go also has this feature.
Detail can be found HERE.
NO “while” loops
Use for instead of while, and you can find the detail from [2]
Variadic Functions
[3]
Named Return Parameters
[4][5]
Defer Keyword in Golang
[6]
Slice is by reference
You may know that Python’s slice is a deep copy. However, in Go, the slice is by reference.
Concurrency in Go
See VIDEO HERE
Reference
[1]https://www.geeksforgeeks.org/type-casting-or-type-conversion-in-golang/
[2]https://www.geeksforgeeks.org/loops-in-go-language/
[3]https://www.geeksforgeeks.org/variadic-functions-in-go/
[4]https://www.geeksforgeeks.org/function-returning-multiple-values-in-go-language/
[5] https://www.geeksforgeeks.org/named-return-parameters-in-golang/