Design extensible Julia code with multiple dispatch
8 steps · about 2 h 2 min · Intermediate
- See the expression problem that dispatch solves (article, Wikipedia, 12 min)
Frames the goal: add new types and new operations without editing old code.
- Compare multiple dispatch with single dispatch (article, Wikipedia, 12 min)
Places Julia's model next to method overloading and visitor patterns.
- Build an abstract type hierarchy (tutorial, Wikibooks, 20 min)
Shows abstract and concrete types and where methods attach.
- Write outer and inner constructors (reference, Julia documentation, 20 min)
Keeps new types valid from the moment they are created.
- Implement iteration and indexing interfaces (reference, Julia documentation, 20 min)
Adding a few methods makes your type work with all of Base.
- Add conversion and promotion rules (reference, Julia documentation, 15 min)
Lets mixed-type arithmetic dispatch to the right method.
- Check which method runs with @which and methodswith (reference, Julia documentation, 8 min)
Confirms that dispatch picked the method you intended.
- Avoid type piracy and over-tight signatures (reference, Julia documentation, 15 min)
Style rules that keep dispatch-based code extensible.