Skip to content

Better vs worse

Each entry shows one small task, written two or three ways. The “Worse” version is code that an AI agent could produce: it compiles, it passes a simple test, and it looks reasonable. The “OK” version is acceptable. The “Better” version is what a reviewer would ask for.

Every version is real code in the examples/better-vs-worse crate. Its tests show how the versions differ, for example a test that proves the “Worse” version panics.

Each entry has:

  • The task, in one sentence.
  • The versions, labeled Worse, OK, and Better.
  • A verdict table. Each version is compared with the Worse version for correctness, failure behavior, performance, readability, and API ergonomics. The scale is Better, Same, or Worse.
  • Trade-offs: when the “Worse” version is acceptable. There is almost always a case.
  • Related smells and concepts.