Rewriting code you’ve already written for another project can be frustrating. That’s why saving and documenting code snippets matters.
What’s a code snippet?
A code snippet is a small, reusable piece of code – anything from a simple function to a short command sequence.
It could be:
- A function with specific arguments to handle a specific task
- A command line that automates several steps
- A few lines that generate a specific plot
In that last case, next time you want to create a similar plot, you just grab your snippet, tweak the colors, rename the data, and run it. Easy.
For years, I built a personal library of snippets for different languages. Then AI arrived.
I realized it was faster to ask an AI assistant for help than to dig through my old snippets. Opening my GitHub Gist and searching for the right code often took longer than just typing a quick AI query or even a web search. So I asked myself: Do I still need to keep documenting snippets? Or is that now a waste of time?
The answer is yes and no.
Everyone works differently. For me, I’ll stop documenting short, generic snippets – the kind I can easily get from AI or a quick web search. Even if I used an AI agent to search my own library, it’s still slower than asking directly from within my IDE (like VS Code), especially when I’m not even sure if I have a relevant snippet saved.
But not all snippets are equal. Some are complex – they chain multiple steps, include refined logic, and are difficult to reproduce. Those are worth keeping. They save real time.
After all, a code snippet’s value comes down to one thing: how much time it saves you.