<- View All Books

Error - Driven Development

error-driven-development

Newcomer Nia had a foolproof debugging method: print statements. Lots and lots of print statements. Her entire codebase was lit up with print("Hello?"), print("Where am I?"), and print("Am I here now?"), like she was programming a haunted house instead of a payroll app.

One afternoon, Nia hit an infinite loop she just couldn’t crack. Her code was churning, throwing out "Am I here now?" in a blinding stream, as if the computer itself was having an existential crisis. She decided she needed backup, so she called in Ravi, the senior developer.

Ravi took one look and grinned. “Amateur hour. Watch and learn,” he said, adding just one line to her code:

print("I'm here to make it better.")

The loop continued anyway, firing off "Am I here now?" and "I'm here to make it better." endlessly. Ravi shrugged, reaching for the big guns. He opened a new terminal and typed:

for i in {1..100}; do echo "Here to help" && sleep 0.1; done

He folded his arms and watched proudly as the terminal echoed “Here to help” over and over again, and somehow, the loop still spun on. Nia tried to point out that he’d basically just written a fancier print loop, but he’d already left for coffee.

Meanwhile, their manager Greg, hearing them grumbling, dropped by. “Here’s a trick I learned in ‘98,” he said, adding a strategically placed print("Hello World!") right at the start. He sat back, as though expecting his statement to miraculously break the loop with wisdom alone. “There,” he said. “That’ll shake it loose.”

The loop kept going.

By now, the screen was a mess of "Hello?", "Am I here now?", "I'm here to make it better.", and "Here to help", scrolling faster than they could blink. They’d turned the app into an impromptu poetry generator.

Nia sighed, opening a new window and typing:

print("Please. Just work.")

Suddenly, the code stopped.

Ravi and Greg stared at her in awe.

“Was it that statement?” Ravi whispered.

Nia blinked, too shocked to answer. “It was… desperation, I think.”

From that day on, she renamed her method Error-Driven Development, with one simple mantra: "When in doubt, beg your code to work."

Open source on GitHub

© 2024 Created by DenITDao