After coding the Go language for half year, I really love this language with all the programming problems being reconsidered and redesigned. At first, it is not easy to get used to this new language, as its syntax is not "usual" at all or may be I was shifting from C/C++ to PHP, then little bit Java/Python, then coding heavily on JavaScript. Sometimes, I mixed up the syntax of different languages when handling multiple languages at the same time. However, learning Go lets you to rethink why the language is designed in this way!
In this post, I would like to list out some cool features / good references that I come across.
- Array and Slices
- Closures & Recursion
- Defer - Ya, this is a really super cool feature that developers will never forget to clean up the resources in the code.
- Gofmt - There is no need to struggle with the formatting with the team anymore
- Reference: gofmt
- Gofmt your code
- Golint - It can help to simplify your code and nicer syntax.
- For example, golint reports warning "should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)" to simplify your code.
- Reference: golint
- Go vet - It can catch some logical bug.
- For example, vet can report suspicious OR if you write the code like this "if a != 1 || a != 2 {}"
- Reference: vet
- JSON - Handy JSON parsing with json.Marshal and json.Unmarshal
- Interface - You can even implement the Stringer interface on some primitive type like int in Go (Actually, Go does not have the primitive type, I should drop this terminology), Anyway, it can make such a clean code below.
- For example
type MyCode int
const (
Msg1 MyCode = iota
)
func (c MyCode) String() string {
switch(c) {
case Msg1:
return "message1"
}
return ""
}
fmt.Printf("%s\n", Msg1)
- Reference: Go Data Structures: Interfaces
- Multiple return values - It simplifies the return object design, so no error code in the return object anymore, as you can return it separately
- Pass by value or reference?
- In Go, as claimed from here, everything is passed by value, just need to pay attention of reference-like object structures.
- Reflection
- Smart way of using label statement in switch and for loop control structures.
- Strings, bytes, runes and characters - It is basic but it is a minimum requirement of software engineers to understand this, and the new introduction of ` to quote the string without escaping it is really cool thing, it is especially useful when you are using in regular expression.
- Strings, bytes, runes and characters in Go
- Regular expression
- The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
- Strong type checking, leading to less error prone codes.
- Testing framework - the native support of testing framework.
- Type switch
More good references are here
- Channels & Go rountine
- Effective Go
- Embedding
- Error handling
- First class function in Go
- The Pig example
- Go by Examples
- Gob
- Godoc
- Gofix
- Glide
- Panic and Recover
- Sharing Memory
- The Blog of Go
Comments
Post a Comment