Set-based checks, and type-safe data serialization
You grab your coffee mug, sighing dramatically for the fifth time this morning. “What’s wrong, your code on fire?” a coworker asks, already bracing for your rant. “The cafe menu update is adding duplicates again,” you grumble, staring into the dark abyss of your third Americano. “The dev who wrote this thing is a menace.”
Ah, the classic story. We’ve all been there. Today, we’re dissecting a code snippet that tried its best to manage a cafe’s digital menu but ended up causing a caffeine catastrophe. We’ll follow the code’s journey, expose its flaws, and see how a little refactoring — and a proper tool — can save everyone’s sanity.
The original recipe: A bitter bug in every bite
Let’s look at the first version. On the surface, it seems decent. Helper functions, constants… but like that weird-flavored coffee pod that somehow made its way into the breakroom supply, something is off.
// Simulating the response object
data class CafeMenuUpdateResponse(val newOfferingsList: JsonElement?) {
    fun getNewOfferingsList(): JsonElement? = newOfferingsList
}
// The culprit class
class MenuManager {
private object MenuItemConstants {
        const val…
Learn more about Tale of Code Review and Refactoring : Episode 1
