Instacart Kaushik Gopal

Instacart's Smarter ToDos With Kotlin

Original post 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.

Continue reading

What This Article Covers

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.

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

This page summarizes “Smarter ToDos With Kotlin” by Instacart, published Mar 13, 2018. All credit for the original work goes to the authors.

Read the original on tech.instacart.com (opens in new tab)

AI tools for Android

Browse all AI tools →