Organizing code snippets and programming knowledge
(This post is geared towards programmers.)
This blog is about structuring your personal knowledge. Code snippets and, more generally, programming language information, are interesting in that everyone and their cubicle neighbor seem to have their own approach to organizing them. Here I survey some interesting software and approaches I’ve read about, their features, and present my own method based on my personal wiki.
UPDATE July 29, 2011: there’s a good discussion about the wide range of options people use over at StackOverflow.
This post is an example where wiki features come in handy (by opp. to a thorough survey of Code Snippet Management as, err, an academic field of study).
Software and approaches
A code snippet manager is a piece of software which allows you to organize short pieces of code to reuse later. Yet I’m also seeking the ability to integrate general information about the language (explanations, elements of theory, etc.): in my experience, snippets are often examples of a notion I’m learning.
In researching a bit on existing systems, I’ve found a few feature families:
- Code features
- Syntax highlighting
- Management of multiple files (a plus if you want to add entire libs to your snippet database)
- More specific:
- automatic indentation on insertion
- dependency management
- IDE integration
- (other noteworthy?)
- Organization and retrieval features
- Hierarchical: by language, by functionality/algorithm
- Tags
- Tags are particularly useful here (vs pure hierarchical) because I’ll often stumble on situations like:
- I need a snippet in whatever language for a quick sort algorithm.
- I need a C++ snippet with an iterator loop.
- Tags are particularly useful here (vs pure hierarchical) because I’ll often stumble on situations like:
- Full-text/regular expression search
- Regular expressions are especially useful since you often seek specific constructs and regular text indexing won’t cut it.
- Hyperlinks (well, hallmark of wikis here)
- Date and other general fields
- Sharing
There are lots of different approaches and systems. Specialized software exists that allows you to organize your snippet library in a standalone and dedicated manner. Google Snippely is an example:
A whole bunch of sharewares exist that do similar jobs. Some IDEs come with a snippet manager integrated, as is the case with Visual Studio. Most of these local programs offer a basic outline for organization with more or less search capabilities. If you’re looking for an online version with tagging, check out Snipplr, which, being online, also allows you to share and search others’ submissions.
In the homebrew solution department, this thread is interesting. Some people talk of filesystem based solutions. A few even use a custom database. Personal wikis (as I use, see bellow) and general outliner software clearly need mention too. For example, this blogger says she uses Microsoft OneNote to organize her snippets.
Getting a bit less personal, it should be noted a quite a few bloggers describe their blog as being a “repository for them to search later”. Therefore blogs and websites somehow count as personal snippet libraries (I did a bit of this with my old me-me-me blog over yonder). These score high on integrating other information (ie. free-form formatted text) with the snippets, and of course on the sharing aspect. Community wikis (ie. not personal) are also a great way to organize and share snippets and knowledge (examples here, here).
As a side note, it’s pretty clear we won’t only rely on our own snippets when coding. “The Web + Google” describes my most often used “system” when searching for coding solutions. Yet there are specialized search engines for this job: Google Code Search (you can use regexps on the whole DB!), Koders, and quite a few more.
My approach
Given earlier posts, this doesn’t need a drum roll introduction: I use my personal wiki to organize my snippets and my programming language learning. Of course, this solution allows for inclusion of formatted text. I admit I have a strong tendency to use my snippets for learning more than for reuse, so that factor might weight more than usual in my choice.
A wiki will allow for many different types of retrieval. For example, using the right combination of plugins, with WikidPad I have hierarchical organization, tags/keywords, full text and regular expression search, and, of course, linking. Most popular wiki systems will have plugins to allow for syntax highlighting, and WikidPad is no exception.

Code snippet screenshot in WikidPad
(using the PrettyCode extension)
Where that solution might be lacking is in the IDE integration department, and in the management of multiple files. In the last case, I have a separate personal code (file system) directory to which I may refer using file:// links.



David San Filippo:
Considering your a fan of Snipplr, you may want to check out my product, Snip-It Pro for managing code snippets. Yes, its commercial, but it it works with any program and has a bunch of extra features including integration with Snipplr.
9 January 2010, 8:38 pmGary Udstrand:
I am becoming a big fan of wikidpad and being a programmer I was especially interested in its usage with snippets. You had mentioned a PrettyCode extension but my subsequent Google searches failed to find any references. Where can I find this extension? Does it work with WikidPad 2.0 beta 12?
Thanks!
24 February 2010, 3:58 pm-g
Francois:
Hi Gary. IIRC I had heard of PrettyCode in the Wikidpad Yahoo Groups… (*searching*) Yup, here, for example: http://tech.groups.yahoo.com/g.....ssage/5038. I think it says it’ll work with 2.0.
If you’re on Windows there shouldn’t be any problem, I guess, but under Linux I had to modify it a bit so it outputs old-style HTML without CSS (“font” tags), as under Windows Wikidpad uses an integrated MSIE component, and the default HTML viewer of wx under Linux (at least that was the case in wp 1.9).
25 February 2010, 2:23 pm