5 ms·
I'll suggest one more addition to this (and any code you take from the internet): put a comment in saying where you got the idea from (with a link). It can help
by moomin 7y ago
I'll suggest one more addition to this (and any code you take from the internet): put a comment in saying where you got the idea from (with a link). It can help the next guy out a lot. And you might be the next guy.
- inetknght 7y agoEspecially if it's not a copy-paste job. If there's any adjustments or even a rewrite, the comment should include the reason why the changes were made. The next guy coming along might not realize that changes were needed
- nradov 7y agoIt's usually better to put that information in the revision comments when you commit rather than in the code itself. Otherwise the code accumulates layers and layers of comments over years.
- penagwin 7y agoI feel like it depends - I know I don't just start digging through the commit history of every line I edit. If I'm trying to fix a bug, and only have to change one line for it to start working, and the tests still pass - but that line was there for a reason that wasn't commented (some edge case) - I'll likely miss it.
- jonreem 7y agoPersonally, I've developed a strong preference for putting this type of information as close to the affected code as possible. Immediately next to the affected code is the only place these types of comments have a prayer of being kept up to date. Keeping them in another document, a commit message, or anything similar just results in the content of the message instantly going out of date.
- tracker1 7y agoSo much this... I tend to do this. There are times where I need a limited subset of a library, and will just pull the two classes I need, add the comment at the top, and adjust the namespace.
- nitrogen 7y agoIncluding an update to all of your copyright notices, of course
- yorwba 7y ago> put a comment in saying where you got the idea from (with a link) StackOverflow content is licensed under CC BY-SA, so you're legally required to do that if you copy code from an answer. (Unless it's so trivial the code is not copyrightable, but it's better to be on the safe side and attribute the source correctly anyway.)
- m_mueller 7y ago> And you might be the next guy. It already happened to me a couple of times that I had a problem, googled it, and found a helpful SO answer .. by myself some years ago. So this is definitely a helpful suggestion.
- Jare 7y agoThis is huge and has saved me a few times already when I became my own "next guy"