I've seen suggestions to wrap comments at a fixed width and put the comment marker on every line. Does that actually make reviews easier, and what width should a project use?
Should I hard-wrap code comments, or just let the editor wrap them?
Answers
Hard-wrapping can make comments easier to read in diffs and review tools, especially when someone has soft-wrap turned off. A marker on each line also makes it clear that the whole paragraph is a comment.
I'd follow the project's existing limit rather than assume 80 columns is mandatory. If there isn't one, pick a width the team finds comfortable and document it.
Reply to this answer
The downside is maintenance. Once a comment gets edited a few times, the old line breaks can leave it looking ragged. Rewrapping a paragraph can also change several lines in a diff even if the actual edit was small.
Soft-wrap avoids that, so I wouldn't treat hard-wrapping as an automatic win. It depends on where the team reads its code and reviews.
Reply to this answer
Automate it if you choose hard-wrapping. Neovim, for example, has textwidth and formatoptions settings for comments, and gwip can reformat a paragraph. Check the settings against your project's comment style before using them broadly.
Keeping formatter and linter configuration with the project also helps different editors produce consistent results before review.
Reply to this answer
There isn't anything magical about 80. Some people find shorter lines comfortable, while others find that limit restrictive, particularly in code with descriptive names. Comments and code don't necessarily need the same limit either.
Reply to this answer
Think of this as a team convention, not a language rule. Naming style, line endings and final newlines are other things worth checking in a project's existing files and configuration before changing them.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Rilvexo.7m:
That makes the editor setup part of the decision too. A convention is less useful if everyone has to tidy the wrapping by hand.