3 Places To Keep Your Pocket Code (Besides Your Pocket)
Filed Under Code, Efficiency Tips
Every developer has some amount of code that they feel is reusable to them, but doesn’t clear that bar to be reusable for everyone.
This is what I call Pocket Code – reusable code that does not belong in reusable libraries that is shared amongst projects and team members, but code that you keep handy somewhere to be cut-and-pasted into applicable projects (I need not bring up the now famous State enumeration).
But where do we keep this code? Do we keep just lug it around on a memory stick or do we attempt to squeeze every last ounce of worth out of it? Here are some ideas besides keeping it squirreled away:
Code Snippet Websites
There are tons of code snippet sites and directories out there. Some are generic, while others are very specific to language or need. Here are the few that I use frequently:
- Code Project – http://www.codeproject.com/
- DZone.com Snippets – http://snippets.dzone.com/
- Regular Expression Library – http://regexlib.com/
- VS.NET IDE Snippet Library – http://gotcodesnippets.com/
- Joyent CodeSnippets – http://codesnippets.joyent.com/
Got another one we should look at? Feel free to add a comment below to your favorite snippet website.
Junk Drawer Assembly/Jar/Repository
This is the least favorite of all the possible choices; however, it is the one I most practice.
The first thing I do when starting a new project is to create the SVN repository. The second thing I do is immediately create a “toolbox” repository for that project that I call – the junk drawer.
Anything code that does not contribute to the product but does indirectly support it (quick and dirty data migration apps, record matching apps, or that crummy State enum) gets saved for prosperity in this repository. There is no structure or rules in the junk drawer.
I have seen people attempt to organically grow “reusable” libraries from these snippets in the forms of assemblies and jars. I highly frown upon this practice – you wouldn’t keep your yeast and flour in the same jar, why are you keeping junk and clean code together? Trust me, the maintenance headache of this practice far out weighs the ROI of ever reusing that pocket code.
Your Blog
The majority of developers who blog create posts only around code – making their code available for the entire world.
Here are a couple of thoughts on this:
- I love bloggers who post and explain code because it adds to community learning
- I loathe bloggers who post uncommented code with no explanation further than – “thought this might be useful to someone else”
- If you are blogging about something – normally you are passionate about the topic, so I will take that piece of code a little more seriously
Those are just some of my ideas, and I am sure there are a few others. Where do you keep your pocket code?
14 Responses to “3 Places To Keep Your Pocket Code (Besides Your Pocket)”
I try to avoid hanging on to pocket code.
I believe that you want to write every piece of your code in every project rather than copy/paste as you may well miss an opportunity to improve the system if you throw in something that worked well enough on another project.
http://pastie.org
Personally I don’t think I have any pocket code these days. What I do have though, which has been evolving on my memory stick for about 5 years is a collection of scripts I’ve written. These include batch scripts, vbscripts (it was a long time ago, I was learning…), PL/SQL scripts, T-SQL scripts you name it. I don’t necessarily even actually use them, but like the internet, they’re a good way to remember a technique for doing something, maybe even in a different language.
I don’t like copying and pasting “pocket” code because it evolves over time and finding and maintaining every copy of the code is a pain.
However, I haven’t really found a good way to collect it into well organised assemblies either.
I guess I’ll blog it for others and, as Garry suggests, just rewrite it each time, making it better.
My pocket code lives in an assembly, but its long since been shelved. Now I write it, every time, all the time.
I assume you mean code like, a recursive method, or a loop that deletes something out of an array, or an html helper that builds a select box? If thats what you mean, most of that code can be generated anyway. The rest should be written by hand, ever time. This stave’s off the code scurvy created by copy/paste.
With over 11,000 code snippets stored to date, CodeKeep (www.codekeep.net) is a widely used site for storing pocket code.
I tend to create blog posts out of them. That makes them show up in Google, and gives me a great format for explaining it.
What definition of condone are you using?!?
Good catch Tim – sorry for misspeaking, meant to say “frown upon” – good catch it is fixed now.
I am usually posting them in my blog. That way I “save” them for pesonal usage and more important – I share them with my readers and with future google searchers.
If I have a little piece of code that is “project specific” (can’t be shared in my blog), I am writing a code snippet or create a static utility class – depends on the situation.
[…] 3 Places to Keep Your Pocket Code (Besides Your Pocket) (Max Pool) […]
Another place for code is Code:Keep http://www.codekeep.net
Blog. I try to put any self-created cool code snippets there, but I agree with everyone on not being a copy/paste person. I do sometimes think about something I have used before and find myself trying to get back to that code to see how I tackled it and use it as a starting point for approaching new problems (improving on the original though).
Also I would say that that good organizing is probably also needed when collecting “pocket code”. Time to time I tend to look for code that I know I have written somewhere- but can’t remember in which project.