Subscribe via RSS

3 Places To Keep Your Pocket Code (Besides Your Pocket)

Filed Under Code, Efficiency Tips

Empty Pockets

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:

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:

  1. I love bloggers who post and explain code because it adds to community learning
  2. I loathe bloggers who post uncommented code with no explanation further than – “thought this might be useful to someone else”
  3. 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?

RSS Icon

  Don't miss a drop! Subscribe now via RSS or email.

Comments

14 Responses to “3 Places To Keep Your Pocket Code (Besides Your Pocket)”

  1. Garry Shutler on May 7th, 2008 6:50 am

    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.

  2. Mike Breen on May 7th, 2008 6:59 am
  3. Neil Barnwell on May 7th, 2008 7:11 am

    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.

  4. Jason Stangroome on May 7th, 2008 7:12 am

    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.

  5. Chris Chandler on May 7th, 2008 7:37 am

    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.

  6. Dave Donaldson on May 7th, 2008 7:40 am

    With over 11,000 code snippets stored to date, CodeKeep (www.codekeep.net) is a widely used site for storing pocket code.

  7. superjason on May 7th, 2008 8:06 am

    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.

  8. Tim on May 7th, 2008 12:55 pm

    What definition of condone are you using?!?

  9. Max Pool on May 7th, 2008 1:09 pm

    Good catch Tim – sorry for misspeaking, meant to say “frown upon” – good catch it is fixed now.

  10. Shahar on May 7th, 2008 11:23 pm

    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.

  11. Dew Drop - May 8, 2008 | Alvin Ashcraft's Morning Dew on May 8th, 2008 7:15 am

    […] 3 Places to Keep Your Pocket Code (Besides Your Pocket) (Max Pool) […]

  12. Nino Benvenuti on May 8th, 2008 8:46 pm

    Another place for code is Code:Keep http://www.codekeep.net

  13. Fervent Coder on May 8th, 2008 11:49 pm

    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).

  14. Janar on October 16th, 2011 11:16 pm

    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.

Max Pool - © 2024 - {codesqueeze}. Sycorr Banking Solutions