CSE Roadmap

Common tier · about 4 hours · 12 parts

Part 4 of 12 · 2 min read

Undo turns a mistake into an inconvenience

A confirmation dialog tries to prevent every mistake before it happens; undo accepts that some will happen anyway and makes them cheap to fix.

Think of a word processor's undo button versus a printing press: one lets you take back the last few minutes of changes, the other commits ink to paper the instant you pull the lever.

In plain words: the safest design doesn't try to make every action perfectly reviewed before it happens. It keeps a log of inverse operations so most mistakes can simply be undone. It treats anything genuinely irreversible as the special case that needs explicit warning instead.

A worked example. Sending an email is the one action in this example with no inverse operation — once it leaves, nothing can call it back. So rather than trying to confirm it perfectly up front, it gets a delayed-commit window: the message is held for 10 seconds before it actually sends. A cancel issued inside that window succeeds cleanly; a cancel issued after the window has already closed fails cleanly rather than silently doing nothing.

The key lines. From code/mini-ui/undo.py:

# from code/mini-ui/undo.py
def undo_last(self):
    for e in reversed(self.entries):
        if e.undone: continue
        if e.undo_fn is None: raise CannotUndo(f"'{e.label}' cannot be undone")
        e.undo_fn(self.state); e.undone = True
        return e
    raise CannotUndo("nothing to undo")

Read it as: an entry with no undo_fn raises rather than silently pretending to undo. The log is honest about which of its own actions it can actually reverse. The person is never told something was undone when it wasn't.

Delayed commit

A delayed commit holds an outgoing, otherwise-irreversible action for a short window before it actually fires, so the person has a real chance to cancel it before it's gone for good.

Example: the 10-second DelayedSend window above — a cancel at second 9 works, a cancel at second 11 does not, and the code tells the difference rather than guessing.