Listing some cool features and references MUST read to understand Go

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
  • 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) 
More good references are here

Comments