Should I learn Go Lang?
- 4 minsI have spent many years in top tech companies working in C programming language. The C language is like a carving knife: simple, sharp, and extremely useful in skilled hands. Like any sharp tool, C can injure people who don’t know how to handle it.
I have seen countless bugs due to this programming language’s common mistakes & pitfalls. Not to mention I also had some nightmares whenever a major feature was released.
Once I was introduced to Golang. I was relieved and amazed at how simple this programming language is and how it has removed all those common mistakes & pitfalls.
Golang, or Go, is a popular programming language used by many top tech companies.
Some interesting concepts in Golang
Here I would like to introduce you to some of the most important features of the language, mainly:
- Closures
- Test code
- Interface
- Map
- Package module
- Defer
- Functions as arguments
- Methods
- Pointers
- Channel
- Goroutines
Code Blocks
-
Channel
messages := make(chan string) messages <- "ping"
-
Goroutines
func f(input string) { } func main() { go f("goroutine") }
-
Closures
func intSeq() func() int { i := 0 return func() int { i++ return i } }
-
Test code
func IntMin(a, b int) int { if a < b { return a } return b } func TestIntMinBasic(t *testing.T) { ans := IntMin(2, -2) if ans != -2 { t.Errorf("IntMin(2, -2) = %d; want -2", ans) } }
-
Interface
type geometry interface { area() float64 perim() float64 }
-
Map or Dictionary
m := make(map[string]int) m["k1"] = 7 m["k2"] = 13
-
Package module
File greetings.go package greetings import "fmt" func Hello(name string) string { return message }
-
Defer
func main() { f := createFile("/tmp/defer.txt") defer closeFile(f) writeFile(f) }
-
Functions as arguments (1st class citizens)
func makeHandler(fn func (http.ResponseWriter, *http.Request, string)) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { } }
-
Methods
type rect struct { width, height int } func (r *rect) area() int { return r.width * r.height } func (r rect) perim() int { return 2*r.width + 2*r.height }
-
Pointers
func zeroptr(iptr *int) { *iptr = 0 }
Conclusion
Coming back to the question “Should I learn Go Lang?” I recommend that one should learn what they plan to use. Go was made by Google and is primarily used in areas where Google needed a better language. That mostly means server programming. Go is a mainstream language for all backend programming.
Next Steps
Try the below resources, play with this language, and have fun.
Web Resources:
DISCLAIMER: All views expressed on this site are my own and do not represent the opinions of any entity whatsoever with which I have been, am now, or will be affiliated. Any collateral used is referenced in the Web Resources or others sections on this page. The information provided on this website does not constitute investment advice, financial advice, or trading advice.