Intro. to Go Programming Language
Reasons People are Here
- Curious whether go is mature enough to be chosen for production
- Manipulate data with go
- Alternative to Python?
- Iz teh new hotness
- why compile anything when scripting languages are great
- Argue against the “here’s some crazy new thing we should try”
- Automation, TDD, tooling?
- Statically-typed compile-time, checking
Why give this talk
- History of building stuff. Http is how they communicate, but not really websites.
- Lots of machines doing stuff and generating data, but some people/groups want different data.
- Getting data from one place, ETLing it, and taking it to somewhere
- Before: used logstache: JRuby, but really slow, took a minute to spin up the JVM.
- Heard about Go, one of the benefits is that it’s a whole lot faster. It compiles down to binary executable. Helps avoid dependency hell because you can deliver an executable to ops team for deployment (and maybe some docs) [security caveat: if you have a dependency with security exploit, you have to redeploy the entire package).
- Written by Ken Thompson and Rob Pike of Unix and C lineage. Google asked them: if you would rewrite C today, here is some money, do it.
- Alternatives: Rust, Erlang, Haskell
- But Go is a very pragmatic language… was written for C and C++ programmers who actually have NOT flocked to Go. C++ gives way more power over stuff (though has a huge learning curve and potential to do things wrong), but if you’re already good at C++, why learn something new that is more controlled. Instead, Python/PHP/Ruby/Java folks are loving it because it’s not super abstract: there are good primitives, memory management (though you have control over GC).
- You can learn the Go language in a weekend and be productive in it in very little time.
- At least an order of magnitude performance benefit over Ruby/Python.
- The product that the Mozilla team decided to first try Go with is not a customer facing product. Backend, data-processing that replaces an existing system with exactly the same functionality. “If no one notices, we’ve done it right”. Can easily benchmark against the existing system. … and it has paid off!
- HEKA: https://github.com/mozilla-services/heka
How to Learn
- Capital lettered functions are exported/public; lowercase are private to the package
- Everything is within one directory, but all functions can be arbitrarily moved within that directory (unlike python where filenames matter when importing).
- Tooling is great. Optimized for the developer experience.
- gofmt - will automatically format your code in the idiomatic manner; every single developer has this hooked up to format-on-save
- GDB works with Go for debugging. Bug because Go is compiled, you can’t interact dynamically with the current state
- Can return multiple variables from a function
- Not much metaprogramming
- There are no object hierarchies or inheritance trees. You can have a struct that has functions on it. It will automatically dereference pointers to structs, so you can write x.y.z where x is a struct, and the return value of y is another struct.
- Goroutines: concurrent processing
- Was initial concern that if something blew up in production, it would be tough to do post-mortem analysis to fix it
- Have yet to crash go program without a solid stack trace that doesn’t point to what broke
- Can run on multiple cores
- Channels: can send and receive values between goroutines. Automatically manages blocking and back-pressure.
- TDD, benchmarks: https://github.com/smartystreets/goconvey , gomock (ehh), gospec (smooth)
- Package Management: there are 17 different ones == none; cmake vs cgo
- Gorilla (pylons), Martini (more golike restful web framework)
- Go is badass multi-threaded, multi-process language
- Ruby/Python/PHP/Java programmers are loving it
- Has awesome interactive documentation at golang.org