Why I use expect/actual sparingly in KMP
expect/actual looks like a clean escape hatch for platform-specific code. It’s also a trap if you reach for it too early.
Reach for it when
- You truly need the platform API (file I/O, crypto, system clock)
- The shape is identical across platforms
- The platform code is small
Skip it when
- An interface in
commonMain+ DI binding works fine - The “platform” diff is one line of config
- You’d otherwise duplicate logic in both
actualblocks
Default to interfaces. expect last.