3

This question already has an answer here:

When is it okay to open-source something? If I have a big project I like to publish it, but is it looked-down-upon to publish, say, a small function?

marked as duplicate by gnat, user40980, EL Yusubov, Jimmy Hoffa, psr Jul 18 '13 at 21:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    Is this code you developed at work? Check with you manager and maybe the legal department too. You might not be allowed to open-source it. – FrustratedWithFormsDesigner Jul 15 '13 at 17:44
  • No. I wrote it as a general-purpose function. – Witch-King Jul 15 '13 at 17:54
  • 3
    Github has many projects that are one line of code. – Reactgular Jul 15 '13 at 18:21
  • Can you provide more details on your specific situation? – Kevin Jul 15 '13 at 22:44
  • Just if I have a random function, such as a form validation script, that I like to use often. – Witch-King Jul 16 '13 at 14:13
15

When is it okay to open-source something?

Assuming that you have legal permission to do so (I am not a lawyer; if the code in question originated at your workplace, consult your manager and legal department before publishing anything as open-source), you can do it whenever you want. Usually before putting it on display for all the world to see, people like to spend some time cleaning up dead code, formatting the code, adding proper comments and documentation, and any special instructions for compiling or running. Once your code is nice and clean looking, go ahead and publish it!

And no, publishing a small function, with a demo project that shows how to use it will not be looked down upon. Somebody somewhere might find it useful and they will be thankful you chose published it.

3

It's okay whenever it's legal, or otherwise obviously not okay. For instance, if you find a security hole in DNS, please don't open source an exploit without making a few phone calls first.

When should you open source something? In the current era, the following benefits are most salient:

  1. Other people can use your stuff. So try to make useful. For instance, npm packages tend to be very small, often only one file of a few hundred lines, simply because they solve one problem that many people run into often. And if you are successful enough to garner attention, other people will start working on it and improving it for you. This is, of course, the business value in open sourcing something.
  2. It builds your portfolio. When applying for jobs it's nice to be able to hand someone a github link that shows what you've done. This is a good reason to open source stuff.
  3. Companies like github will gladly manage your open code for you. Github's business model is, if you contribute to our site with your code, it's free. If you don't want to contribute, you can share. More generally, it's obviously just easier to work with code, a document, or whatever, when it's not a problem if someone reads it. Even my boring to-do lists are "open" on my small personal site. If you happen to read one, then not much happens besides your wasting 15 seconds of your life, but it means from a mobile phone or any random computer I can just look up a post with no authentication whatsoever.

There are many more reasons and it's a big topic, but I think this speaks to what you were asking moreso than simply documenting when it's okay. I will take the stance that unless you're planning on monetizing some proprietary code in the near future, it's probably very good for you and a little good for the community to open source whatever you can.

2

Publishing a small function can be very helpful, especially when accompanied by a blog or something similar which provides an explanation as to the purpose. I have been helped many times by open source functions.

The gist feature of GitHub also encourages publishing small code snippets.

You should only open source code that you own, or have permission to publish.

2

Ethically, I'd say it is almost always OK - at worst, it will be ignored, at best, you'll change the world, but more likely it will make someone's life somewhere a miniscule bit better. You're giving it away for free, and you're not forcing anything on anyone - that's about as ethical as you can get, in general. I have a hard time coming up with examples where it would not be OK to share your code; the only thing that comes to mind would be if you have discovered a security vulnerability and written an exploit. Publishing the exploit without prior warning is questionable, and in most cases "responsible disclosure" (tell the maintainer/author first, and only release the information to the general public after a grace period long enough to get the problem fixed, ideally in cooperation with the maintainers) is a better way to go.

Legally, the story is different. If you have written the code under an employment or consulting agreement, you may not have copyright over it, and you cannot legally publish it as yours. The code may also contain trade secrets or other restricted information, or it may do things that are considered illegal in at least some jurisdictions: for example (I may be wrong, but this is my understanding) publishing DVD playback software that can play encrypted DVD's is illegal in the USA unless you have a valid license to do so (and such a license is incompatible with free software in general). Software that is written to perform crimes may also be illegal in and of itself - e.g., if you were to write a program that automatically analyzes Google Maps imagery to find homes that are likely to be easy targets for burglary, it could be argued that you have made the software equivalent of a lock-picking tool. And then there's the wild world of patents, which may also pose an obstacle to legally releasing your code to the world.

1

is it looked-down-upon to publish, say, a small function?

This seems to be the core of the question, and it's a social consideration.

Looking at the open source community in general, I'd say that it would view publishing any code as open source as a good thing.

But communities are made up of individuals, and individual reactions can be wildly variable. Some may find your function useful and thank you personally, or even build a story of a new generation of open source hackers out of it, warranted or not. Some will use it as an opportunity to assert their superiority and will mock your for doing things obviously wrong (i.e. different than what they would have done).

Realistically though, chances are that hardly anyone will notice.

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