More than Just Lines on a Map: Best Practices for U.S Bike Routes
Strongly Typed Data Structures in Go
1. Strongly Typed Data Structures in Go
Nate Finch
Currently employed by Advent Software
13 years as a developer
Mainly C++/C#
Startups & Enterprise Software
2. Go doesn't have generics
● Sure it does – array, slice, map, channel
● But...
● No user-created generic data structures
● No generic functions
3. Do we even need them?
● Built-in containers solve a lot of problems
– Dictionary, set, stack, list
● But not all:
– Left Leaning Red Black Tree
– Heap
– etc
4. Interface{} to the rescue?
● No!
● What are we, barbarians?
● STOGTFO (Strongly Typed Or Get The F Out)
– That's a technical term
● Compile-time type safety
● Refactoring
● Static code analysis
5. Is there another way?
● Yes!
● Have you seen package sort?
● We can do the same thing for data structures
● Index as a generic pointer
● Comparison function using indices
6. Generic Trees
● The algorithmic code is generic
● A few lines creates a new wrapper around
your data container
● No casts, no Interface{}
● 36 LOC (incl. comments) for a new tree
7. Where do we go from here?
● This method can be used for other data
structures
● Similar methods can be used for other needs.
● Slice indices, map keys, both can be used for
genericizing. (not to be confused with jazzercizing)
8. Questions?
Code is on github:
https://github.com/natefinch/tree
https://github.com/natefinch/treesample
slides will be posted to G+ after the meeting