I am a learner .. and on my career as software engineer, I learned many things, and lately Go is one of language that I was interested to learn and use more.
Here are the things I found interesting in Go:
- Simplicity & Performance
Go language is built on promise of simplicity but powerful to do many things, and what I like most is the performance of Go is GREAT.
- No comma
We don’t need to put any comma to end of statement, but we need to stick to specific syntax to make sure our code is translated correctly, mainly if we want to put opening curly brace for if statement, we need to put immediately on same line after if condition itself.
Defer is new thing for me, that I haven’t met on other language. It make sure the code is run before the function executing the
make is special function to create slices, maps, and channels that can return initialized (not zeroed) value of type
Other than array, there is slice which is wrapper of array that has characteristic “copy by reference” and can have dynamic length, differ with array that have fixed length.
- Strict unused import and variable
Compiler will complain if there is unused import or unused variable
- Import for side effect
Sometimes it is useful to import a package only for its side effects, without any explicit use so we can use way like below:
import _ "net/http/pprof"
- Embed Interface and Struct
We can easily implement other interface in one interface by “embedding”, and we also can implement other struct in a struct in very easy way.
Goroutines is one of most interesting thing I found in Go. A goroutine is kind of function executing concurrently with other goroutines in the same address space. It is lightweight, costing little more than the allocation of stack space. And the stacks start small, so they are cheap, and grow by allocating (and freeing) heap storage as required. Goroutines are multiplexed onto multiple OS threads so if one should block, such as while waiting for I/O, others continue to run. “And blocked goroutines doesn’t use a thread” (source: https://talks.golang.org/2016/applicative.slide?utm_source=golangweekly&utm_medium=email#29)
Channels provides communication between goroutines. It is kind of “pipe” to specify goroutine where to send the output of goroutine and where to assign the output from the channel itself.