What's Go?
- Natively compiled, statically typed, garbage collected language, with many similarities to C.
- Small syntax, quick ramp up time for C developers or C# developers familiar with pointers (did I mention GC?)
- Cross-platform (Win/Mac/*nix)
- Concurrency facilities built into the language.
- Designed with servers and distributed systems in mind.
Why learn Go?
- Fast code than uses less compute and memory resources than .NET/Java.
- Learning more languages makes you a better developer in languages you already know.
- Get invited to events with free beer!
Learning Resources
Who's using Go in production?
Can it do what I need?
- Messaging:
- Serialization:
- Databases:
-
Drivers for SQL Server, PostgreSQL, MongoDB, MySQL, etc. https://github.com/golang/go/wiki/SQLDrivers
- For PostgreSQL, the most often cited package is https://github.com/lib/pq, which conforms to database/sql, though it doesn't have the best performance.
- https://github.com/jackc/pgx is currently the fastest in its native mode.
- https://github.com/go-pg/pg is also faster than lib/pq, and offers some ORM-like features like struct mapping.
- Some PostgreSQL wisdom:
- http://www.anchor.com.au/hosting/dedicated/Tuning_PostgreSQL_on_your_Dedicated_Server
<kuroneko> there's some interesting omissions from the postgresql query cost estimation system and some painful assumptions
<kuroneko> and you have to play with the numbers a little to alter it's behaviour appropriately
<kuroneko> things to watch: If your write performance is significantly slower than your read, you need to push random iop cost extremely close to your sequence iop cost otherwise random tables and disk sorts will get prioritised over use of indexes
<kuroneko> the things that hurt DBs the most are full table scans, and worse, aggregates without an index to help order them
<kuroneko> (poor temporary table storage write performance can also hurt)
- Helpful tool for making EXPLAIN ANALYZE readable: http://explain.depesz.com/
- Lightweight ORMs - https://github.com/coopernurse/gorp
- Caching:
- Logging:
- Run as Windows Service:
- Data Structures:
- go-datastructures is a collection of useful, performant, and threadsafe Go datastructures.
Web
Need more? Search for Go Packages (standard packages and open source projects)
Community
YouTube Videos
Development Tools / IDEs
Testing
More Good Stuff
- v1.x is locked down for breaking changes – no need to worry about fixing any code until v2.
- Compiling/linking comes down to a single EXE, all packages are embedded – no DLL's or framework dependencies.
- Can run as a standalone web server, reverse proxy, or FastCGI (you can make Apache, Nginx, or IIS forward calls to your Go server).
- "go doc" works like NDoc, Javadoc, Sandcastle, etc. for automatically building HTML docs for your publicly exported types / API.
For example, all packages automatically get this level of documentation; the same can be done for internal packages easing cross-team dependencies.
- "go fmt" removes (most) developer clashes over style. It mercilessly formats your code which turns out to be a good thing; consistency is more important than which line a curly brace goes on.
- The smallness of the language leads to fewer idioms. Jumping into an unfamiliar codebase isn't scary.
- Reflection and tags (C# "Attribute" like metadata). Very different model than C# but comparable in functionality.
DevOps
Desktop/mobile applications
Tips for C# developers
- map ≈ Dictionary<,> - but it's unordered
- slice ≈ List<>, it's a "view" into a backing array (much like List).
- For maps and slices, understand make and delete.
- For slices, understand append and slice expressions.
- Exceptions are generally errors from multi-value returns. panic exists for truly unrecoverable, exceptional state.
- There are no generics (yet), but there are type assertions. You may not miss them as much as you'd think; typed slices and maps cover many common use cases.
Concurrency