Strongly Typed Data Structures in Go

311 views
241 views

Published on

Talk from the Go Boston meetup on 4/16/2013

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
311
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Strongly Typed Data Structures in Go

  1. 1. Strongly Typed Data Structures in GoNate FinchCurrently employed by Advent Software13 years as a developerMainly C++/C#Startups & Enterprise Software
  2. 2. Go doesnt have generics● Sure it does – array, slice, map, channel● But...● No user-created generic data structures● No generic functions
  3. 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. 4. Interface{} to the rescue?● No!● What are we, barbarians?● STOGTFO (Strongly Typed Or Get The F Out)– Thats a technical term● Compile-time type safety● Refactoring● Static code analysis
  5. 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. 6. Generic Trees● The algorithmic code is generic● A few lines creates a new wrapper aroundyour data container● No casts, no Interface{}● 36 LOC (incl. comments) for a new tree
  7. 7. Where do we go from here?● This method can be used for other datastructures● Similar methods can be used for other needs.● Slice indices, map keys, both can be used forgenericizing. (not to be confused with jazzercizing)
  8. 8. Questions?Code is on github:https://github.com/natefinch/treehttps://github.com/natefinch/treesampleslides will be posted to G+ after the meeting

×