tags:

views:

488

answers:

17

I took a data structures class in C++ last year, and consequently implemented all the major data structures in templated code. I saved it all on a flash drive because I have a feeling that at some point in my life, I'll use it again. I imagine something I end up programming will need a B-Tree, or is that just delusional? How long do you typically save the code you write for possible reuse?

+27  A: 

Forever (or as close as I can get). That's the whole point of a source control system.

Chris Upchurch
Plus disk space is cheap.
Mark Biek
Yep. I gave up actively deleting stuff off my hard drive a long time ago. Just like with gmail, with decent search it's easier to just archive everything rather than worry about sorting, filing, and deleting it.
Chris Upchurch
+1  A: 

I keep backups of all of my code for as long as possible. The important things are backed up on my web server and external hdd. You can always delete things later, but if you think you might find a use for it, why not keep it?

Scott S.
A: 

Source control, keep it offsite and keep it for life! You'll never have to worry about it.

Aupajo
+2  A: 

If I use it, it gets stuck in a Bazaar repository and uploaded to Launchpad. If it's a little side project that pitters out, I usually move it to a junk/ subdirectory.

I'll use it again. I imagine something I end up programming will need a B-Tree, or is that just delusional?

Something you write will need a B-tree, but you'll be able to use a library for it because the real world values working solutions over extra code.

John Millikin
A: 

I have code from many, many years ago. In fact, I think I still have my first php script. If nothing else, it's a good way to see how much you have changed over time.

dawnerd
A: 

I agree with the other posters. I've kept my code from school in a personal source code repository. What harm does hanging on to it really do?

codefin
A: 

I still have (some) code I wrote as far back as college, and that would be 18 years ago :-). As is often the case, it is better to have it and never want it, than to want it and not have it.

rjray
A: 

I would just put it on a disk for historical sake. Use the Standard Template Library - one mistake people make is assuming that thier implementation of moderate to complex data structures are the best. I can't tell you how many times I have found a bug in a home grown B-tree implementation.

MikeJ
+1  A: 

+1 to keeping code forever. In this day and age, there's just no reason to delete data which could possibly be of value in the future. Even if you don't use the B-Tree as a useful structure, you may want to look at the code to see how you did something. Or even better, you may wish to come back to the code someday for instructional purposes. You'll never know when you might want to look at that one particular sniblet of code that accomplished a task in a certain way.

Daniel Spiewak
A: 

Keep everything! You never know when it will save you some work. About a year ago I needed some c code to parse an expression, tokenize it for storage, and evaluate the results latter. Ugly little piece of code.. But is seemed familiar, as it should have- I had to do a post-fix evaluator in college (30 years ago)- and still had the code. Admittedly it needed a little clean-up, but saved me a couple of days of work.

A: 

I implemented a red black tree in Java while in in college. I have always wanted to find that code again and cannot.

Now I do not have the time to recreate it from scratch since I have three kids and do not develop in Java.

I now keep everything so that I can relearn much faster. I also find it fascinating to see how I did something 1, 5, 10 years ago. It makes me feel good because I either did it right or I am better now and would do it differently

If I ever go back to college to give a lecture to future students it in on the list of things to do:

Save everything...

Dining Philanderer
+2  A: 

-1 to saving everything that's ever produced. I liken that to a proud parent saving every single used nappy ever to grace the cheeks of their little nipper. It's shitty and the world doesn't benefit from it's existence.

How many people here go past the first page in google on a regular basis? Having so much crap around only seems to make it difficult to find anything useful.

Matt Jacobsen
A: 

I'm a code packrat, for better or worse, but I guard it, because sometimes it's client-confidential.

On occasion, this has been really useful, like if a client lost their stuff, or their documentation.

Mike Dunlavey
A: 

I lost a lot of old code (from 10 years ago) because of computer failure that wasn't backed up but in fact I do not really care because I do not really want to see code that is programmed in very old language. Most of this code was written in VB5...

I agree that now it's easy to keep everything but I think sometime it's good to clean up our backup/computer storage because it's like in the real world, we do not need to keep everything forever.

Daok
A: 

Forever is the beauty of the electronic medium. That's one of the most attractive aspects for me.

But, the keeping of it depends on your coding style, and what you do with it.

I'd suggest tossing your code if you're the type that...

  • Never looks back.
  • Would rather re-write from your memory to improve your craft.
  • Isn't very organized.
  • Is bothered by latent storage to no end.
  • Likes to live on the edge.
  • Worships efficiency of memory.

Logical reasons for tossing could would be...

  • It bothers you.
  • It disrupts your workflow by getting in your way.
  • You're ashamed of it.
  • It confuses you and distracts you.

Like anything that takes up physical space in life, it's value is weighed against it's usefulness.

All my code is kept indefinitely, with plans to return to it at some point, reflect, and refactor. I do that because it's fun to see my progress, and provides very accessible learning experiences. Furthermore, the incorporation of all my code into a consolidated framework is something I work towards all the time.

Pup
A: 

Forever...

Good code never dies. ;)

Nick Haslam
A: 

I don't own most of the code I develop: my employer does. So I don't keep that code (my employer does - or should).

Since I discovered computing, I wrote code for devices that no longer exist in languages that are no longer worth. Maybe there is some emulator but keeping that code and running it would be nostalgia.

You can find B-tree information (and many other subjects) on Wikipedia (and many other places). There is no need to keep that code.

In the end I keep only code that I own and maintain.

mouviciel