Should code comments link to Stack Overflow answers? Let's argue about it
Scheduled broken-link and redirect checks that tell you the moment a link breaks — linkbruno.com Open any mature codebase and search for stackoverflow.com . You'll find a few dozen comments like this: // Safari doesn't fire 'change' on autofill, see // https://stackoverflow.com/a/<answer-id> Some teams love these. Some ban them in code review. Most have never discussed it. I think it's worth…
The debate over whether code comments should link to Stack Overflow answers rages on. Some teams embrace these links, while others ban them during code reviews. The case for linking is strong: a single line explaining the "why" can make the otherwise confusing workaround much easier for future maintainers to understand. Links provide honest attribution, especially when code is adapted from an answer.
They also serve as a useful signal for later cleanup, as a comment pointing to an answer from several years ago can indicate that the current workaround may no longer be necessary. Search engines and AI assistants, however, do not replace these links. They simply assume the next developer knows how to search for the solution themselves.
Moreover, links in code are prone to rot. They are seldom checked, and links can break when answers get deleted, accounts removed, or URLs change format. Over time, even the version of the answer you initially linked to may change, making the explanation outdated. The case against linking is valid as well: links in code can quietly rot, becoming a riddle without an explanation.
If the link dies, the next maintainer may be left wondering why the workaround was used in the first place. This can lead to either keeping the confusing code indefinitely or removing it and reintroducing the original bug. Ultimately, the decision on whether to allow Stack Overflow links in your codebase, require them for copied code, or strip them in reviews should be a team decision, rather than left to individual reviewers.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.