A couple of questions I've read today discuss the legal implications of using someones code in your project:
- Can I legally incorporate GPL & LGPL, open-sourced software in a proprietary, closed-source project?
 - Do you save the code you wrote at your previous jobs?
 
This has left me wondering where example code found online fits into things.
Scenario:
- A developer is working on a project and encounters a problem.
 - They ask a question on the internet somewhere (ie stackoverflow.com)
 - Someone answers their question and provides a nice code snippet that just about does what they want.
 
Where does one legally stand if the developer includes the code verbatim in their project's code?
I know I've done this before...and I'm sure others have too...but I'd really like to know what the legal or ethical answer is to this question.
- Should one use the example code and move on?
 - Should one use the example code and provide a comment referencing its origin?
 - Should one inform the provider of the example code that they've used their code?
 - Should one not use the example code at all and use the basic idea to create your own code?
 - Is it ok to use said example code in proprietary closed-source projects?
 - Is it ok to use said example code in proprietary but internal-use-only projects?
 - Are the legal implications currently undefined?