I haven't used a statically typed language for anything serious in the past. Most of my experience has been with Python (a dynamically typed language.)
I am beginning to see the benefits of a statically typed language. Especially as the system grows. Type checking is extremely useful and starting to wish it was there in Python.
The more I think back to many of the bugs fixed in my Python web applications I realize they would be non-existent in Go.
What impresses me the most are I/O streams, networking support and goroutines. The combination of those three things is absolutely mind blowing.
Go's func
keyword was originally function
. During a meeting with Larry Page and Sergey Brin, Larry said it should be func
.
Source: Rob Pike during his keynote at GopherCon 2014
A perfect example of how lovely Go can be:
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
var handler http.Handler | |
select { | |
case <-(func() <-chan struct{} { | |
ch := make(chan struct{}) | |
go func() { | |
time.Sleep(6 * time.Second) | |
close(ch) | |
}() | |
return ch | |
})(): | |
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
w.WriteHeader(http.StatusOK) | |
w.Write([]byte("hello world")) | |
}) | |
case <-time.After(5 * time.Second): | |
handler = UserTemplateResponse(http.StatusGatewayTimeout, ci) | |
} | |
handler.ServeHTTP(w, r) | |
}) |
This code is from Gondor's router during spin (being ported from original Python so not complete yet.)
One of the most powerful aspects to Go are its interfaces. See http://talks.golang.org/2015/json.slide for some mind blowing ideas for JSON decoding.