All programmers have their own ways of storing useful code for future use. Some don't do anything special for it. They can remember which project they had used the code - all they have to do is call up the source code for that project, search around a bit and they have the code they wanted. I used to be in this class - but now, I have too much projects and too much code for that to work. So I am exploring alternative methods to do this.
The simplest methods are often the best - storing all the text snippets as text files. You can arrange it into folders for easier management. I have tried this approach - but it did not work for me. Searching gets a bit hard after some time. Another problem with this method is that the data is limited to one computer - you will have to carry all these files around if you want to use it in other systems.
Single Text file
You can save all the code snippets in one big text file - this will make searching easier. Another advantage of this method is that you can carry this file around - so it is more portable approch. I have not tried this method - if I find multiple text files hard to manage, there is no way I can do it with a single text file. But there are people who have done it - and swear by it.
Single (Some format) File
You don't have to use text - you can use excel or LaTeX or some other format to store everything you need in a single file. As long as the data is findable, its possible.
There are many applications that can be used to store text snippets. I have not used any applications for this purpose - so I cannot recommend any specific tool. I am sure that a google search will reveal many such software. In Linux, you could use KJots and BasKet to do this. Do you know any application that could be used for this?
If you have done a bit of Database Designing, I am sure you are already working on a design to store the code in a Database - locally or on the web. This method will involve making an interface to input, search and display the snippets as well. If you are using a database like Access, you can use the 'Forms' feature to do it. But if you are using MySQL, SQLite or something like that, you may have to create a custom application. This could be a web application or a desktop application. I almost went this way - but my work with Nexty prevented me from doing much.
There are sites that could be used store snippets. One such site is Text Snippets. It supports all features necessary for storing code snippets -
- Syntax Highlight for the code
- Easy Interface
- And more..
I tried it out - but did not find it very useful...
- The Syntax Highlighting expects all code to be in ruby
- No way to backup the data
- You have to use the web interface to enter the data.
- No way to get the data if you are offline
Other sites that could be used to do this are...
And the best method is...
I tried most of the above methods - but none matched my requirements. After much searching I found a method thats perfect. I will talk about that in the next post.
Update : Saving Code Snippets - Part 2 Ready!