Designing a logging abstraction: Go interfaces vs Rust traits
WHAT IT TESTS: ability to design polymorphic abstractions and explain dispatch. OUTLINE: define a Logger interface/trait with a write method; Go interfaces are always dynamically dispatched; Rust lets you choose static dispatch (impl Trait/generics) or…
WHAT IT TESTS: whether you can design a clean abstraction and articulate the static-versus-dynamic dispatch distinction. ANSWER OUTLINE: Define a Logger interface in Go with a Log(msg string) error method and a consumer func process(l Logger); any type with the method conforms. In Rust define trait Logger { fn log(&self, msg: &str) -> io::Result<()>; } and consume via generics fn process<L: Logger>(l: &L) for static dispatch or fn process(l: &dyn Logger) for dynamic.
Read the original → interview
- #go
- #rust
- #polymorphism
- #dispatch
- #traits
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.