@@ -24,3 +24,88 @@ decisions within the context and constraints of your own projects.
24
24
## Schedule
25
25
26
26
{{%session outline}}
27
+
28
+ <details name =" Course outline " >
29
+
30
+ <!-- TODO: Remove this `details` section once the course material is finalized -->
31
+
32
+ The course will cover the topics listed below. Each topic may be covered in one
33
+ or more slides, depending on its complexity and relevance.
34
+
35
+ ### Foundations of API design
36
+
37
+ - Golden rule: prioritize clarity and readability at the callsite. People will
38
+ spend much more time reading the call sites than declarations of the functions
39
+ being called.
40
+ - Make your API predictable
41
+ - Follow naming conventions (case conventions, prefer vocabulary precedented
42
+ in the standard library - e.g., methods should be called "push" not
43
+ "push_back", "is_empty" not "empty" etc.)
44
+ - Know the vocabulary types and traits in the standard library, and use them
45
+ in your APIs. If something feels like a basic type/algorithm, check in the
46
+ standard library first.
47
+ - Use well-established API design patterns that we will discuss later in this
48
+ class (e.g., newtype, owned/view type pairs, error handling)
49
+ - Write meaningful and effective doc comments (e.g., don't merely repeat the
50
+ method name with spaces instead of underscores, don't repeat the same
51
+ information just to fill out every markdown tag, provide usage examples)
52
+
53
+ ### Leveraging the type system
54
+
55
+ - Short recap on enums, structs and type aliases
56
+ - Newtype pattern and encapsulation: parse, don't validate
57
+ - Extension traits: avoid the newtype pattern when you want to provide
58
+ additional behaviour
59
+ - RAII, scope guards and drop bombs: using ` Drop ` to clean up resources, trigger
60
+ actions or enforce invariants
61
+ - "Token" types: force users to prove they've performed a specific action
62
+ - The typestate pattern: enforce correct state transitions at compile-time
63
+ - Using the borrow checker to enforce invariants that have nothing to do with
64
+ memory ownership
65
+ - OwnedFd/BorrowedFd in the standard library
66
+ - [ Branded types] ( https://plv.mpi-sws.org/rustbelt/ghostcell/paper.pdf )
67
+
68
+ ### Don't fight the borrow checker
69
+
70
+ - "Owned" types and "view" types: ` &str ` and ` String ` , ` Path ` and ` PathBuf ` ,
71
+ etc.
72
+ - Don't hide ownership requirements: avoid hidden ` .clone() ` , learn to love
73
+ ` Cow `
74
+ - Split types along ownership boundaries
75
+ - Structure your ownership hierarchy like a tree
76
+ - Strategies to manage circular dependencies: reference counting, using indexes
77
+ instead of references
78
+ - Interior mutability (Cell, RefCell)
79
+ - Working with lifetime parameters on user-defined data types
80
+
81
+ ### Polymorphism in Rust
82
+
83
+ - A quick refresher on traits and generic functions
84
+ - Rust has no inheritance: what are the implications?
85
+ - Using enums for polymorphism
86
+ - Using traits for polymorphism
87
+ - Using composition
88
+ - How do I pick the most appropriate pattern?
89
+ - Working with generics
90
+ - Generic type parameter in a function or trait object as an argument?
91
+ - Trait bounds don't have to refer to the generic parameter
92
+ - Type parameters in traits: should it be a generic parameter or an associated
93
+ type?
94
+ - Macros: a valuable tool to DRY up code when traits are not enough (or too
95
+ complex)
96
+
97
+ ### Error Handling
98
+
99
+ - What is the purpose of errors? Recovery vs. reporting.
100
+ - Result vs. Option
101
+ - Designing good errors:
102
+ - Determine the error scope.
103
+ - Capture additional context as the error flows upwards, crossing scope
104
+ boundaries.
105
+ - Leverage the ` Error ` trait to keep track of the full error chain.
106
+ - Leverage ` thiserror ` to reduce boilerplate when defining error types.
107
+ - ` anyhow `
108
+ - Distinguish fatal errors from recoverable errors using
109
+ ` Result<Result<T, RecoverableError>, FatalError> ` .
110
+
111
+ </details >
0 commit comments