Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm a novice programmer and I occasionally come up with ideas that I think will be handy on future projects. Having an art background, I used to keep a sketchbook. I would go back through these sketchbooks use them to inform future projects.

Do you keep your scratch code from past projects to track how your past projects developed? Do you store that alongside the final product? Do you keep a "code sketchbook"? What is a good way of capturing past ideas and making them accessible?

I saw this thread, and I'm more interested in capturing those disjointed ideas and solutions that and problems that I come up with. I like the idea of the wiki, but I also like the idea of something that is easily executable in EMACS.

share|improve this question

closed as too broad by Thomas Owens Sep 23 '13 at 0:44

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

Ideas, yes. Code not running in production, no. It will never be what you need anyway. –  user1249 Aug 7 '12 at 16:23
I should have included in my above question "project related scratch code", or that may be a separate question altogether. –  Chow Aug 7 '12 at 21:57
Generally no. In a very few cases - like functional proof-of-concept code, then perhaps yes. –  user1249 Aug 7 '12 at 23:27
Just for context I do mostly R programming where much of my coding is done in an interactive session to understand the data I'm working with. –  Chow Aug 29 '12 at 16:04
I really like the idea of a code-scratchbook! I keep my old files (obviously), but a neat way of organizing old code without much effort seems great! –  phi Sep 22 '13 at 19:36
show 1 more comment

8 Answers

up vote 14 down vote accepted

I actually keep a local wiki of code snippets and ideas. Its a really nice, productive way of organizing the small things that you don't immediately need. In general, there are a few rules you should follow if you don't want it to get out of hand:

  • Give the snippets long, understandable names. This way, you know exactly what the snippet is about and how it could be used.
  • Comment like crazy for the same reasons as above.
  • Setup a personal organization system that suits your exact needs.

I recommend using MediaWiki or MoinMoin, but there is a whole list over at Wikipedia.

Generally, I make a page for each code snippet/idea, and write a history and description of each. I make them as search friendly as possible so that I can find them fast and easy.

Of course, you can't execute within the wiki, but that's what jsFiddle, Ideone, and Codepad are for. Also, you can always run the code on your machine.

share|improve this answer
A local wiki is a good way to go –  waffleman Aug 8 '12 at 13:43
The main problem with a local wiki is you can wipe the system and forget to back it up. So either make sure you have automated offsite backup in place or look for something like txt files in a Dropbox account. –  David C. Bishop Sep 23 '13 at 23:12
Depending on the size/complexity of your snippets you could also keep them as private gists if you have a github account and don't want to set up a wiki. –  Evicatos Sep 23 '13 at 23:14
add comment

I generally do my tinkering and new tech investigation on my home box. I just keep them all in their own directory under a general "Experiments" directory. They're usually not directly applicable, but they're often a good reference (e.g., when I was figuring out how to process Java annotations). I keep thinking I'll release some of the more self-contained ones as open source, but I never seem to get around to making a SourceForge or GitHub account.

share|improve this answer
add comment

Disclaimer: I am the founder and creator of GistBox. There's a demo video of the app at: http://www.youtube.com/watch?v=VLgyY6lqpsQ

GistBox was created with the code "sketchbook" purpose in mind. For instance, as I am working on a project and I run across a good pattern, control or algorithm I'd like to save for later, I create a new Gist and label it accordingly.

Labels in GistBox

If you are interested in documentation, GistBox also renders Markdown (.md) files properly. You can easily create a label of "Ideas from Project X" and stick a bunch of Markdown notes into it, creating a sort of lightweight wiki.

Markdown file in GistBox

As for retrieval, GistBox's search relies on a Gists's description field. Be sure to give each new Gist a descriptive one.

If you'd like to learn more about Gist workflows or would like to suggest a feature, feel free to email me directly at rui@gistboxapp.com

share|improve this answer
Thank you for calling out your connection to GistBox. Thorough answer to the question. –  GlenH7 Sep 22 '13 at 15:19
add comment

I have a directory for programming, and I keep different subdirectories in it for different languages (Programming/CPP, Programming/Ruby, Programming/Lisp, etc.) and in each of these directories, I keep a folder named "snippets" where I save reusable code in that language. The only problem with this is that files start to pile up in it, and it can get out of hand. If you do this, try to keep it organized.

share|improve this answer
add comment

It might be a good idea to create a "scrap"; "scratch" or "sandbox" area in the source repository, specifically for experimental code, snippets & incomplete thoughts. This means you can:

  1. Keep them.
  2. Share them and collaborate on them.
  3. Potentially show how the code evolved from your initial thoughts to something usable (via the revision history of each item.

It might also have the beneficial side-effect of de-sanctifying the repository in people's minds.

share|improve this answer
If this were stated as an answer instead a question, I'd +1 it. –  DarenW Aug 9 '12 at 20:08
Well, I am not yet confident that it is a good idea. –  William Payne Aug 9 '12 at 20:12
I would agree with the point of "de-sanctifying the repository". I have code snippets and small tools that I think are useful but I am not confident to put into mainline code yet. But would like to allow colleagues to try –  justintime Aug 24 '12 at 6:45
I now have both a "sandbox" area, for trying new things out, and a "research" area, for throwaway exploratory data analysis and other R&D-ish scripts. –  William Payne Aug 24 '12 at 23:00
add comment

I used to, but at some point over the years it became just too big a pile o' code and I started throwing out huge chunks of it. It can be beneficial as long as it doesn't grow out of control.

share|improve this answer
add comment

If you are interested in something for emacs, I strongly suggest you take a look at org-mode. org-mode has several tools that make it great for taking notes and maintaining a set of examples and ideas for future reference.

  • babel allows you to insert code snippets in multiple languages in the same file, while still maintaining proper indentation/formatting for each language.

  • You can export your notes, along with your code, to numerous file formats, including HTML, LaTeX, and OpenDocument.

  • org-mode supports capturing quick snippets of code or text, which can help keep you from getting distracted while you work on something else.

  • Attachements, internal and external hyperlinks, and tags help you organize your snippets and notes, while also linking to external files or websites.

Finally, org-mode comes with an excellent manual, which will help you get up and running quickly.

share|improve this answer
add comment

For code snippets you can use GistBox.

There are many other sites to store code-snippets, you can find the in this article.

If you want to store ideas I think evernote is the best.

share|improve this answer
how does this answer the question asked? –  gnat Sep 22 '13 at 8:58
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.