7

Say for example I have some unused code that I want to use in the future and does not work with the rest program,or say that I come across some interesting code online. Is there any good program that I can store different pieces of code in?

  • Emacs org-mode might be a interesting choice for taking notes and storing programs. It's powerful and especially suited to programmers. – xji Apr 25 '17 at 11:35
15

If it's for a program which is already under source control, just keep these changes in a branch of that repo.

For odd bits of code, you could use almost anything, but some good options would be private GitHub or Bitbucket repo, a Gist, or some private source-control system you maintain on your own hardware. Non-source control options might include dumping things into an S3 bucket or similar cloud storage system, esp. with your usage likely to not exceed the free pricing tier.

2

To my mind - these are 2 different questions:

Unused code that I want to use in the future and does not work with the rest of the program

If your VCS system supports it, I'd be inclined to put this in a shelveset since it isn't current development but you may want to pull the code and work on it later.

Some interesting code online

Rather than pollute the source code tree with this, either bookmark the page or stash the code somewhere else (print it off, put it on the LAN, store it on a USB stick etc).

You may also want to email it to colleagues or add it to a wiki to raise awareness.

0

I think a good way to park your code is git. For example if you have a github account just create a repository there and put all your samples there.

I have something similar in my account and I call it garbage

It might be better than S3 or gists as you can organize/version/search your parked code easier.

  • Gists are versioned (they're git repositories). They're also searchable if public. – 8bittree Apr 28 '17 at 20:02
0

If it is part of your project, I would make a branch or a tag and then delete that code from your main repo.

I used to keep blocks of code in my main repo that served no other purpose other than that they might be needed later. Really what I was saying was that it might be useful later and I needed to find it. A tag might be even better as branches are supposed to be more ephemeral. Branch vs Tag

In any case unused code will just confuse you and other devs later. So it's not a great practice to leave it in a project.

protected by gnat Apr 19 '17 at 9:33

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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