Instacart Kaushik Gopal Mar 13, 2018

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

Critical Insight

A simple Kotlin wrapper around TODO() that checks BuildConfig.DEBUG and date conditions prevents production crashes while keeping developers accountable.

The author's original time-bomb approach got pushback from Jesse Wilson, leading to an even cheekier solution involving strategic sleep delays.

About This Article

Problem

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.

Solution

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.

Impact

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.