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.
Text Files
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.
Special Application
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?
Database
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.
Online Services
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
- Tagging
- 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!
4 Comments:
A friend of mine tried to explore numerous ways to file his long list of code from various projects but ended up storing them in text files and search using google desktop-search.
Will have to wait to read how you store your snippets.
If you have a lot of different php functions it makes sense to store them in a single file. You can use Notepad++ to jump to these functions as you need. Same with other languages.
I've got a folder on my comp with a lot of code sorted out that I've written or coded in the past several years.
@Raj, I can not use Google Desktop search as I am on Linux - we have a similar application - Beagle. But is it possible to limit the search to a specific folder in Google Desktop Search?
@Ajay, Have you tried searching thru the folder to get a piece of code? Thats when the trouble appears. And wait for my method to store Text Snippets - you are going to love it.
The best tool, and I mean far the best, about 100 times then the rest, used to be NoteTab (Pro). It's ingenious. However, I am using linux for about 7 years now and I have never found a replacement.
NoteTab is really ingenious - you can create libraries, fill the libraries with snippets startin with simple "hello" and enging up with interactive complicated templates, which you make just by adding few characters to your source code at places where you want to have a dialog field, option select, a loop, etc. No other editor I've ever seen could match. I even try to run it in Linux in Wine.
Post a Comment