Tech News
← Home  ·  All topics

Polymorphism

2 GoKawiil briefs on this topic

Zig developer proposes compile-time trait-based alternative to interfaces

A programmer writing about recent experience with the Zig programming language describes two conventional approaches to polymorphism in Zig: dynamic interfaces using virtual tables, and comptime 'duck typing' using type reflection and monomorphization. The author argues both approaches have tradeoffs—interfaces add runtime overhead while comptime duck typing lacks strict type contracts—and introduces a technique resembling traits to address these limitations.

Deep dive explains how Rust's dyn Trait represents vtables in memory

A developer blog post dissects how Rust implements runtime polymorphism through dyn Trait, comparing it to C++'s virtual functions and CRTP patterns. The author walks through experiments and diagrams showing exactly how vtable pointers and fat pointers are laid out in memory when using trait objects, with all code published on GitHub.