Smarter ToDos With Kotlin
Article Summary
Kotlin's built-in TODO() is great, except it crashes your app in production. Kaushik Gopal built something smarter.
Standard Kotlin TODOs throw NotImplementedError exceptions that blow up your app whenever the code path executes. Gopal created a custom ToDo() function that's aggressive with developers but gentle with users.
Key Takeaways
- Custom ToDo() only crashes in debug builds, never in production
- Accepts due dates so TODOs blow up only after deadline passes
- Alternative approach: sleep execution 10ms per overdue day (max 5s)
- Keeps documentation in code without requiring external tracking tools
A simple Kotlin wrapper around TODO() that checks BuildConfig.DEBUG and date conditions prevents production crashes while keeping developers accountable.
About This Article
Kaushik Gopal wanted to mark incomplete work directly in his code without relying on external tools. He also needed to prevent NotImplementedError exceptions from crashing applications when they ran in production.
Gopal built a custom ToDo() function in DevCop.kt that wraps Kotlin's standard TODO(). It checks BuildConfig.DEBUG and compares the current date against a deadline parameter before deciding whether to throw an exception.
Developers can now set time-based deadlines for their incomplete work. The function crashes only in debug builds after the deadline passes. There's also an alternative approach using sleep that slows performance by 10ms per overdue day, capped at 5 seconds total. This prevents ANR crashes and avoids blocking other team members.