What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 128 Stack Exchange communities.

I've read over the Attribution Clause and, as I understand it, this is to protected against others scraping information from StackOverflow and selling and/or redistributing it without permission.

My question is: do you ever cite a helpful question's URL in code?

I recently came across a simple utility function in an answer which saved me a little time*. It was syntactically correct, dropped right in, and may look stylistically out of place, so I thought it appropriate to put the URL in a comment.

// http://stackoverflow.com/questions/80476/...
public static final String [] whatever = concat(...);

I have done this before with my own questions, writing a comment explaining a section of code which ultimately had no definite or elegant solution. Is anyone else in the practice of doing this? I'm curious to know what others think.


*Time that I somehow used to write this question instead :-p

share|improve this question

2 Answers 2

I can't readily think of any instances where I've used code from SO verbatim in production work. Seems careless and lazy.

That said, if it's something tricky I'll usually try to explain it, and link to relevant documentation in the comments - usually this takes the form of MSDN URLs, but I could see throwing a SO link in there...

share|improve this answer
    
True, questions are almost always just snippets of a larger problem. I guess I meant more for instances where it is helpful to explain a concept and its attached talking points. –  zourtney Dec 15 '10 at 18:18

Happens to me quite frequently, I post a lot of code. Today's featured example was this thread, partly copied from my answer here.

No attribution at all, called him on it in a comment. The outcome is pretty common too, he got an answer that doesn't help him at all, just a rehash of the original answer without the magic sauce. I knew the answer but just didn't feel particularly enticed to post it. There will be somebody else that does it the right way, I can wait.

Yeah, attribution is there for a good and simple reason. And putting a comment link in your code is an excellent way to do it for more than one reason. SEO for a programmer and a fine resource for whomever takes over the maintenance of your code some day.

share|improve this answer
    
Now you've got me wondering. I know there are times I incorporate tricks into my answers that I've learned elsewhere (and don't remember where), but I've never copied and pasted code without attribution. I completely agree with your answer here, but now I'm wondering what that magic sauce is that I'm missing. The code I posted is from a class I wrote that wraps the built-in Cursor class. So far it works for me, but I'm always looking to learn something new. Would you prefer I open a new question? Or is this a pretty simple secret? –  Cody Gray Apr 6 '11 at 2:41
    
Oops, didn't realize it was you. Ahem, gotten to know you since then. It is leaking the cursor handle, check the Cursor(IntPtr) constructor Remarks section. The sauce is the reflection code to force it to own the handle. –  Uphill Luge Apr 6 '11 at 3:04
    
Well, it wasn't my question. I was just the one who answered it, but I noticed you said the answer he got wasn't necessarily complete. I appreciate the clarification. The custom class I use actually sets a flag indicating whether it owns the handle; I see I did leave the dispose call out of my answer. Either way, forcing the underlying Cursor class to own and dispose it automatically is a solution I hadn't even considered. Much more elegant than mine. –  Cody Gray Apr 6 '11 at 6:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .