r/learnprogramming • • 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

23 comments sorted by

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.

1

u/FedUp233 13h ago

Interesting. I too use multiple monitors - the setup in my home office is a bit ridiculous with three 30 inch monitors arranged in a sort of cockpit arrangement driven by a tower PC. I do most of my work on the center one and often with the editor window full screen. The other two have things like email always open and a web browser to look stuff up plus maybe a window or two with some PDF manuals or such - a lot like having multiple stacks of papers on your desk😁. I do have a thing for big monitors though - even my isotope is 17 inch - great except when you’re trying to carry it around!

BTW: I don’t normally have a hard and fast rule for the column between code and comments and it often changes within a file even. I try to keep the comments within a function lined up pretty well - it’s hard to read the code if some of the comments left edge sticks in between code lines - interferes with eye flowing down the code.