12 Nov 2013 , tagged: Go, First Impression, Golang
First impressions: Go
Ever since Google release Go I’ve been curious. Many good things were said and I always read bits and pieces here and there. Last week I decided to dive deeper and write some small things and get to know the language.
So far I’m really impressed. This is a quick list of things I’ve noticed:
Language
The go language is full of nice surprises. I haven’t seen everything, but just a few things that really impressed me:
- Semicolons are optional!
- Type inference with the
:=
operator! - Curly braces after if statements are required, but regular (round) brackets around the condition are not!
- The language does tuples, which means you can cool things like double assignments:
int a,b := 27, 6
A lot of the functions in the class library seem to return tuples, one value being the actual result and the other a status/error code. - It feels very C-like but comes with garbage collection!
- Declaring but not using variables is an error!
- Maps are part of the language, and their declaration requires the last element to be trailed by a comma:
map[string]int { "a":1, "b":2, }
- Go has slices, something like an array but different.
- Reasonable to string conversion for all built in types
- The package library is huge! Need a MIME multipart parser? All there. Need to deal with PNG’s or JPEGs? Go got you covered. Need to start a simple HTTP server with like two lines of code? Here you go.
Tooling
-
Go’s compiler is fast. And calling it just a compiler is an understatement. The
go
tool does so many useful things:- It acts as a build tool. Point it to a directory and it will build everything in it
- Also, it’ll format your source code:
go fmt
- Dependencies will magically be downloaded. (Note to self: until I figure out how this works, it’s Magic!)
-
godoc. It’s fantastic. Run godoc -http:6060 and you have your own webserver that servers the go documentation.
Build Output
- Binaries are statically linked per default. A Hello World program is a whooping 1MB, but I guess it pays off in deployment scenarios.
- I built a simple wiki following the instructions on the go website, and the runtime memory consumption of the entire app, including the HTTP server was 3.3MB.
Summary
All in all I’ve only scratched the surface, but what I’ve seen is really impressive. The Go language itself seems very powerful and has some interesting mechanisms and I hope I can find more time to play with it.
See also
- Learning Go Free book on learning go. Reading it right now and it’s quite good!