I think most of us, programmers, used Stack Overflow to solve every day problems: looked for an efficient algorithm to do something.Now imagine a situation: you have a problem to solve. Googled a bit, found a StackOverflow question but you are not really satisfied with the answers so far. So you have to do your own research: you need to do it because you want it in the company's app. Eventually after some hours you have found the better solution. You're happy, you added it to the company's code base, then you want to submit your answer with a code snippet (just several lines) to the question you've found before to help others too. But wait: the company's software is closed source, and you worked on it on the clock. So does this mean I shouldn't post the answer neither at work nor at home to that question in the rest of my life, because I solved it at work, and the company owns that piece of code?
Found a better solution to a problem at work - should I deter from posting the code snippet online?
legal
Exposing proprietary company information is something you should never do.  Most code snippets on Stack Overflow are far more mundane than that, however.  Consider this example:public static unsafe void SwapX4(Byte[] Source)  {      fixed (Byte* pSource = &Source[0])      {          Byte* bp = pSource;          Byte* bp_stop = bp + Source.Length;          while (bp < bp_stop)          {            *(UInt32*)bp = (UInt32)(                (*bp       << 24) |                (*(bp + 1) << 16) |                (*(bp + 2) <<  8) |                (*(bp + 3)      ));            bp += 4;          }      }  }This method inverts the endianness of a 32 bit number, by swapping the bytes around.  The difference between this implementation and a naive one is that this one runs twice as fast, but you can only run it on a little endian machine.  It's being used in a proprietary program, but it describes a general technique, and does not expose anything confidential.