[go: up one dir, main page]

DEV Community

David Amos
David Amos

Posted on

How To Stay Curious as a Coder

Man holding a torch looking down a dark tunnel

Cover photo by Wil Stewart on Unsplash.


It's easy to be complacent about curiosity. Our lives are filled with stress. We craft routines around that stress. Sometimes those routines turn life into an inescapable turnstile. It isn't easy to be curious when your life depends on keeping the wheel turning.

I spend a lot of my time solving problems with Python. Problem-solving demands creativity. Curiosity breeds creativity. The demand for creative software solutions is constant, but curiosity comes and goes.

When your curiosity wanes, don't resign yourself to the idea that some people are naturally more curious about things and that perhaps you're not one of them. Curiosity is not an immutable trait. You can learn how to be more curious.

How To Cultivate Curiosity

Curiosity is contagious. Follow curious people, and you'll likely catch the bug. Once your mind is infected with a framework for curiosity, you instinctively apply that framework to everything.

Mystery is the key to curiosity. Embrace feeling puzzled because puzzles are everywhere. Question absolutes and axioms, even the ones in this article. Devise experiments to test premises.

Learn to recognize when your curiosity ebbs. I know that my curiosity is critically low whenever I stop reading consistently. I'm not talking about reading code —— I mean reading anything. It's a case of intellectual malnutrition, and the cure is a content-rich diet.

Consume Content Voraciously

Get into a habit of passive consumption. Listen to podcasts during your commute or household chores. Watch documentaries during your lunch break. If your mind wanders, let it. Don't focus on one topic. A diverse content diet is more likely to reveal a mystery that stirs you.

Actively consume content about mysteries that particularly draw your attention. Read long-form articles and books. Listen intently and take notes. But refrain from forcing yourself into active consumption. Forced activity stifles joy.

🦁 Key Takeaway: Consume content the same way a lion consumes prey. Spend most of your time passively observing the stream of information before you. When hunger strikes, ferociously stalk your curiosity.

Dive Deeply Into Things That Interest You Right Now

Unlike diets that nourish our bodies, a curiosity-inducing content diet has no plan and no schedule. Explore topics haphazardly, but also explore them deeply. Don't delay your curiosity. Pursue topics that interest you right now.

Get lost in rabbit holes, but avoid ones generated algorithmically. Algorithms have a knack for surfacing similar content. Actively search for answers to questions that arise.

💦 Key takeaway: Curiosity moves like water pulled upwards through a tree's xylem by capillary action. Surrender to the twists and turns. Allow the final destination to be a mystery.

Embrace Learning as a Conversation

Curiosity is a tug-of-war between selfishness and humility. You're compelled by a primal urge to know more. Yet learning requires you to expose a gap in your understanding, to recognize that there is still more to be known.

Learning is a conversation. Participate in that conversation. Ask questions. A good question synthesizes existing knowledge and addresses an acknowledged gap in understanding.

♻️ Key takeaway: Curiosity is like a REPL:

  • Read: Consume content.
  • Evaluate: Think critically, ask questions, and discover solutions.
  • Print: Share what you've learned
  • Loop: Interpret feedback and start over.

How To Practice Curiosity as a Coder

Getting better at being curious requires practicing curiosity. Fortunately, coding is full of puzzles. There are packages and tools to discover, languages to learn, and implementation details to explore.

Here are two techniques I've used to practice curiosity while coding.

Use Things In Ways They Weren't Intended to Be Used

Push boundaries and perform experiments.

I once worked as a programmer for a commercial audio/visual installation company. On one job, we installed a distributed video switching system controlled by an app. The app sent TCP packets from an iPad to a network switch and used VLAN untagging to connect video receivers on the network to broadcasts streamed by transmitters.

The app was incompatible with the latest switch firmware. The IT department refused to downgrade the firmware, and the app developer couldn't deliver a patch until well after the project deadline. But I could configure the app to send commands to any IP address.

I could write a TCP server to accept commands from the app, convert them to the network switch's protocol, and forward them to the switch. I needed a machine to host the script. The audio processing unit (APU) was a Linux box with plenty of storage and memory. Installing a custom script would void the warranty.

The APU was programmed by a drag-and-drop visual coding interface. One of the available "blocks" could run Lua scripts inside the application's sandbox. But, could a script running in the sandbox receive commands from the app and communicate with the network switch?

There were no documented restrictions, so I ran an experiment. It worked! Even better, script blocks automatically started whenever the APU booted. Video switching worked effortlessly even after reboots from power outages and other incidents.

My curiosity paid off. We completed the job on time. My discoveries created new solutions for clients and spawned internal tools that saved time and money on installations.

Try To Break Things

Destruction can be productive.

I enjoy finding ways to "break" a language. It isn't about finding bugs. It's about finding code examples that exhibit surprising behavior. It always starts with a question.

"How does a Python set determine if two objects are distinct?"

Knowing where to start looking for answers is a crucial skill. The Python docs on sets are pretty good.

"Oh, ok. Sets use an algorithm that checks if two objects have the same hash value and compare equal to each other. If both checks are true, then those objects are indistinguishable from each other, and the set can only contain one of them."

A little bit of knowledge opens the door to new questions.

"Can you 'trick' a set into thinking two different objects are nondistinct?"

Now there's a fun little puzzle. Think about it. An integer hashes to its value. You can control a custom object's hash value with the .__hash__() method. That means you can create an object that hashes to the same value as the integer 1:

class NotOne:
    def __hash__(self):
        return 1
Enter fullscreen mode Exit fullscreen mode

To confuse a set into thinking NotOne instances are equal to 1, you need them to compare equal to 1. You can make NotOne objects compare equal to any object by implementing an .__eq__() method that always returns True:

class NotOne:
    def __hash__(self):
        return 1

    def __eq__(self, other):
        return True
Enter fullscreen mode Exit fullscreen mode

Now see what happens when you create a set containing 1 and an instance of NotOne:

>>> n = NotOne()

>>> # Create a set S containing 1 and n
>>> S = {1, n}

>>> # S only contains 1
>>> S
{1}

>>> # But somehow n is in S!
>>> n in S
True
Enter fullscreen mode Exit fullscreen mode

n is very much a distinct object from 1. n isn't even a number. It doesn't support arithmetic operations. But you'll never be able to put n and 1 in a set together because they fail to meet a set's criteria for distinctness. It feels weird that any set containing 1 also contains n.

"That's pretty weird. I wonder if there's a way to trick a set into thinking two nondistinct objects are distinct from each other?"

For such a thing to be possible requires an object that doesn't compare equal to itself. If you've ever worked with IEEE 754 NaN objects before, you know they fit the bill.

"What happens when you try to put several NaN values into a Python set?"

Let's find out.

>>> S = {float("nan"), float("nan"), float("nan")}
>>> S
{nan, nan, nan}
Enter fullscreen mode Exit fullscreen mode

"Ok, that is weird. But surely you can verify that the set contains a NaN object. Right?"

Behold:

>>> float("nan") in S
False
Enter fullscreen mode Exit fullscreen mode

I love examples like this. In all honesty, nothing is broken - except maybe my brain for a little bit. Seeking out and understanding examples like these strengthens your intuition about code and surfaces new ideas for solving problems.

Where To Go From Here

Start practicing curiosity today. Ask more questions and do more experiments. Be thankful that it's impossible to know everything. There's always a new puzzle to be solved. There are always new things to wonder about.

Continue Learning

Here are five resources to help you learn more about the science of curiosity and cultivate more of it for yourself:

  • How to become more curious by Scott H. Young. More on the science of curiosity and tips for cutlivating more of it.
  • This is your brain on curiosity by Matthias Gruber. Explore curiosity's role in how well we remember information.
  • The psychology and neuroscience of curiosity by Celeste Kidd and Benjamin Y. Haden. A survey of research into curiosity.
  • Finding curiosity by Steve Mould. In the autumn of 1989 Steve found out that his brain was weird and it changed the course of his life. In a good way. This is the story of his growing passion for education and his quest to find out how people learn.
  • What the f*ck Python! Here's a fun project attempting to explain what exactly is happening under the hood for some counter-intuitive snippets and lesser-known features in Python.

Practice curiosity with me each week by subscribing to my "Curious About Code" newsletter.

Top comments (3)

Collapse
 
andrewbaisden profile image
Andrew Baisden

Enjoyed reading this.

Collapse
 
thewebking profile image
Kingsley Odibendi

Beautiful piece!
One of the best I’ve read this year.

Key takeaway: The curious mind never lacks purpose!

Collapse
 
somacdivad profile image
David Amos

Wow, thanks! What a compliment!

That’s a really great takeaway, too!