This article contains affiliate links. See my affiliate disclosure for more information.

This might sound crazy, but… I like to practice having ridiculous ideas.

I pick a problem or a question and brainstorm absurd solutions. Anything goes, no matter how crazy. This is particularly fun to do with code. And it's not just for diversion.

Practicing absurdity helps solve real-world coding problems.

✉️
This article was originally published in my Curious About Code newsletter. Never miss an issue. Subscribe here →

Have fun and boost creativity

I asked people on Twitter to share the most absurd way they could think of to add two numbers in Python without using the + operator.

Luciano Ramalho, the author of Fluent Python (essential reading for any intermediate Python developer) responded with this gem:

View on Twitter

I love Luciano's solution because the foundation is relatively tame.

Instead of adding two numbers a and b,  he subtracts -a from b. It's the recursion, though, that takes it to the next level. I don't even mind that it only works for integers! It's just beautifully absurd.

But what's the point of writing code like this?

For starters, absurdity is fun.

Gerard van Honthorst, Public domain, via Wikimedia Commons

Happiness and fun are linked to creative output. So coming up with absurd code examples like Luciano's is a way to set the stage and prepare your mind for creative work. It gets you into a creative mood.

The benefits don't end there.

Make surprising conceptual connections

Absurd code ties concepts together in unusual ways.

One way that your brain forms memories is through synaptic plasticity. Synapses — i.e., connections — between neurons are strengthened when they fire together and weakened when they do not. Stronger connections increase the likelihood that specific neural patterns will fire in response to a given stimulus.

In other words:

💡
Writing absurd code strengthens connections between concepts that may not have been strengthened otherwise.

Not all of these connections are useful.

Many will not last. But some will surprise you when they pop back into your thoughts during a serious coding session. Suddenly, you have a new and potentially productive way to approach a problem.

And sometimes you'll break things in important ways.

Expose weaknesses in systems

Absurd code comes in many forms.

There are examples like Luciano's that take a silly approach to solving a simple problem. Then there's the Obfuscated C Mandelbrot- and Julia-set Generator. It's written in ANSI-C and its source code resembles the Mandelbrot set:

The Obfuscated C Mandelbrot- and Julia-set Generator

Got a sweet tooth for a chocolate cake whose recipe is a valid "Hello World" program? Have at it.

When you write ridiculous code, all of the rules are off of the table.

The absurdity might lie in the silliness of the problem's solutions. Or it might be found in the presentation of the code itself. Sometimes, it's about writing innocuous-looking code with a sinister secret.

That's what Linus Åkesson did when he won the 2015 Underhanded C contest.

Åkesson's code leverages a subtle confusion of floating-point types to misrepresent the energy spectrum of a nuclear warhead. A nuclear arms inspector could be fooled by the spectrum and, according to Page Stoutland — a technical advisor for the Nuclear Threat Initiative — "could let states take credit for disarmament without actually disarming.”

Seriously.

A bad code contest exposed a critical flaw in nuclear nonproliferation.

Turn creativity into a habit

Feel like you aren't clever enough to write "good" bad code?

I've got good news for you. You're not born with a finite amount of "creative juice." You're born into a sea of sweeping creative currents. You can learn how to navigate those currents and explore the depths of your imagination. Creativity is a skill you can practice.

And you can start small.

Here are five coding prompts to get you started:

  • What's the most absurd way you can think of to print "Hello world"?
  • Write a program that uses lots of resources but does nothing.
  • Write a program that compiles and runs in two different programming languages.
  • Solve a problem with code that really shouldn't be solved with code.
  • Write a program that has no infinite loop but will never stop running (It's OK if it would stop running, but there's not enough time between now and the heat death of the universe.)

Work on a new prompt once or twice a month.

And don't forget to raise a glass to the joy of absurdity.

Gerard van Honthorst, Public domain, via Wikimedia Commons

Want to learn more about the intersection of coding and creativity?

Manning just launched The Creative Programmer in their early access program.

While you're at it, give Dylan Beattie's classic talk The Art of Code a watch.

And for absurd inspiration, I highly recommend XKCD creator Randall Munroe's books How To, What If, and What If 2.