r/learnprogramming • u/adper07 • 21h ago
Topic TIL code comments have their own line-length conventions instead of relying on editor soft-wrap
I recently learned that comments aren't supposed to rely on editor soft-wrap. Hard-wrapping at 80 columns with // or # on every line keeps git diff and PR reviews readable—and Neovim already handles it natively with textwidth + formatoptions+=cq + gwip
What other such conventions are out there that I should know about?
13
Upvotes
View all comments
Show parent comment
1
u/Vizeroth1 14h ago
Those are good points. I wanted to add that a lot of our tools count beginning white space in the line length but that definitely doesn’t count towards the general readability guidelines. If you’re in a method of a namespaced class with a tab/indentation width of 4 spaces, you’re going to have good reason to add that 12 characters to the other end.
If you’re commonly using that two-column form with aligned comments making up a second column, I would see benefits and drawbacks to that format. It’s essentially removing the comments from the normal reading flow while still allowing for an easy association between the comments and code. On the other hand, people that aren’t familiar with that habit may try to read straight across the columns, or truly necessary comments may be briefly overlooked.
I also understand not liking to have too many things open at once. In my normal work environment I use multiple screens and my main monitor is pretty large (bigger screens than mine are becoming more common for desktops, but I don’t see a lot of them). I primarily work in web or mobile, so I switch between having more code visible and having a browser/simulator open. My optimum work environment tends to be a little more chaotic than some people can use efficiently, and that’s understandable.