Web Development

Code sharing website options

Justin James discusses the characteristics of the ideal code sharing site and various code sharing facilities.

Member Mat O'Hare posted this great topic idea on TechRepublic's Facebook page:

"Another suggestion for the TR blog: What code-sharing facilities are good. I signed on to The Code Project to get something. It didn't suit me so I wrote my own. Now I'd like to put it somewhere. It seems Google has a similar facility. I've also seen others that are specific to programming platforms. What are good things to consider for places to share code?"

I haven't found any great sites for sharing code. Microsoft used to run a great site that made it really easy to upload a discrete piece of code with some attached descriptions. There was also something a long time ago called "Code Jack," which was like a P2P tool (think Gnutella or BitTorrent) that let you put up "artifacts" (ranging from small snippets of code to entire applications) and search them locally and on other users' machines. Both of these options were just right, but are since long gone.

There are sites that let you easily answer questions and include code in the response (or question). Some sites are like online magazines that are optimized for programming topics. And there are plenty of public code repositories. You could, of course, post code to your own website or blog.

To me, the ideal code sharing site has the following characteristics:

  • Powerful search that is optimized for inspecting code, and preferably language aware
  • High-quality system for viewing code online in a visual format that is easy to understand
  • Mechanisms for keeping the code up-to-date, but also maintain version history (version control)
  • A good system for writing about the code, not just posting it with a basic description; code annotations and such
  • The ability to parse the code for embedded documentation and automatically generate it and post it to the site when new code is posted
  • Can handle snippets just as readily as fully pieces of code
  • Gives you control over the license used

With these criteria in mind, let's look at our options.

Q&A sites

If you don't mind trying to work within the Q&A format, the only site worth considering is Stack Overflow. They have a critical mass of usage that cannot be beat. It is not great for working with code bigger than a snippet, and at best, you are going to be posting up your own question and then answering it with your own code. But it has high discoverability via search, and it is someplace that other people often visit. Unfortunately, Stack Overflow gives you no control over what license is used.

Online magazines

While not a true magazine like Dr. Dobb's or MSDN Magazine, the best bet here is The Code Project. They do not have facilities for code management, but if you want to get a small piece of code online with a detailed explanation of how it works, The Code Project is a good choice. There are, however, a couple of problems here. For one thing, the site is designed for articles and not big chunks of code. People are going to be rating your article based on its usefulness, and just trying to put up a lot of code won't do well. In addition, you have no control over the license.

Code repositories

The better online code repositories make it easy to browse for code and examine the source, as well as organize an actual project. On top of that, they allow you a version control system, user management, and project management facilities. In addition, you control the license more often than not.

One drawback is the facilities for writing about the code are not so hot. Another is that in many cases they are more complex than a simple "post, describe, and save" process. Your best bets in this space are SourceForge, Bitbucket, GitHub, CodePlex, and Google Code.

Self hosting

Self hosting is what I have chosen to do. I already have a small website for my personal business, so it is not a big deal for me to throw snippets of code, entire applications, etc. up there with the writing about it at my discretion. And, I have total control over the license.

The downside is I don't have versioning or code browsing support. I suppose if that was important to me (I almost never update the code there -- it's small stuff that's good to go), I would use a code repository (probably Bitbucket) to hold the code, and then link to it from my site's write up. For what I do (one or two pieces of code a year, outside of what gets posted here on TechRepublic in articles), it is just fine.

My wish for a long-term solution

I'd like to see something like a Wikipedia for code, where the topics are the need being addressed and sections would show how to handle them in different languages, with links to full, version controlled code in the descriptions. I'm mildly surprised that no one has done this; it's just a matter of combining the open source Wikipedia code with different Web front ends for code repositories, and as time goes on, blending the two to be more seamless. This sounds like a great project for someone with more time than I have at the moment.

Conclusion

The route you take is up to you and your needs. I look forward to reading members' suggestions in the comments.

J.Ja

About

Justin James is the Lead Architect for Conigent.

12 comments
apotheon
apotheon

I'm actually working on an idea for a new code hosting site. I'll try to keep these criteria of yours for "code sharing" features in mind as I plan the project.

walrii
walrii

I use Evernote to store "tidbits". Anything from code fragments tagged by subject and language to notes, scripts, or instructions for things that took a while to figure out. Accessible via the web or local app.

jseller
jseller

I have used bitbucket.org and it did everything I needed for a small project. It has a wiki and bug tracking as well, with easy backups. Very useful!

gmaran23
gmaran23

Hey justin, I am wondering if this is an intentional mistake.. :) Under Online Magazines sub heading, the hyperlinks to dr.dobbs and msdn magazine are the same? -Maran

sean.hanford
sean.hanford

I am grateful to resources like Tech Republic as they have a large community of individuals with positive and well thought-out ideas and debates. With respect to your request, I belong to a site that is somewhat similar to what you are looking for: snipplr.com. I'm afraid that the net is getting so big that we all desire specific types of resources and expect to find them online. If they do not do a good job with SEO or site optimization, they may never be found unless word of mouth or something viral actually puts them on the map. This is my contribution to the hope that we do one day have a large code repository to share among our peers.

mattohare
mattohare

We can handle the version control for our own projects, and just put up the occasional package (zip, self-installer, etc.) to the sharing site. People want an older version, they take it. But don't have to wade thru a sea of commits.

Justin James
Justin James

I hope that you are able to get that put together, and I'll gladly take a look at it when it's ready for demos. I hope it uses Mercurial under the hood for the versioning end of things. :) J.Ja

Justin James
Justin James

Thanks! I'll let my editor know, I'm sure it was just a missed "Copy" operation causing the same text to be pasted twice. :) J.Ja

Justin James
Justin James

Use something like that only for public versions, internal versions stay internal. It's nice if the public version uses the same source control as the internal too, which is a great reason to be using Mercurial or Git. :) J.Ja

apotheon
apotheon

I'm afraid you're destined to be disappointed. I'll probably see what I can do about making imports from Git and Mercurial easy, though.

apotheon
apotheon

I take it "I'm kind of surprised" is about my choice to use something other than Mercurial. It might be a fair bit more than 10-20 minutes. I want to see how little versioning data I can manage to lose in an import. The differing versioning models used by these things lead to some mismatches in how stuff is managed, so I'm not sure yet how successful I can be in ensuring that people don't lose any data they might later want. It's the edge cases that worry me.

Justin James
Justin James

I figured that you'd do something like that to get a leg up on it. :) Then again, for what you are looking at doing, it may only be 10 - 20 minutes of work to build in what's actually needed anyways. J.Ja